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 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 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); }