home *** CD-ROM | disk | FTP | other *** search
- /*
- * Common routines used in all drawing styles.
- *
- */
-
- #include <scan/modall.h>
- #include <scan/drawinfo.h>
- #include <string.h>
-
-
- #define Channel (ScanBase->sb_Channel)
-
-
- #ifdef USE_BUFFERS
-
-
- BOOL __regargs GetFromBuf (struct Buffer *buf, struct IDrawInfo *di)
- {
- UBYTE *sr, *sg, *sb;
- UBYTE *dr, *dg, *db;
- UBYTE *red, *grn, *blu;
- int i, j;
- int w, h;
- int x, y;
- // int xo, xl;
-
- if (!buf) return(FALSE);
-
- /*
- * Only copy if space has been allocated for us. Some drawing
- * modes may not require this information, so the buffers may
- * not be allocated to save time & space.
- */
-
- if (di->BBuf)
- {
-
- w = di->BufW;
- h = di->BufH;
-
- for (j = 0, y = di->TE - di->BufYO; j < h; j++, y++)
- {
- GetBufLine(di->BBuf, &dr, &dg, &db, j);
-
- if ((y >= 0) && (y < buf->Height))
- {
- if (GetBufLine(buf, &red, &grn, &blu, y))
- {
- sr = red + di->LE - di->BufXO;
- sg = grn + di->LE - di->BufXO;
- sb = blu + di->LE - di->BufXO;
- for (x = di->LE - di->BufXO, i = 0; i < w; i++, x++)
- {
- if ((x >= 0) && (x < buf->Width))
- {
- *dr++ = *sr++;
- *dg++ = *sg++;
- *db++ = *sb++;
- }
- else
- {
- *dr++ = 0;
- *dg++ = 0;
- *db++ = 0;
- sr++; sg++; sb++;
- }
- }
- #if 0
- memcpy(dr, sr, w);
- memcpy(dg, sg, w);
- memcpy(db, sb, w);
- if (di->LE - di->BufXO < 0)
- {
- /* outside bounds of image is black */
- memset(dr, 0, -(di->LE - di->BufXO));
- memset(dg, 0, -(di->LE - di->BufXO));
- memset(db, 0, -(di->LE - di->BufXO));
- }
- if (di->LE - di->BufXO + w >= buf->Width)
- {
- /* outside bounds of image is black */
- xo = di->LE - di->BufXO + w - buf->Width + 1;
- xl = w - xo;
- memset(dr + xo, 0, xl);
- memset(dg + xo, 0, xl);
- memset(db + xo, 0, xl);
- }
- #endif
-
- }
- }
- else
- {
- /* outside bounds of image is black */
- memset(dr, 0, w);
- memset(dg, 0, w);
- memset(db, 0, w);
- }
-
- PutBufLine(di->BBuf);
- }
-
- }
-
- return(TRUE);
- }
-
-
- BOOL __regargs PutToBuf (struct Buffer *buf, struct IDrawInfo *di)
- {
- UBYTE *sr, *sg, *sb;
- UBYTE *dr, *dg, *db;
- UBYTE *red, *grn, *blu;
- UBYTE *mask;
- int i, j, x, y, mx, my;
- int left, top;
- short drawpart = (ScanBase->sb_DrawBlend * 255 / 100);
- int mix;
- short r, g, b;
- UBYTE *alphapix;
- struct Buffer *abuf = ScanBase->Alpha;
-
- if (!buf) return(FALSE);
-
- left = di->LE;
- top = di->TE;
-
- /*
- * Put the pixels into the buffer, applying blending and masking.
- * Also clip to buffer boundaries.
- */
- for (y = top, j = 0; j < di->Height; j++, y++) {
- if (di->Flags & IDIF_StatusBar)
- {
- if (Bar(j)) ReturnError(ERR_UserCancel, FALSE);
- }
- if (y >= 0 && y < buf->Height) {
- GetBufLine(di->BOut, &sr, &sg, &sb, j);
- GetBufLine(di->BMask, &mask, NULL, NULL, j);
- GetBufLine(buf, &red, &grn, &blu, y);
- if (buf->Mask) my = y - buf->Mask->OffsetY;
- dr = red + left;
- dg = grn + left;
- db = blu + left;
- if (abuf && ScanBase->sb_DrawAlpha)
- {
- GetBufLine(abuf, &alphapix, NULL, NULL, y % abuf->Height);
- }
- for (x = left, i = 0; i < di->Width; i++, x++) {
- mix = *mask;
- if (buf->Mask) mx = x - buf->Mask->OffsetX;
- if (x >= 0 && x < buf->Width) {
- if (CheckMask(buf->Mask, mx, my)) {
- if (mix && !CheckCloseness(*dr,*dg,*db)) {
- switch(ScanBase->sb_DrawAlpha)
- {
- case 0 : /* alpha = off */
- r = mixer(*sr, *dr, mixer(drawpart,0,mix));
- g = mixer(*sg, *dg, mixer(drawpart,0,mix));
- b = mixer(*sb, *db, mixer(drawpart,0,mix));
- break;
- case 1 : /* alpha = frisket */
- //GetBufLine(abuf, &alphapix, NULL, NULL, y % abuf->Height);
- if (abuf)
- {
- mix = mixer(mix, 0, alphapix[x % abuf->Width]);
- }
- r = mixer(*sr, *dr, mixer(drawpart,0,mix));
- g = mixer(*sg, *dg, mixer(drawpart,0,mix));
- b = mixer(*sb, *db, mixer(drawpart,0,mix));
- break;
- case 2 : /* alpha = texture */
- //GetBufLine(abuf, &alphapix, NULL, NULL, y % abuf->Height);
- if (abuf)
- {
- r = *sr + alphapix[x % abuf->Width] - 128; if (r < 0) r = 0; else if (r > 255) r = 255;
- g = *sg + alphapix[x % abuf->Width] - 128; if (g < 0) g = 0; else if (g > 255) g = 255;
- b = *sb + alphapix[x % abuf->Width] - 128; if (b < 0) b = 0; else if (b > 255) b = 255;
- }
- else
- {
- r = *sr;
- g = *sg;
- b = *sb;
- }
- r = mixer(r, *dr, mixer(drawpart,0,mix));
- g = mixer(g, *dg, mixer(drawpart,0,mix));
- b = mixer(b, *db, mixer(drawpart,0,mix));
- break;
- }
- if (buf->Depth == 1 || (Channel & CHAN_RED)) { *dr = r; }
- if (buf->Depth > 1)
- {
- if (Channel & CHAN_GRN) { *dg = g; }
- if (Channel & CHAN_BLU) { *db = b; }
- }
- }
- }
- }
- dr++; dg++; db++;
- sr++; sg++; sb++;
- mask++;
- }
- PutBufLine(buf);
- }
- }
-
- return(TRUE);
- }
-
-
- #else
-
-
- BOOL __regargs GetFromBuf (struct Buffer *buf, struct IDrawInfo *di)
- {
- UBYTE *sr, *sg, *sb;
- UBYTE *dr, *dg, *db;
- UBYTE *red, *grn, *blu;
- int j;
- int w, h;
- int xo, xl, y;
-
- if (!buf) return(FALSE);
-
- /*
- * Only copy if space has been allocated for us. Some drawing
- * modes may not require this information, so the buffers may
- * not be allocated to save time & space.
- */
-
- if (di->BufR && di->BufG && di->BufB)
- {
-
- w = di->BufW;
- h = di->BufH;
-
- dr = di->BufR - di->BufOffs;
- dg = di->BufG - di->BufOffs;
- db = di->BufB - di->BufOffs;
-
- for (j = 0, y = di->TE - di->BufYO; j < h; j++, y++)
- {
-
- if ((y >= 0) && (y < buf->Height))
- {
- if (GetBufLine(buf, &red, &grn, &blu, y))
- {
- sr = red + di->LE - di->BufXO;
- sg = grn + di->LE - di->BufXO;
- sb = blu + di->LE - di->BufXO;
- memcpy(dr, sr, w);
- memcpy(dg, sg, w);
- memcpy(db, sb, w);
- if (di->LE - di->BufXO < 0)
- {
- /* outside bounds of image is black */
- memset(dr, 0, -(di->LE - di->BufXO));
- memset(dg, 0, -(di->LE - di->BufXO));
- memset(db, 0, -(di->LE - di->BufXO));
- }
- if (di->LE - di->BufXO + w >= buf->Width)
- {
- /* outside bounds of image is black */
- xo = di->LE - di->BufXO + w - buf->Width + 1;
- xl = w - xo;
- memset(dr + xo, 0, xl);
- memset(dg + xo, 0, xl);
- memset(db + xo, 0, xl);
- }
-
- }
- }
- else
- {
- /* outside bounds of image is black */
- memset(dr, 0, w);
- memset(dg, 0, w);
- memset(db, 0, w);
- }
-
- dr += di->BufW;
- dg += di->BufW;
- db += di->BufW;
-
- }
-
- }
-
- return(TRUE);
- }
-
-
- BOOL __regargs PutToBuf (struct Buffer *buf, struct IDrawInfo *di)
- {
- UBYTE *sr, *sg, *sb;
- UBYTE *dr, *dg, *db;
- UBYTE *red, *grn, *blu;
- UBYTE *mask;
- int i, j, x, y, mx, my;
- int left, top;
- short drawpart = (ScanBase->sb_DrawBlend * 255 / 100);
- int mix;
- short r, g, b;
- UBYTE *alphapix;
- struct Buffer *abuf = ScanBase->Alpha;
-
- if (!buf) return(FALSE);
-
- left = di->LE;
- top = di->TE;
-
- /*
- * Read pixels from buffer.
- */
- if (!GetBufLines(buf, &red, &grn, &blu, top, di->Height)) return(FALSE);
-
- /*
- * Put the pixels into the buffer, applying blending and masking.
- * Also clip to buffer boundaries.
- */
- sr = di->OutR;
- sg = di->OutG;
- sb = di->OutB;
- mask = di->Mask;
- for (y = top, j = 0; j < di->Height; j++, y++) {
- if (buf->Mask) my = y - buf->Mask->OffsetY;
- if (y >= 0 && y < buf->Height) {
- dr = red + left + (j * buf->BytesPerRow);
- dg = grn + left + (j * buf->BytesPerRow);
- db = blu + left + (j * buf->BytesPerRow);
- for (x = left, i = 0; i < di->Width; i++, x++) {
- mix = *mask;
- if (buf->Mask) mx = x - buf->Mask->OffsetX;
- if (x >= 0 && x < buf->Width) {
- if (CheckMask(buf->Mask, mx, my)) {
- if (mix && !CheckCloseness(*dr,*dg,*db)) {
- switch(ScanBase->sb_DrawAlpha)
- {
- case 0 : /* alpha = off */
- r = mixer(*sr, *dr, mixer(drawpart,0,mix));
- g = mixer(*sg, *dg, mixer(drawpart,0,mix));
- b = mixer(*sb, *db, mixer(drawpart,0,mix));
- break;
- case 1 : /* alpha = frisket */
- GetBufLine(abuf, &alphapix, NULL, NULL, y % abuf->Height);
- mix = mixer(mix, 0, alphapix[x % abuf->Width]);
- r = mixer(*sr, *dr, mixer(drawpart,0,mix));
- g = mixer(*sg, *dg, mixer(drawpart,0,mix));
- b = mixer(*sb, *db, mixer(drawpart,0,mix));
- break;
- case 2 : /* alpha = texture */
- GetBufLine(abuf, &alphapix, NULL, NULL, y % abuf->Height);
- r = *sr + alphapix[x % abuf->Width] - 128; if (r < 0) r = 0; else if (r > 255) r = 255;
- g = *sg + alphapix[x % abuf->Width] - 128; if (g < 0) g = 0; else if (g > 255) g = 255;
- b = *sb + alphapix[x % abuf->Width] - 128; if (b < 0) b = 0; else if (b > 255) b = 255;
- r = mixer(r, *dr, mixer(drawpart,0,mix));
- g = mixer(g, *dg, mixer(drawpart,0,mix));
- b = mixer(b, *db, mixer(drawpart,0,mix));
- break;
- }
- if (buf->Depth == 1 || (Channel & CHAN_RED)) { *dr = r; }
- if (buf->Depth > 1)
- {
- if (Channel & CHAN_GRN) { *dg = g; }
- if (Channel & CHAN_BLU) { *db = b; }
- }
- }
- }
- }
- dr++; dg++; db++;
- sr++; sg++; sb++;
- mask++;
- }
- }
- else {
- sr += di->Width;
- sg += di->Width;
- sb += di->Width;
- mask += di->Width;
- }
- }
-
- PutBufLines(buf, -1, -1);
- return(TRUE);
- }
-
- #endif
-