home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / sharewar / dos / program / gs300sr1 / gs300sr1.exe / ZCOLOR1.C < prev    next >
C/C++ Source or Header  |  1994-07-27  |  8KB  |  249 lines

  1. /* Copyright (C) 1993 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* zcolor1.c */
  20. /* Level 1 extended color operators */
  21. #include "ghost.h"
  22. #include "errors.h"
  23. #include "oper.h"
  24. #include "estack.h"
  25. #include "ialloc.h"
  26. #include "igstate.h"
  27. #include "iutil.h"
  28. #include "store.h"
  29. #include "gxfixed.h"
  30. #include "gxmatrix.h"
  31. #include "gzstate.h"
  32. #include "gxdevice.h"
  33. #include "gxcmap.h"
  34. #include "gscolor1.h"
  35. #include "gscspace.h"
  36.  
  37. /* Import color remapping stuff from zcolor.c. */
  38. /* Define the number of stack slots needed for remap_one. */
  39. extern const int zcolor_remap_one_ostack;
  40. extern const int zcolor_remap_one_estack;
  41. int zcolor_remap_one(P5(const ref *, os_ptr, gx_transfer_map *, const gs_state *, int (*)(P1(os_ptr))));
  42. int
  43.   zcolor_remap_one_finish(P1(os_ptr)),
  44.   zcolor_remap_one_signed_finish(P1(os_ptr)),
  45.   zcolor_remap_color(P1(os_ptr));
  46.  
  47. /* Import image setup from zpaint.c. */
  48. extern int zimage_opaque_setup(P4(os_ptr, bool, const gs_color_space_type _ds *, int));
  49.  
  50. /* zsetcolorscreen is defined in zht.c */
  51. extern int zsetcolorscreen(P1(os_ptr));
  52.  
  53. /* Transfer functions for the library layer. */
  54. /* These just return what's already in the map. */
  55. private float
  56. transfer_red(const gs_state *pgs, floatp value)
  57. {    return gx_map_color_float(pgs, value, transfer.red);
  58. }
  59. private float
  60. transfer_green(const gs_state *pgs, floatp value)
  61. {    return gx_map_color_float(pgs, value, transfer.green);
  62. }
  63. private float
  64. transfer_blue(const gs_state *pgs, floatp value)
  65. {    return gx_map_color_float(pgs, value, transfer.blue);
  66. }
  67. private float
  68. transfer_gray(const gs_state *pgs, floatp value)
  69. {    return gx_map_color_float(pgs, value, transfer.gray);
  70. }
  71. private float
  72. generate_black(const gs_state *pgs, floatp value)
  73. {    return gx_map_color_float(pgs, value, black_generation);
  74. }
  75. private float
  76. remove_undercolor(const gs_state *pgs, floatp value)
  77. {    return gx_map_color_float(pgs, value, undercolor_removal);
  78. }
  79.  
  80. /* - currentblackgeneration <proc> */
  81. int
  82. zcurrentblackgeneration(register os_ptr op)
  83. {    push(1);
  84.     *op = istate->black_generation;
  85.     return 0;
  86. }
  87.  
  88. /* - currentcmykcolor <cyan> <magenta> <yellow> <black> */
  89. int
  90. zcurrentcmykcolor(register os_ptr op)
  91. {    float par[4];
  92.     gs_currentcmykcolor(igs, par);
  93.     push(4);
  94.     make_reals(op - 3, par, 4);
  95.     return 0;
  96. }
  97.  
  98. /* - currentcolortransfer <redproc> <greeproc> <blueproc> <grayproc> */
  99. int
  100. zcurrentcolortransfer(register os_ptr op)
  101. {    push(4);
  102.     op[-3] = istate->transfer_procs.colored.red;
  103.     op[-2] = istate->transfer_procs.colored.green;
  104.     op[-1] = istate->transfer_procs.colored.blue;
  105.     *op = istate->transfer_procs.colored.gray;
  106.     return 0;
  107. }
  108.  
  109. /* - currentundercolorremoval <proc> */
  110. int
  111. zcurrentundercolorremoval(register os_ptr op)
  112. {    push(1);
  113.     *op = istate->undercolor_removal;
  114.     return 0;
  115. }
  116.  
  117. /* <proc> setblackgeneration - */
  118. int
  119. zsetblackgeneration(register os_ptr op)
  120. {    int code;
  121.     check_proc(*op);
  122.     check_ostack(zcolor_remap_one_ostack - 1);
  123.     check_estack(1 + zcolor_remap_one_estack);
  124.     code = gs_setblackgeneration_remap(igs, generate_black, 0);
  125.     if ( code < 0 )
  126.         return code;
  127.     istate->black_generation = *op;
  128.     pop(1);  op--;
  129.     push_op_estack(zcolor_remap_color);
  130.     return zcolor_remap_one(&istate->black_generation, op,
  131.                 igs->black_generation, igs,
  132.                 zcolor_remap_one_finish);
  133. }
  134.  
  135. /* <cyan> <magenta> <yellow> <black> setcmykcolor - */
  136. int
  137. zsetcmykcolor(register os_ptr op)
  138. {    float par[4];
  139.     int code;
  140.     if ( (code = num_params(op, 4, par)) < 0 ||
  141.          (code = gs_setcmykcolor(igs, par[0], par[1], par[2], par[3])) < 0
  142.        )
  143.       return code;
  144.     make_null(&istate->colorspace.array);
  145.     pop(4);
  146.     return 0;
  147. }
  148.  
  149. /* <redproc> <greenproc> <blueproc> <grayproc> setcolortransfer - */
  150. int
  151. zsetcolortransfer(register os_ptr op)
  152. {    int code;
  153.     check_proc(op[-3]);
  154.     check_proc(op[-2]);
  155.     check_proc(op[-1]);
  156.     check_proc(*op);
  157.     check_ostack(zcolor_remap_one_ostack * 4 - 4);
  158.     check_estack(1 + zcolor_remap_one_estack * 4);
  159.     istate->transfer_procs.colored.red = op[-3];
  160.     istate->transfer_procs.colored.green = op[-2];
  161.     istate->transfer_procs.colored.blue = op[-1];
  162.     istate->transfer_procs.colored.gray = *op;
  163.     if ( (code = gs_setcolortransfer_remap(igs, transfer_red, transfer_green, transfer_blue, transfer_gray, 0)) < 0 )
  164.         return code;
  165.     /* Use osp rather than op here, because zcolor_remap_one pushes. */
  166.     pop(4);  op -= 4;
  167.     push_op_estack(zcolor_remap_color);
  168.     if ( (code = zcolor_remap_one(&istate->transfer_procs.colored.red,
  169.                       osp, igs->transfer.red, igs,
  170.                       zcolor_remap_one_finish)) < 0 ||
  171.          (code = zcolor_remap_one(&istate->transfer_procs.colored.green,
  172.                       osp, igs->transfer.green, igs,
  173.                       zcolor_remap_one_finish)) < 0 ||
  174.          (code = zcolor_remap_one(&istate->transfer_procs.colored.blue,
  175.                       osp, igs->transfer.blue, igs,
  176.                       zcolor_remap_one_finish)) < 0
  177.        )
  178.       return code;
  179.     return zcolor_remap_one(&istate->transfer_procs.colored.gray,
  180.                 osp, igs->transfer.gray, igs,
  181.                 zcolor_remap_one_finish);
  182. }
  183.  
  184. /* <proc> setundercolorremoval - */
  185. int
  186. zsetundercolorremoval(register os_ptr op)
  187. {    int code;
  188.     check_proc(*op);
  189.     check_ostack(zcolor_remap_one_ostack - 1);
  190.     check_estack(1 + zcolor_remap_one_estack);
  191.     code = gs_setundercolorremoval_remap(igs, remove_undercolor, 0);
  192.     if ( code < 0 )
  193.         return code;
  194.     istate->undercolor_removal = *op;
  195.     pop(1);  op--;
  196.     push_op_estack(zcolor_remap_color);
  197.     return zcolor_remap_one(&istate->undercolor_removal, op,
  198.                 igs->undercolor_removal, igs,
  199.                 zcolor_remap_one_signed_finish);
  200. }
  201.  
  202. /* <width> <height> <bits/comp> <matrix> */
  203. /*    true <datasrc_0> ... <datasrc_ncomp-1> <ncomp> colorimage - */
  204. /*    false <datasrc> <ncomp> colorimage - */
  205. int
  206. zcolorimage(register os_ptr op)
  207. {    int spp;            /* samples per pixel */
  208.     int npop = 7;
  209.     os_ptr procp = op - 2;
  210.     static const gs_color_space_type _ds *apcst[] = {
  211.         0, &gs_color_space_type_DeviceGray, 0,
  212.         &gs_color_space_type_DeviceRGB,
  213.         &gs_color_space_type_DeviceCMYK
  214.     };
  215.     bool multi = false;
  216.     check_int_leu(*op, 4);        /* ncolors */
  217.     check_type(op[-1], t_boolean);    /* multiproc */
  218.     switch ( (spp = (int)(op->value.intval)) )
  219.     {
  220.     case 1:
  221.         break;
  222.     case 3: case 4:
  223.         if ( op[-1].value.boolval )    /* planar format */
  224.             npop += spp - 1,
  225.             procp -= spp - 1,
  226.             multi = true;
  227.         break;
  228.     default:
  229.         return_error(e_rangecheck);
  230.     }
  231.     return zimage_opaque_setup(procp, multi, apcst[spp], npop);
  232. }
  233.  
  234. /* ------ Initialization procedure ------ */
  235.  
  236. op_def zcolor1_op_defs[] = {
  237.     {"0currentblackgeneration", zcurrentblackgeneration},
  238.     {"0currentcmykcolor", zcurrentcmykcolor},
  239.     {"0currentcolortransfer", zcurrentcolortransfer},
  240.     {"0currentundercolorremoval", zcurrentundercolorremoval},
  241.     {"1setblackgeneration", zsetblackgeneration},
  242.     {"4setcmykcolor", zsetcmykcolor},
  243.     {"4setcolortransfer", zsetcolortransfer},
  244.     {"<setcolorscreen", zsetcolorscreen},    /* in zht.c */
  245.     {"1setundercolorremoval", zsetundercolorremoval},
  246.     {"7colorimage", zcolorimage},
  247.     op_def_end(0)
  248. };
  249.