void wdCanvasStipple(cdCanvas* canvas, int w, int h, const unsigned char *fgbg, double w_mm, double h_mm) { unsigned char *stipple = NULL; int w_pxl, h_pxl, x, y, cx, cy; int wratio, hratio; int *XTab, *YTab; assert(canvas); if (!_cdCheckCanvas(canvas)) return; cdCanvasMM2Pixel(canvas, w_mm, h_mm, &w_pxl, &h_pxl); /* to preserve the pattern characteristics must be an integer number */ wratio = cdRound((double)w_pxl/(double)w); hratio = cdRound((double)h_pxl/(double)h); wratio = (wratio <= 0)? 1: wratio; hratio = (hratio <= 0)? 1: hratio; w_pxl = wratio * w; h_pxl = hratio * h; stipple = (unsigned char*)malloc(w_pxl*h_pxl); XTab = cdGetZoomTable(w_pxl, w, 0); YTab = cdGetZoomTable(h_pxl, h, 0); for (y=0; y<h_pxl; y++) { cy = YTab[y]; for (x=0; x<w_pxl; x++) { cx = XTab[x]; stipple[x + y*w_pxl] = fgbg[cx + cy*w]; } } cdCanvasStipple(canvas, w_pxl, h_pxl, stipple); free(XTab); free(YTab); free(stipple); }
void cdfSimPutImageRectRGBA(cdCanvas* canvas, int iw, int ih, const unsigned char *r, const unsigned char *g, const unsigned char *b, const unsigned char *a, double x, double y, double w, double h, int xmin, int xmax, int ymin, int ymax) { int size, i, j, dst, src, *fx, *fy, rw, rh; unsigned char *ar, *ag, *ab, al; int zw = _cdRound(w); int zh = _cdRound(h); (void)ih; size = zw * zh; ar = (unsigned char*)malloc(size * 3); if (!ar) return; ag = ar + size; ab = ag + size; canvas->cxGetImageRGB(canvas->ctxcanvas, ar, ag, ab, _cdRound(x), _cdRound(y), zw, zh); rw = xmax - xmin + 1; rh = ymax - ymin + 1; fx = cdGetZoomTable(zw, rw, xmin); fy = cdGetZoomTable(zh, rh, ymin); for (j = 0; j < zh; j++) { for (i = 0; i < zw; i++) { dst = j * zw + i; src = fy[j] * iw + fx[i]; al = a[src]; ar[dst] = CD_ALPHA_BLEND(r[src], ar[dst], al); ag[dst] = CD_ALPHA_BLEND(g[src], ag[dst], al); ab[dst] = CD_ALPHA_BLEND(b[src], ab[dst], al); } } canvas->cxFPutImageRectRGB(canvas->ctxcanvas, zw, zh, ar, ag, ab, x, y, w, h, 0, 0, 0, 0); free(ar); free(fx); free(fy); }
void wdCanvasPattern(cdCanvas* canvas, int w, int h, const long *color, double w_mm, double h_mm) { long *pattern = NULL; int w_pxl, h_pxl, x, y, cx, cy; int wratio, hratio; int *XTab, *YTab; assert(canvas); if (!_cdCheckCanvas(canvas)) return; cdCanvasMM2Pixel(canvas, w_mm, h_mm, &w_pxl, &h_pxl); /* to preserve the pattern characteristics must be an integer number */ wratio = cdRound((double)w_pxl/(double)w); hratio = cdRound((double)h_pxl/(double)h); wratio = (wratio <= 0)? 1: wratio; hratio = (hratio <= 0)? 1: hratio; w_pxl = wratio * w; h_pxl = hratio * h; pattern = (long*)malloc(w_pxl*h_pxl*sizeof(long)); XTab = cdGetZoomTable(w_pxl, w, 0); YTab = cdGetZoomTable(h_pxl, h, 0); for (y=0; y<h_pxl; y++) { cy = YTab[y]; for (x=0; x<w_pxl; x++) { cx = XTab[x]; pattern[x + y*w_pxl] = color[cx + cy*w]; } } cdCanvasPattern(canvas, w_pxl, h_pxl, pattern); free(XTab); free(YTab); free(pattern); }
void cdSimPutImageRectRGBA(cdCanvas* canvas, int iw, int ih, const unsigned char *r, const unsigned char *g, const unsigned char *b, const unsigned char *a, int x, int y, int w, int h, int xmin, int xmax, int ymin, int ymax) { int size, i, j, dst, src, *fx, *fy, rw, rh; unsigned char *ar, *ag, *ab, al; (void)ih; size = w * h; ar = (unsigned char*)malloc(size*3); if (!ar) return; ag = ar + size; ab = ag + size; canvas->cxGetImageRGB(canvas->ctxcanvas, ar, ag, ab, x, y, w, h); rw = xmax-xmin+1; rh = ymax-ymin+1; fx = cdGetZoomTable(w, rw, xmin); fy = cdGetZoomTable(h, rh, ymin); for (j = 0; j < h; j++) { for (i = 0; i < w; i++) { dst = j * w + i; src = fy[j] * iw + fx[i]; al = a[src]; ar[dst] = CD_ALPHA_BLEND(r[src], ar[dst], al); ag[dst] = CD_ALPHA_BLEND(g[src], ag[dst], al); ab[dst] = CD_ALPHA_BLEND(b[src], ab[dst], al); } } canvas->cxPutImageRectRGB(canvas->ctxcanvas, w, h, ar, ag, ab, x, y, w, h, 0, 0, 0, 0); free(ar); free(fx); free(fy); }
void wdCanvasStipple(cdCanvas* canvas, int w, int h, const unsigned char *fgbg, double w_mm, double h_mm) { unsigned char *stipple = 0; int w_pxl, h_pxl, x, y, cx, cy; int wratio, hratio; int *XTab, *YTab; cdCanvasMM2Pixel(canvas, w_mm, h_mm, &w_pxl, &h_pxl); wratio = cdRound((double)w_pxl/(double)w); hratio = cdRound((double)h_pxl/(double)h); wratio = (wratio <= 0)? 1: wratio; hratio = (hratio <= 0)? 1: hratio; w_pxl = wratio * w; h_pxl = hratio * h; stipple = (unsigned char*)malloc(w_pxl*h_pxl); XTab = cdGetZoomTable(w_pxl, w, 0); YTab = cdGetZoomTable(h_pxl, h, 0); for (y=0; y<h_pxl; y++) { cy = YTab[y]; for (x=0; x<w_pxl; x++) { cx = XTab[x]; stipple[x + y*w_pxl] = fgbg[cx + cy*w]; } } cdCanvasStipple(canvas, w_pxl, h_pxl, stipple); free(XTab); free(YTab); free(stipple); }
void wdCanvasPattern(cdCanvas* canvas, int w, int h, const long *color, double w_mm, double h_mm) { long *pattern = 0; int w_pxl, h_pxl, x, y, cx, cy; int wratio, hratio; int *XTab, *YTab; cdCanvasMM2Pixel(canvas, w_mm, h_mm, &w_pxl, &h_pxl); wratio = cdRound((double)w_pxl/(double)w); hratio = cdRound((double)h_pxl/(double)h); wratio = (wratio <= 0)? 1: wratio; hratio = (hratio <= 0)? 1: hratio; w_pxl = wratio * w; h_pxl = hratio * h; pattern = (long*)malloc(w_pxl*h_pxl*sizeof(long)); XTab = cdGetZoomTable(w_pxl, w, 0); YTab = cdGetZoomTable(h_pxl, h, 0); for (y=0; y<h_pxl; y++) { cy = YTab[y]; for (x=0; x<w_pxl; x++) { cx = XTab[x]; pattern[x + y*w_pxl] = color[cx + cy*w]; } } cdCanvasPattern(canvas, w_pxl, h_pxl, pattern); free(XTab); free(YTab); free(pattern); }
void cdwDIBEncodeRGBARectZoom(cdwDIB* dib, const unsigned char *red, const unsigned char *green, const unsigned char *blue, const unsigned char *alpha, int w, int h, int xi, int yi, int wi, int hi) { int x,y, resto1, resto2, offset; BYTE* bits; const unsigned char *_red, *_green, *_blue, *_alpha; unsigned char a; bits = dib->bits; resto1 = cdwDIBLineSize(dib->w, 24) - dib->w * 3; if (dib->w != wi || dib->h != hi) { int* XTab = cdGetZoomTable(dib->w, wi, xi); int* YTab = cdGetZoomTable(dib->h, hi, yi); for (y = 0; y < dib->h; y++) { offset = YTab[y] * w; _red = red + offset; _green = green + offset; _blue = blue + offset; _alpha = alpha + offset; for (x = 0; x < dib->w; x++) { offset = XTab[x]; a = _alpha[offset]; *bits++ = CD_ALPHA_BLEND(_blue[offset], *bits, a); *bits++ = CD_ALPHA_BLEND(_green[offset], *bits, a); *bits++ = CD_ALPHA_BLEND(_red[offset], *bits, a); } bits += resto1; } free(XTab); free(YTab); } else { resto2 = w - wi; offset = w * yi + xi; red = red + offset; green = green + offset; blue = blue + offset; alpha = alpha + offset; for (y = 0; y < dib->h; y++) { for (x = 0; x < dib->w; x++) { a = *alpha++; *bits++ = CD_ALPHA_BLEND(*blue++, *bits, a); *bits++ = CD_ALPHA_BLEND(*green++, *bits, a); *bits++ = CD_ALPHA_BLEND(*red++, *bits, a); } bits += resto1; red += resto2; green += resto2; blue += resto2; alpha += resto2; } } }