static int test2(gs_state * pgs, gs_memory_t * mem) { gs_client_color cc; gx_tile_bitmap tile; /*const */ byte tpdata[] = { /* Define a pattern that looks like this: ..xxxx .....x .....x ..xxxx .x.... x..... */ 0x3c, 0, 0, 0, 0x04, 0, 0, 0, 0x04, 0, 0, 0, 0x3c, 0, 0, 0, 0x40, 0, 0, 0, 0x80, 0, 0, 0 }; gs_newpath(pgs); gs_moveto(pgs, 100.0, 300.0); gs_lineto(pgs, 500.0, 500.0); gs_lineto(pgs, 200.0, 100.0); gs_lineto(pgs, 300.0, 500.0); gs_lineto(pgs, 500.0, 200.0); gs_closepath(pgs); gs_setrgbcolor(pgs, 0.0, 0.0, 0.0); gs_gsave(pgs); gs_fill(pgs); gs_grestore(pgs); tile.data = tpdata; tile.raster = 4; tile.size.x = tile.rep_width = 6; tile.size.y = tile.rep_height = 6; tile.id = gx_no_bitmap_id; gs_makebitmappattern(&cc, &tile, true, pgs, NULL); /* Note: color space is DeviceRGB */ cc.paint.values[0] = 0.0; cc.paint.values[1] = 1.0; cc.paint.values[2] = 1.0; gs_setpattern(pgs, &cc); gs_eofill(pgs); gs_makebitmappattern(&cc, &tile, false, pgs, NULL); gs_setcolor(pgs, &cc); gs_moveto(pgs, 50.0, 50.0); gs_lineto(pgs, 300.0, 50.0); gs_lineto(pgs, 50.0, 300.0); gs_closepath(pgs); gs_setrgbcolor(pgs, 1.0, 0.0, 0.0); gs_gsave(pgs); gs_fill(pgs); gs_grestore(pgs); gs_setpattern(pgs, &cc); gs_eofill(pgs); return 0; }
/* set an srgb color */ int pl_setSRGBcolor(gs_state *pgs, float r, float g, float b) { int code; gs_client_color color; #ifdef DEVICE_DOES_COLOR_CONVERSION return gs_setrgbcolor(pgs, r, g, b); #endif /* make sure we have a crd set up */ code = pl_build_crd(pgs); if ( code < 0 ) return code; code = pl_setSRGB(pgs); if ( code < 0 ) return code; /* set the color */ color.paint.values[0] = r; color.paint.values[1] = g; color.paint.values[2] = b; code = gs_setcolor(pgs, &color); return code; }
static int test1(gs_state * pgs, gs_memory_t * mem) { int n; gs_scale(pgs, 72.0, 72.0); gs_translate(pgs, 4.25, 5.5); gs_scale(pgs, 4.0, 4.0); gs_newpath(pgs); for (n = 200; --n >= 0;) { int j; #define rf() (rand() / (1.0 * 0x10000 * 0x8000)) double r = rf(), g = rf(), b = rf(); double x0 = rf(), y0 = rf(), x1 = rf(), y1 = rf(), x2 = rf(), y2 = rf(); gs_setrgbcolor(pgs, r, g, b); for (j = 0; j < 6; j++) { gs_gsave(pgs); gs_rotate(pgs, 60.0 * j); gs_moveto(pgs, x0, y0); gs_lineto(pgs, x1, y1); gs_lineto(pgs, x2, y2); gs_fill(pgs); gs_grestore(pgs); } } #undef mem return 0; }
/* sethsbcolor */ int gs_sethsbcolor(gs_state * pgs, floatp h, floatp s, floatp b) { float rgb[3]; color_hsb_to_rgb(force_unit(h), force_unit(s), force_unit(b), rgb); return gs_setrgbcolor(pgs, rgb[0], rgb[1], rgb[2]); }
int gs_setcolorspace(gs_state *pgs, gs_color_space *pcs) { /****** ONLY IMPLEMENTED FOR Device SPACES ******/ int code; switch ( pcs->type ) { case gs_color_space_DeviceGray: code = gs_setgray(pgs, 0.0); break; case gs_color_space_DeviceRGB: code = gs_setrgbcolor(pgs, 0.0, 0.0, 0.0); break; case gs_color_space_DeviceCMYK: code = gs_setcmykcolor(pgs, 0.0, 0.0, 0.0, 1.0); break; default: code = gs_error_undefined; } return code; }
static int test8(gs_state * pgs, gs_memory_t * mem) { /* * Define a 16 x 16 pattern using a 4-entry palette * (white, red, green, black). */ static const byte pdata[] = { 0x7f, 0xff, 0x00, 0x03, 0x7f, 0xff, 0x00, 0x0c, 0x50, 0x00, 0x00, 0x30, 0x50, 0x00, 0x00, 0xc0, 0x50, 0x00, 0x03, 0x00, 0x50, 0x00, 0x0c, 0x00, 0x50, 0x00, 0x30, 0x00, 0x50, 0x00, 0xc0, 0x00, 0xf0, 0x00, 0xc0, 0x00, 0xf0, 0x00, 0x30, 0x00, 0xf0, 0x00, 0x0c, 0x00, 0xf0, 0x00, 0x03, 0x00, 0xf0, 0x00, 0x00, 0xc0, 0xf0, 0x00, 0x00, 0x30, 0xea, 0x55, 0xaa, 0x5c, 0xea, 0x55, 0xaa, 0x57, }; gs_depth_bitmap ptile; gs_const_string table; gs_color_space *pcs; gs_client_color ccolor; gs_color_space *rgb_cs; rgb_cs = gs_cspace_new_DeviceRGB(mem); table.data = (const byte *)"\377\377\377\377\000\000\000\377\000\000\000\000"; table.size = 12; gs_cspace_build_Indexed(&pcs, rgb_cs, 4, &table, mem); ptile.data = pdata; ptile.raster = 4; ptile.size.x = ptile.size.y = 16; ptile.id = gs_no_bitmap_id; ptile.pix_depth = 2; ptile.num_comps = 1; gs_makepixmappattern(&ccolor, &ptile, false /*mask */ , NULL /*pmat */ , gs_no_id, pcs, 0 /*white_index */ , pgs, mem); { gs_rect r; r.p.x = 100; r.p.y = 100; r.q.x = 200; r.q.y = 200; gs_setrgbcolor(pgs, 1.0, 1.0, 0.0); gs_rectfill(pgs, &r, 1); gs_setpattern(pgs, &ccolor); gs_settexturetransparent(pgs, true); gs_rectfill(pgs, &r, 1); r.p.x += 150; r.q.x += 150; gs_setrgbcolor(pgs, 1.0, 1.0, 0.0); gs_rectfill(pgs, &r, 1); gs_setpattern(pgs, &ccolor); gs_settexturetransparent(pgs, false); gs_rectfill(pgs, &r, 1); } gs_free_object(mem, rgb_cs, "test8 rgb_cs"); return 0; }
static int test5(gs_state * pgs, gs_memory_t * mem) { gx_device *dev = gs_currentdevice(pgs); gx_image_enum_common_t *info; gx_image_plane_t planes[5]; gx_drawing_color dcolor; int code; static const byte data3[] = { 0x00, 0x44, 0x88, 0xcc, 0x44, 0x88, 0xcc, 0x00, 0x88, 0xcc, 0x00, 0x44, 0xcc, 0x00, 0x44, 0x88 }; gs_color_space *gray_cs = gs_cspace_new_DeviceGray(mem); /* * Neither ImageType 3 nor 4 needs a current color, * but some intermediate code assumes it's valid. */ set_nonclient_dev_color(&dcolor, 0); /* Scale everything up, and fill the background. */ { gs_matrix mat; gs_currentmatrix(pgs, &mat); mat.xx = gs_copysign(98.6, mat.xx); mat.yy = gs_copysign(98.6, mat.yy); mat.tx = floor(mat.tx) + 0.499; mat.ty = floor(mat.ty) + 0.499; gs_setmatrix(pgs, &mat); } gs_setrgbcolor(pgs, 1.0, 0.9, 0.9); fill_rect1(pgs, 0.25, 0.25, 4.0, 6.0); gs_setrgbcolor(pgs, 0.5, 1.0, 0.5); #if 0 /* Make things a little more interesting.... */ gs_translate(pgs, 1.0, 1.0); gs_rotate(pgs, 10.0); gs_scale(pgs, 1.3, 0.9); #endif #define do_image(image, idata)\ BEGIN\ code = gx_device_begin_typed_image(dev, (gs_imager_state *)pgs, NULL,\ (gs_image_common_t *)&image, NULL, &dcolor, NULL, mem, &info);\ /****** TEST code >= 0 ******/\ planes[0].data = idata;\ planes[0].data_x = 0;\ planes[0].raster = (image.Height * image.BitsPerComponent + 7) >> 3;\ code = gx_image_plane_data(info, planes, image.Height);\ /****** TEST code == 1 ******/\ code = gx_image_end(info, true);\ /****** TEST code >= 0 ******/\ END #define W 4 #define H 4 /* Test an unmasked image. */ gs_gsave(pgs); { gs_image1_t image1; void *info1; gs_color_space *cs; cs = gs_cspace_new_DeviceGray(mem); gs_image_t_init(&image1, cs); /* image */ image1.ImageMatrix.xx = W; image1.ImageMatrix.yy = -H; image1.ImageMatrix.ty = H; /* data_image */ image1.Width = W; image1.Height = H; image1.BitsPerComponent = 8; gs_translate(pgs, 0.5, 4.0); code = gx_device_begin_image(dev, (gs_imager_state *) pgs, &image1, gs_image_format_chunky, NULL, &dcolor, NULL, mem, &info1); /****** TEST code >= 0 ******/ planes[0].data = data3; planes[0].data_x = 0; planes[0].raster = (image1.Height * image1.BitsPerComponent + 7) >> 3; /* Use the old image_data API. */ code = gx_image_data(info1, &planes[0].data, 0, planes[0].raster, image1.Height); /****** TEST code == 1 ******/ code = gx_image_end(info1, true); /****** TEST code >= 0 ******/ gs_free_object(mem, cs, "colorspace"); } gs_grestore(pgs); /* Test an explicitly masked image. */ gs_gsave(pgs); { gs_image3_t image3; static const byte data3mask[] = { 0x60, 0x90, 0x90, 0x60 }; static const byte data3x2mask[] = { 0x66, 0x99, 0x99, 0x66, 0x66, 0x99, 0x99, 0x66 }; gs_image3_t_init(&image3, gray_cs, interleave_scan_lines); /* image */ image3.ImageMatrix.xx = W; image3.ImageMatrix.yy = -H; image3.ImageMatrix.ty = H; /* data_image */ image3.Width = W; image3.Height = H; image3.BitsPerComponent = 8; /* MaskDict */ image3.MaskDict.ImageMatrix = image3.ImageMatrix; image3.MaskDict.Width = image3.Width; image3.MaskDict.Height = image3.Height; /* Display with 1-for-1 mask and image. */ gs_translate(pgs, 0.5, 2.0); code = gx_device_begin_typed_image(dev, (gs_imager_state *) pgs, NULL, (gs_image_common_t *) & image3, NULL, &dcolor, NULL, mem, &info); /****** TEST code >= 0 ******/ planes[0].data = data3mask; planes[0].data_x = 0; planes[0].raster = (image3.MaskDict.Height + 7) >> 3; planes[1].data = data3; planes[1].data_x = 0; planes[1].raster = (image3.Height * image3.BitsPerComponent + 7) >> 3; code = gx_image_plane_data(info, planes, image3.Height); /****** TEST code == 1 ******/ code = gx_image_end(info, true); /****** TEST code >= 0 ******/ /* Display with 2-for-1 mask and image. */ image3.MaskDict.ImageMatrix.xx *= 2; image3.MaskDict.ImageMatrix.yy *= 2; image3.MaskDict.ImageMatrix.ty *= 2; image3.MaskDict.Width *= 2; image3.MaskDict.Height *= 2; gs_translate(pgs, 1.5, 0.0); code = gx_device_begin_typed_image(dev, (gs_imager_state *) pgs, NULL, (gs_image_common_t *) & image3, NULL, &dcolor, NULL, mem, &info); /****** TEST code >= 0 ******/ planes[0].data = data3x2mask; planes[0].raster = (image3.MaskDict.Width + 7) >> 3; { int i; for (i = 0; i < H; ++i) { planes[1].data = 0; code = gx_image_plane_data(info, planes, 1); planes[0].data += planes[0].raster; /****** TEST code == 0 ******/ planes[1].data = data3 + i * planes[1].raster; code = gx_image_plane_data(info, planes, 1); planes[0].data += planes[0].raster; /****** TEST code >= 0 ******/ } } /****** TEST code == 1 ******/ code = gx_image_end(info, true); /****** TEST code >= 0 ******/ } gs_grestore(pgs); /* Test a chroma-keyed masked image. */ gs_gsave(pgs); { gs_image4_t image4; const byte *data4 = data3; gs_image4_t_init(&image4, gray_cs); /* image */ image4.ImageMatrix.xx = W; image4.ImageMatrix.yy = -H; image4.ImageMatrix.ty = H; /* data_image */ image4.Width = W; image4.Height = H; image4.BitsPerComponent = 8; /* Display with a single mask color. */ gs_translate(pgs, 0.5, 0.5); image4.MaskColor_is_range = false; image4.MaskColor[0] = 0xcc; do_image(image4, data4); /* Display a second time with a color range. */ gs_translate(pgs, 1.5, 0.0); image4.MaskColor_is_range = true; image4.MaskColor[0] = 0x40; image4.MaskColor[1] = 0x90; do_image(image4, data4); } gs_grestore(pgs); gs_free_object(mem, gray_cs, "test5 gray_cs"); #undef W #undef H #undef do_image return 0; }