home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / lib / pict_r.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-20  |  28.8 KB  |  1,187 lines

  1. /*
  2. %    PICT_Read . C
  3. %
  4. %    input PICT (Mac); output 24-bit RLE (ILL), SGF, or SEPLANE.
  5. %
  6. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  7.  
  8. This software is copyright (C) by the Lawrence Berkeley Laboratory.
  9. Permission is granted to reproduce this software for non-commercial
  10. purposes provided that this notice is left intact.
  11.  
  12. It is acknowledged that the U.S. Government has rights to this software
  13. under Contract DE-AC03-765F00098 between the U.S.  Department of Energy
  14. and the University of California.
  15.  
  16. This software is provided as a professional and academic contribution
  17. for joint exchange. Thus, it is experimental, and is provided ``as is'',
  18. with no warranties of any kind whatsoever, no support, no promise of
  19. updates, or printed documentation. By using this software, you
  20. acknowledge that the Lawrence Berkeley Laboratory and Regents of the
  21. University of California shall have no liability with respect to the
  22. infringement of other copyrights by any part of this software.
  23.  
  24. For further information about this notice, contact William Johnston,
  25. Bld. 50B, Rm. 2239, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
  26. (wejohnston@lbl.gov)
  27.  
  28. For further information about this software, contact:
  29.     Jin Guojun
  30.     Bld. 50B, Rm. 2275, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
  31.     g_jin@lbl.gov
  32.  
  33. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  34. % AUTHOR:    Jin Guojun - LBL
  35. */
  36.  
  37. #include "header.def"
  38. #include "imagedef.h"
  39.  
  40. typedef    unsigned short    u_sht;
  41.  
  42. typedef    struct    {
  43.     u_sht    top, left, bottom, right;
  44.     }Rect;
  45.  
  46. typedef    struct    {
  47.     Rect    Bounds;
  48.     u_sht    version,
  49.         packType;
  50.     longword
  51.         packSize,
  52.         hRes,
  53.         vRes;
  54.     u_sht    pixelType,
  55.         pixelSize,
  56.         cmpCount,
  57.         cmpSize;
  58.     longword
  59.         planeBytes,
  60.         pmTable,
  61.         pmReserved;
  62.     } pixMap;
  63.  
  64. typedef    struct    {
  65.     u_sht    red, green, blue;
  66.     } ct_entry;
  67.  
  68. typedef    struct    {
  69.     char*    name;
  70.     int    len;
  71.     void    (*impl)();
  72.     char*    description;
  73.     } opdef;
  74.  
  75. #define WORD_LEN (-1)
  76. /* seems like RGB colours are 6 bytes, but Apple says they're variable */
  77. #define    RGB_LEN    (6)
  78. #define NA    (0)
  79.  
  80. #define    RVD    "reserved"
  81. #define    RVAU    "reserved for Apple use"
  82. #define    RECT    "rect"
  83. #define    RECT_sAaA    "rect, startAngle, arcAngle"
  84. #define    SPOR    skip_poly_or_region
  85.  
  86. /* for reserved opcodes of known length */
  87. #define res(length) \
  88.     { RVD, (length), NULL, RVAU }
  89.  
  90. /* for reserved opcodes of length determined by a function */
  91. #define resf(skipfunction) \
  92.     { RVD, NA, (skipfunction), RVAU }
  93.  
  94. static    void    Clip(), BkPixPat(), PnPixPat(), FillPixPat(), LongText(),
  95.         DHText(), DVText(), DHDVText(), skip_poly_or_region(),
  96.         BitsRect(), BitsRegion(), Opcode_9A(), LongComment(),
  97.         read_rect(), dump_rect(), do_bitmap(), blit(),
  98.         read_pattern(), read_pixmap(), rectinter(), compact_image();
  99. static    byte    *expand_buf();
  100. static    ct_entry    *read_colour_table();
  101.  
  102. static opdef    optable[] = {
  103. /* 0x00 */    { "NOP", 0, NULL, "nop" },
  104. /* 0x01 */    { "Clip", NA, Clip, "clip" },
  105. /* 0x02 */    { "BkPat", 8, NULL, "background pattern" },
  106. /* 0x03 */    { "TxFont", 2, NULL, "text font (u_sht)" },
  107. /* 0x04 */    { "TxFace", 1, NULL, "text face (byte)" },
  108. /* 0x05 */    { "TxMode", 2, NULL, "text mode (u_sht)" },
  109. /* 0x06 */    { "SpExtra", 4, NULL, "space extra (fixed point)" },
  110. /* 0x07 */    { "PnSize", 4, NULL, "pen size (point)" },
  111. /* 0x08 */    { "PnMode", 2, NULL, "pen mode (u_sht)" },
  112. /* 0x09 */    { "PnPat", 8, NULL, "pen pattern" },
  113. /* 0x0a */    { "FillPat", 8, NULL, "fill pattern" },
  114. /* 0x0b */    { "OvSize", 4, NULL, "oval size (point)" },
  115. /* 0x0c */    { "Origin", 4, NULL, "dh, dv (u_sht)" },
  116. /* 0x0d */    { "TxSize", 2, NULL, "text size (u_sht)" },
  117. /* 0x0e */    { "FgColor", 4, NULL, "foreground color (longword)" },
  118. /* 0x0f */    { "BkColor", 4, NULL, "background color (longword)" },
  119. /* 0x10 */    { "TxRatio", 8, NULL, "numer (point), denom (point)" },
  120. /* 0x11 */    { "Version", 1, NULL, "version (byte)" },
  121. /* 0x12 */    { "BkPixPat", NA, BkPixPat, "color background pattern" },
  122. /* 0x13 */    { "PnPixPat", NA, PnPixPat, "color pen pattern" },
  123. /* 0x14 */    { "FillPixPat", NA, FillPixPat, "color fill pattern" },
  124. /* 0x15 */    { "PnLocHFrac", 2, NULL, "fractional pen position" },
  125. /* 0x16 */    { "ChExtra", 2, NULL, "extra for each character" },
  126. /* 0x17 - 0x19    */    res(0),    res(0),    res(0),
  127. /* 0x1a */    { "RGBFgCol", RGB_LEN, NULL, "RGB foreColor" },
  128. /* 0x1b */    { "RGBBkCol", RGB_LEN, NULL, "RGB backColor" },
  129. /* 0x1c */    { "HiliteMode", 0, NULL, "hilite mode flag" },
  130. /* 0x1d */    { "HiliteColor", RGB_LEN, NULL, "RGB hilite color" },
  131. /* 0x1e */    { "DefHilite", 0, NULL, "Use default hilite color" },
  132. /* 0x1f */    { "OpColor", RGB_LEN, NULL, "RGB OpColor for arithmetic modes" },
  133. /* 0x20 */    { "Line", 8, NULL, "pnLoc (point), newPt (point)" },
  134. /* 0x21 */    { "LineFrom", 4, NULL, "newPt (point)" },
  135. /* 0x22 */    { "ShortLine", 6, NULL, "pnLoc (point, dh, dv (-128 .. 127))" },
  136. /* 0x23 */    { "ShortLineFrom", 2, NULL, "dh, dv (-128 .. 127)" },
  137. /* 0x24 - 0x27    */    res(WORD_LEN),    res(WORD_LEN),
  138.             res(WORD_LEN),    res(WORD_LEN),
  139. /* 0x28 */    { "LongText", NA, LongText, "txLoc (point), count (0..255), text" },
  140. /* 0x29 */    { "DHText", NA, DHText, "dh (0..255), count (0..255), text" },
  141. /* 0x2a */    { "DVText", NA, DVText, "dv (0..255), count (0..255), text" },
  142. /* 0x2b */    { "DHDVText", NA, DHDVText, "dh, dv (0..255), count (0..255), text" },
  143. /* 0x2c - 0x2F    */    res(WORD_LEN),    res(WORD_LEN),
  144.             res(WORD_LEN),    res(WORD_LEN),
  145. /* 0x30 */    { "frameRect", 8, NULL, RECT },
  146. /* 0x31 */    { "paintRect", 8, NULL, RECT },
  147. /* 0x32 */    { "eraseRect", 8, NULL, RECT },
  148. /* 0x33 */    { "invertRect", 8, NULL, RECT },
  149. /* 0x34 */    { "fillRect", 8, NULL, RECT },
  150. /* 0x35 - 0x37    */    res(8),    res(8),    res(8),
  151. /* 0x38 */    { "frameSameRect", 0, NULL, RECT },
  152. /* 0x39 */    { "paintSameRect", 0, NULL, RECT },
  153. /* 0x3a */    { "eraseSameRect", 0, NULL, RECT },
  154. /* 0x3b */    { "invertSameRect", 0, NULL, RECT },
  155. /* 0x3c */    { "fillSameRect", 0, NULL, RECT },
  156. /* 0x3d - 0x3F    */    res(0),    res(0),    res(0),
  157. /* 0x40 */    { "frameRRect", 8, NULL, RECT },
  158. /* 0x41 */    { "paintRRect", 8, NULL, RECT },
  159. /* 0x42 */    { "eraseRRect", 8, NULL, "rect" },
  160. /* 0x43 */    { "invertRRect", 8, NULL, "rect" },
  161. /* 0x44 */    { "fillRRrect", 8, NULL, "rect" },
  162. /* 0x45 - 0x47    */    res(8),    res(8),    res(8),
  163. /* 0x48 */    { "frameSameRRect", 0, NULL, "rect" },
  164. /* 0x49 */    { "paintSameRRect", 0, NULL, "rect" },
  165. /* 0x4a */    { "eraseSameRRect", 0, NULL, "rect" },
  166. /* 0x4b */    { "invertSameRRect", 0, NULL, "rect" },
  167. /* 0x4c */    { "fillSameRRect", 0, NULL, "rect" },
  168. /* 0x4d - 0x4F    */    res(0),    res(0),    res(0),
  169. /* 0x50 */    { "frameOval", 8, NULL, "rect" },
  170. /* 0x51 */    { "paintOval", 8, NULL, "rect" },
  171. /* 0x52 */    { "eraseOval", 8, NULL, "rect" },
  172. /* 0x53 */    { "invertOval", 8, NULL, "rect" },
  173. /* 0x54 */    { "fillOval", 8, NULL, "rect" },
  174. /* 0x55 - 0x57    */    res(8),    res(8),    res(8),
  175. /* 0x58 */    { "frameSameOval", 0, NULL, "rect" },
  176. /* 0x59 */    { "paintSameOval", 0, NULL, "rect" },
  177. /* 0x5a */    { "eraseSameOval", 0, NULL, "rect" },
  178. /* 0x5b */    { "invertSameOval", 0, NULL, "rect" },
  179. /* 0x5c */    { "fillSameOval", 0, NULL, "rect" },
  180. /* 0x5d */    res(0),
  181.         res(0),
  182. /* 0x5f */    res(0),
  183. /* 0x60 */    { "frameArc", 12, NULL, RECT_sAaA },
  184. /* 0x61 */    { "paintArc", 12, NULL, RECT_sAaA },
  185. /* 0x62 */    { "eraseArc", 12, NULL, RECT_sAaA },
  186. /* 0x63 */    { "invertArc", 12, NULL, RECT_sAaA },
  187. /* 0x64 */    { "fillArc", 12, NULL, RECT_sAaA },
  188. /* 0x65 */    res(12),
  189.         res(12),
  190. /* 0x67 */    res(12),
  191. /* 0x68 */    { "frameSameArc", 4, NULL, RECT_sAaA },
  192. /* 0x69 */    { "paintSameArc", 4, NULL, RECT_sAaA },
  193. /* 0x6a */    { "eraseSameArc", 4, NULL, RECT_sAaA },
  194. /* 0x6b */    { "invertSameArc", 4, NULL, RECT_sAaA },
  195. /* 0x6c */    { "fillSameArc", 4, NULL, RECT_sAaA },
  196. /* 0x6d */    res(4),
  197.         res(4),
  198. /* 0x6f */    res(4),
  199. /* 0x70 */    { "framePoly", NA, SPOR, "poly" },
  200. /* 0x71 */    { "paintPoly", NA, SPOR, "poly" },
  201. /* 0x72 */    { "erasePoly", NA, SPOR, "poly" },
  202. /* 0x73 */    { "invertPoly", NA, SPOR, "poly" },
  203. /* 0x74 */    { "fillPoly", NA, SPOR, "poly" },
  204. /* 0x75 */    resf(SPOR),
  205.         resf(SPOR),
  206.         resf(SPOR),
  207. /* 0x78 */    { "frameSamePoly", 0, NULL, "poly (NYI)" },
  208. /* 0x79 */    { "paintSamePoly", 0, NULL, "poly (NYI)" },
  209. /* 0x7a */    { "eraseSamePoly", 0, NULL, "poly (NYI)" },
  210. /* 0x7b */    { "invertSamePoly", 0, NULL, "poly (NYI)" },
  211. /* 0x7c */    { "fillSamePoly", 0, NULL, "poly (NYI)" },
  212. /* 0x7d */    res(0),
  213. /* 0x7e */    res(0),
  214. /* 0x7f */    res(0),
  215. /* 0x80 */    { "frameRgn", NA, SPOR, "region" },
  216. /* 0x81 */    { "paintRgn", NA, SPOR, "region" },
  217. /* 0x82 */    { "eraseRgn", NA, SPOR, "region" },
  218. /* 0x83 */    { "invertRgn", NA, SPOR, "region" },
  219. /* 0x84 */    { "fillRgn", NA, SPOR, "region" },
  220. /* 0x85 */    resf(SPOR),
  221.         resf(SPOR),
  222. /* 0x87 */    resf(SPOR),
  223. /* 0x88 */    { "frameSameRgn", 0, NULL, "region (NYI)" },
  224. /* 0x89 */    { "paintSameRgn", 0, NULL, "region (NYI)" },
  225. /* 0x8a */    { "eraseSameRgn", 0, NULL, "region (NYI)" },
  226. /* 0x8b */    { "invertSameRgn", 0, NULL, "region (NYI)" },
  227. /* 0x8c */    { "fillSameRgn", 0, NULL, "region (NYI)" },
  228. /* 0x8d */    res(0),
  229.         res(0),
  230. /* 0x8f */    res(0),
  231. /* 0x90 */    { "BitsRect", NA, BitsRect, "copybits, rect clipped" },
  232. /* 0x91 */    { "BitsRgn", NA, BitsRegion, "copybits, rgn clipped" },
  233. /* 0x92 */    res(WORD_LEN),
  234.         res(WORD_LEN),
  235.         res(WORD_LEN),
  236.         res(WORD_LEN),
  237.         res(WORD_LEN),
  238. /* 0x97 */    res(WORD_LEN),
  239. /* 0x98 */    { "PackBitsRect", NA, BitsRect, "packed copybits, rect clipped" },
  240. /* 0x99 */    { "PackBitsRgn", NA, BitsRegion, "packed copybits, rgn clipped" },
  241. /* 0x9a */    { "Opcode_9A", NA, Opcode_9A, "the mysterious opcode 9A" },
  242. /* 0x9b */    res(WORD_LEN),
  243.         res(WORD_LEN),
  244.         res(WORD_LEN),
  245.         res(WORD_LEN),
  246. /* 0x9f */    res(WORD_LEN),
  247. /* 0xa0 */    { "ShortComment", 2, NULL, "kind (u_sht)" },
  248. /* 0xa1 */    { "LongComment", NA, LongComment, "kind (u_sht), size (u_sht), data" }
  249. };
  250.  
  251. static    int    align, version;
  252. static    Rect    picFrame;
  253. static    u_sht    *red, *green, *blue,
  254.         rowlen;
  255. static longword    planelen;
  256.  
  257. static
  258. read_byte(infp)
  259. FILE*    infp;
  260. {
  261.     ++align;
  262.     return    fgetc(infp);
  263. }
  264.  
  265. static
  266. read_u_sht(infp)
  267. FILE*    infp;
  268. {
  269. int    bh, bl;
  270.  
  271.     bh = read_byte(infp);    bl = read_byte(infp);
  272.     if (bh<0 || bl<0)
  273.         return    -1;
  274.     return((bh << 8) | bl);
  275. }
  276.  
  277. static longword
  278. read_long(infp)
  279. FILE*    infp;
  280. {
  281. int    lh = read_u_sht(infp);
  282.     return((lh << 16) | read_u_sht(infp));
  283. }
  284.  
  285. static
  286. skip(n, infp)
  287. FILE*    infp;
  288. {
  289. char    buf[1024];
  290.  
  291.     for (align += n; n > 0; n -= 1024)
  292.         if (fread(buf, n > 1024 ? 1024 : n, 1, infp) != 1)
  293.         return    prgmerr(DEBUGANY, "EOF / while skip %d", n);
  294.     return    0;
  295. }
  296.  
  297. static
  298. read_n(n, buf, infp)
  299. char*    buf;
  300. FILE    *infp;
  301. {
  302.     align += n;
  303.     if (fread(buf, n, 1, infp) != 1)
  304.         return    prgmerr(0, "EOF / read %d", n);
  305.     return    n;
  306. }
  307.  
  308. /*
  309. *    data in version 2 is u_sht aligned. Odd size data is padded with 0.
  310. */
  311. static
  312. get_op(version, infp)
  313. FILE*    infp;
  314. {
  315.     if ((align & 1) && version == 2)
  316.         read_byte(infp);    /* align for opcode */
  317.  
  318.     /*    reading opcode    */
  319.     if (version == 1)
  320.         return    (read_byte(infp));
  321.     else
  322.         return    (read_u_sht(infp));
  323. }
  324.  
  325.  
  326. pict_header_handle(job, img, ac, av, assist)
  327. U_IMAGE    *img;
  328. int    ac;
  329. char    **av;
  330. VType    *assist;
  331. {
  332. byte    ch;
  333. u_sht    picSize;
  334.  
  335.     switch (job) {
  336.     case HEADER_READ:
  337.     case HEADER_FREAD:
  338.     if (!av)
  339.         fseek(img->IN_FP, 0, 0);
  340.  
  341.     /*    pass 512 byte header    */
  342.     skip(512, img->IN_FP);
  343.     picSize = read_u_sht(img->IN_FP);
  344.  
  345.     DEBUGMESSAGE("picture size = %d (0x%x)", picSize, picSize);
  346.  
  347.     read_rect(&picFrame, img->IN_FP);
  348.  
  349.     if (DEBUGANY) {
  350.         dump_rect("Picture frame:", &picFrame);
  351.         message("Picture size is %d x %d",
  352.             picFrame.right - picFrame.left,
  353.             picFrame.bottom - picFrame.top);
  354.     }
  355.  
  356.     /* allocation is same for version 1 or version 2.  We are super-duper
  357.      * wasteful of memory for version 1 picts.  Someday, we'll separate
  358.      * things and only allocate a byte per pixel for version 1 (or heck,
  359.      * even only a bit, but that would require even more extra work).
  360.      */
  361.  
  362.     img->width = rowlen = picFrame.right - picFrame.left;
  363.     img->height = picFrame.bottom - picFrame.top;
  364.     planelen = rowlen * img->height;
  365.  
  366.     img->pxl_in = 1;
  367.     img->channels = 3;
  368.     img->in_type = PICT;
  369.  
  370.     while (!(ch = read_byte(img->IN_FP)));
  371.  
  372.     if (ch != 0x11)
  373. pict_hderr:    return    EOF;
  374.  
  375.     switch (read_byte(img->IN_FP)) {
  376.     case 1:
  377.         version = 1;
  378.         img->in_form = IFMT_SCF;
  379.         break;
  380.     case 2:
  381.         if (read_byte(img->IN_FP) != 0xff)    {
  382.             mesg("version 2, only subcode 0xff");
  383.             goto    pict_hderr;
  384.         }
  385.         img->in_form = IFMT_SEPLANE;
  386.         version = 2;
  387.         break;
  388.     default:    goto    pict_hderr;
  389.     }
  390.     img->in_color = CFM_SEPLANE;
  391.     break;
  392.     case HEADER_WRITE:
  393.     default:    return    prgmerr(0, "no such a pict job %d\n", job);
  394.     }
  395. DEBUGMESSAGE("PICT version %d", version);
  396. return    0;
  397. }
  398.  
  399. read_pict_image(img, OsameI8)
  400. U_IMAGE    *img;
  401. {
  402. int    opcode,    len, rows = img->height, cols = img->width;
  403.  
  404. verify_buffer_size(&img->src, rows*cols, img->channels, "pict-src");
  405.  
  406. red = nzalloc(rows * cols, 3 * sizeof(*red), "pict-rect");
  407. green = red + rows * cols;
  408. blue = green + rows * cols;
  409.  
  410.     while((opcode = get_op(version, img->IN_FP)) != 0xFF) {
  411.         if (opcode < 0xA2) {
  412.         if (optable[opcode].impl != NULL)
  413.             (*optable[opcode].impl)(version, img->IN_FP);
  414.         else if (optable[opcode].len >= 0)
  415.             skip(optable[opcode].len, img->IN_FP);
  416.         else switch (optable[opcode].len) {
  417.         case WORD_LEN:
  418.             len = read_u_sht(img->IN_FP);
  419.             skip(len, img->IN_FP);
  420.             break;
  421.         default:
  422.             return    prgmerr(DEBUGANY, "can't do length of %d",
  423.                     optable[opcode].len);
  424.         }
  425.         }
  426.         else if (opcode == 0xC00) {
  427.         DEBUGMESSAGE("HeaderOp");
  428.         skip(24, img->IN_FP);
  429.         }
  430.         else if (opcode > 0xA1 && opcode < 0xB0) {
  431.         DEBUGMESSAGE("skip reserved 0x%X", opcode);
  432.         skip(read_u_sht(img->IN_FP), img->IN_FP);
  433.         }
  434.         else if (opcode >= 0xB0 && opcode < 0xD0) {
  435.         /* just a reserved opcode, no data */
  436.         DEBUGMESSAGE("reserved 0x%X", opcode);
  437.         }
  438.         else if (opcode >= 0xD0 && opcode < 0x100) {
  439.         DEBUGMESSAGE("skip 0x%X", opcode);
  440.         skip(read_long(img->IN_FP), img->IN_FP);
  441.         }
  442.         else if (opcode >= 0x100 && opcode < 0x8000) {
  443.         DEBUGMESSAGE("skip 0x%X", opcode);
  444.         skip((opcode >> 7) & 255, img->IN_FP);
  445.         }
  446.         else if (opcode >= 0x8000 && opcode < 0x8100) {
  447.         /* just a reserved opcode */
  448.         DEBUGMESSAGE("reserved 0x%X", opcode);
  449.         }
  450.         else if (opcode >= 8100 && opcode < 0x10000) {
  451.         DEBUGMESSAGE("skipping 0x%X", opcode);
  452.         skip(read_long(img->IN_FP), img->IN_FP);
  453.         }
  454.         else    return    prgmerr(0, "can't handle opcode of %X", opcode);
  455.     }
  456.     if (img->mid_type==ICC || img->color_form==CFM_SEPLANE)    {
  457.         compact_image(red, img->src, planelen);
  458.         compact_image(green, (char*)img->src + planelen, planelen);
  459.         compact_image(blue, (char*)img->src + (planelen<<1), planelen);
  460.     }
  461.     else if (img->color_form == CFM_SGF)    {
  462.         compact_image(red, red, planelen);
  463.         compact_image(blue, blue, planelen);
  464.         compact_image(green, green, planelen);
  465.         ill_to_gray(img->src, red, green, blue, planelen);
  466.     }
  467.     else    {    /*    default to RLE    */
  468.     char    *p = img->src;
  469.     register int    lin_inc;
  470.         for (len=lin_inc=0; len < rows; len++)    {
  471.         compact_image(red + lin_inc, p, cols);    p += cols;
  472.         compact_image(green+ lin_inc, p, cols);    p += cols;
  473.         compact_image(blue + lin_inc, p, cols);    p += cols;
  474.         lin_inc += cols;
  475.         }
  476.     }
  477.     free(red);
  478. if (img->mid_type == RLE)
  479.     img->channels = img->dpy_channels;
  480. return    cols * rows;
  481. }
  482.  
  483.  
  484. static
  485. rectequal(r1, r2)
  486. Rect    *r1, *r2;
  487. {
  488. return    (r1->top == r2->top && r1->bottom == r2->bottom &&
  489.     r1->left == r2->left && r1->right == r2->right);
  490. }
  491.  
  492. static
  493. rectsamesize(r1, r2)
  494. Rect    *r1, *r2;
  495. {
  496. return    (r1->right - r1->left == r2->right - r2->left &&
  497.     r1->bottom - r1->top == r2->bottom - r2->top);
  498. }
  499.  
  500. static void
  501. rectinter(r1, r2, r3)
  502. Rect    *r1, *r2, *r3;
  503. {
  504.     r3->left = MAX(r1->left, r2->left);
  505.     r3->top = MAX(r1->top, r2->top);
  506.     r3->right = MIN(r1->right, r2->right);
  507.     r3->bottom = MIN(r1->bottom, r2->bottom);
  508. }
  509.  
  510.  
  511. static void
  512. read_rect(r, infp)
  513. Rect*    r;
  514. FILE*    infp;
  515. {
  516.     r->top = read_u_sht(infp);
  517.     r->left = read_u_sht(infp);
  518.     r->bottom = read_u_sht(infp);
  519.     r->right = read_u_sht(infp);
  520. }
  521.  
  522. static void
  523. dump_rect(s, r)
  524. char*    s;
  525. Rect*    r;
  526. {
  527.     message("%s (%d,%d) (%d,%d)", s, r->left, r->top, r->right, r->bottom);
  528. }
  529.  
  530. static void
  531. compact_image(in, out, len)
  532. register u_sht*    in;
  533. register byte*    out;
  534. register int    len;
  535. {
  536.     while (len--)
  537.         *out++ = (*in++ >> 8) & 0xFF;
  538. }
  539.  
  540. /*
  541. %    READ_PIXMAP . C
  542. %
  543. % George Phillips <phillips@cs.ubc.ca>
  544. % Department of Computer Science
  545. % University of British Columbia
  546. %
  547. % This could use read_pixmap, but I'm too lazy to hack read_pixmap.
  548. %
  549. % Permission is granted to freely distribute this program in whole or in
  550. % part provided you don't make money off it, you don't pretend that you
  551. % wrote it and that this notice accompanies the code.
  552. %
  553. % Modified:    Jin, Guojun
  554. % Date:    Sat, Feb 15, 1992
  555. % ITG - Lawrence Berkeley Laboratory
  556. */
  557.  
  558. #if __STDC__
  559. static byte*
  560. unpackbits(Rect* bounds, u_sht rowBytes, int pixelSize, FILE* infp)
  561. #else /*__STDC__*/
  562. static byte*
  563. unpackbits(bounds, rowBytes, pixelSize, infp)
  564. Rect    *bounds;
  565. u_sht    rowBytes;
  566. #endif /*__STDC__*/
  567. {
  568. byte    *linebuf,
  569.     *pm, *pm_ptr;
  570. register int    i,j;
  571. u_sht    pixwidth;
  572. int    linelen, len;
  573. byte*    bytepixels;
  574. int    buflen, pkpixsize;
  575.  
  576.     if (pixelSize <= 8)
  577.         rowBytes &= 0x7fff;
  578.  
  579.     /*    unpacking packbits    */
  580.  
  581.     pixwidth = bounds->right - bounds->left;
  582.  
  583.     pkpixsize = 1;
  584.     if (pixelSize == 16)
  585.         pixwidth *= (pkpixsize = 2);
  586.     else if (pixelSize == 32)
  587.         pixwidth *= 3;
  588.  
  589.     if (!rowBytes)
  590.         rowBytes = pixwidth;
  591.  
  592.     /* we're sloppy and allocate some extra space because we can overshoot
  593.     * by as many as 8 bytes when we unpack the raster lines.  Really, I
  594.     * should be checking to see if we go over the scan line (it is
  595.     * possbile) and complain of a corrupt file.  That fix is more complex
  596.     * (and probably costly in CPU cycles) and will have to come later.
  597.     */
  598.     pm = (byte*)nzalloc(pixwidth * (bounds->bottom - bounds->top) + 8,
  599.         sizeof(*pm), "packbits rectangle");
  600.  
  601.     /* Sometimes we get rows with length > rowBytes.  I'll allocate some
  602.     * extra for slop and only die if the size is _way_ out of wack.
  603.     */
  604.     linebuf = (byte*)nzalloc(rowBytes + 100, 1, "line buf");
  605.  
  606.     if (rowBytes < 8) {
  607.     /* ah-ha!  The bits aren't actually packed.  This will be easy */
  608.         for (i=0; i < bounds->bottom - bounds->top; i++) {
  609.             pm_ptr = pm + i * pixwidth;
  610.             read_n(buflen = rowBytes, linebuf, infp);
  611.             bytepixels = expand_buf(linebuf, &buflen, pixelSize);
  612.             for (j = 0; j < buflen; j++)
  613.                 *pm_ptr++ = *bytepixels++;
  614.         }
  615.     } else    for (i=0; i < bounds->bottom - bounds->top; i++) {
  616.             pm_ptr = pm + i * pixwidth;
  617.             if (rowBytes > 250 || pixelSize > 8)
  618.                 linelen = read_u_sht(infp);
  619.             else
  620.                 linelen = read_byte(infp);
  621.  
  622.             DEBUGMESSAGE("linelen: %d", linelen);
  623.  
  624.             if (linelen > rowBytes)
  625.                 message("linelen > rowbytes! (%d > %d) at line %d",
  626.                 linelen, rowBytes, i);
  627.  
  628.             read_n(linelen, linebuf, infp);
  629.  
  630.             for (j=0; j < linelen; j += buflen + 1) {
  631.             register int    k, l;
  632.                 if (linebuf[j] & 0x80) {
  633.                     len = ((linebuf[j] ^ 255) & 255) + 2;
  634.                     buflen = pkpixsize;
  635.                     bytepixels = expand_buf(linebuf + j+1, &buflen, pixelSize);
  636.                     for (l=len; l--; bytepixels -= buflen)
  637.                         for (k=buflen; k--;)
  638.                         *pm_ptr++ = *bytepixels++;
  639.                 }
  640.                 else {
  641.                     len = (linebuf[j] & 255) + 1;
  642.                     buflen = len * pkpixsize;
  643.                     bytepixels = expand_buf(linebuf + j+1, &buflen, pixelSize);
  644.                     for (k=buflen; k--;)
  645.                         *pm_ptr++ = *bytepixels++;
  646.                 }
  647.             }
  648.     }
  649.  
  650.     free(linebuf);
  651.     return(pm);
  652. }
  653.  
  654. static void
  655. Opcode_9A(version, infp)
  656. FILE*    infp;
  657. {
  658. #ifdef DUMP
  659.     int    ch;
  660.     FILE    *fp = fopen("data", "w");
  661.     if (fp == NULL)
  662.         exit(1);
  663.     while ((ch = fgetc(infp)) != EOF) fputc(ch, fp);
  664.     exit(0);
  665. #else
  666. pixMap    p;
  667. Rect    srcRect,
  668.     dstRect;
  669. byte*    pm;
  670. int    pixwidth;
  671. u_sht    mode;
  672.  
  673.     /* skip fake len, and fake EOF */
  674.     skip(4, infp);
  675.     read_u_sht(infp);    /* version */
  676.     read_rect(&p.Bounds, infp);
  677.     pixwidth = p.Bounds.right - p.Bounds.left;
  678.     p.packType = read_u_sht(infp);
  679.     p.packSize = read_long(infp);
  680.     p.hRes = read_long(infp);
  681.     p.vRes = read_long(infp);
  682.     p.pixelType = read_u_sht(infp);
  683.     p.pixelSize = read_u_sht(infp);
  684.     p.pixelSize = read_u_sht(infp);
  685.     p.cmpCount = read_u_sht(infp);
  686.     p.cmpSize = read_u_sht(infp);
  687.     p.planeBytes = read_long(infp);
  688.     p.pmTable = read_long(infp);
  689.     p.pmReserved = read_long(infp);
  690.  
  691.     if (p.pixelSize == 16)
  692.         pixwidth <<= 1;
  693.     else if (p.pixelSize == 32)
  694.         pixwidth *= 3;
  695.  
  696.     read_rect(&srcRect, infp);
  697.     if (DEBUGANY)    dump_rect("source rectangle:", &srcRect);
  698.  
  699.     read_rect(&dstRect, infp);
  700.     if (DEBUGANY)    dump_rect("destination rectangle:", &dstRect);
  701.  
  702.     mode = read_u_sht(infp);
  703.     DEBUGMESSAGE("mode = %x", mode);
  704.  
  705.     pm = unpackbits(&p.Bounds, 0, p.pixelSize, infp);
  706.  
  707.     blit(&srcRect, &(p.Bounds), pixwidth, pm, p.pixelSize,
  708.         &dstRect, &picFrame, rowlen, NULL, mode);
  709.  
  710.     free(pm);
  711. #endif
  712. }
  713.  
  714. #if __STDC__
  715. static void
  716. do_pixmap(int version, u_sht rowBytes, int is_region, FILE* infp)
  717. #else /*__STDC__*/
  718. static void
  719. do_pixmap(version, rowBytes, is_region, infp)
  720. u_sht rowBytes;
  721. FILE*    infp;
  722. #endif /*__STDC__*/
  723. {
  724. pixMap    p;
  725. u_sht    mode, pixwidth;
  726. byte*    pm;
  727. ct_entry*    colour_table;
  728. Rect    srcRect,
  729.     dstRect;
  730.  
  731.     read_pixmap(&p, NULL, infp);
  732.  
  733.     pixwidth = p.Bounds.right - p.Bounds.left;
  734.  
  735.     DEBUGMESSAGE("%d x %d rectangle", pixwidth,
  736.             p.Bounds.bottom - p.Bounds.top);
  737.  
  738.     colour_table = read_colour_table(infp);
  739.  
  740.     read_rect(&srcRect, infp);
  741.     if (DEBUGANY)
  742.         dump_rect("source rectangle:", &srcRect);
  743.  
  744.     read_rect(&dstRect, infp);
  745.     if (DEBUGANY)
  746.         dump_rect("destination rectangle:", &dstRect);
  747.  
  748.     mode = read_u_sht(infp);
  749.     DEBUGMESSAGE("mode = %x", mode);
  750.  
  751.     if (is_region)
  752.         skip_poly_or_region(version, infp);
  753.  
  754.     /*    unpacking rectangle    */
  755.  
  756.     pm = unpackbits(&p.Bounds, rowBytes, p.pixelSize, infp);
  757.  
  758.     blit(&srcRect, &(p.Bounds), pixwidth, pm, 8,
  759.         &dstRect, &picFrame, rowlen, colour_table, mode);
  760.  
  761.     free(colour_table);
  762.     free(pm);
  763. }
  764.  
  765. static void
  766. BitsRect(version, infp)
  767. FILE*    infp;
  768. {
  769. u_sht    rowBytes;
  770.  
  771.     /*    for bitsrect    */
  772.     rowBytes = read_u_sht(infp);
  773.  
  774.     DEBUGMESSAGE("rowbytes = 0x%x (%d)", rowBytes, rowBytes & 0x7FFF);
  775.  
  776.     if (rowBytes & 0x8000)
  777.         do_pixmap(version, rowBytes, 0, infp);
  778.     else
  779.         do_bitmap(version, rowBytes, 0, infp);
  780. }
  781.  
  782. static void
  783. BitsRegion(version, infp)
  784. FILE*    infp;
  785. {
  786. u_sht    rowBytes;
  787.  
  788.     /*    for bitsregion    */
  789.     rowBytes = read_u_sht(infp);
  790.  
  791.     if (rowBytes & 0x8000)
  792.         do_pixmap(version, rowBytes, 1, infp);
  793.     else    do_bitmap(version, rowBytes, 1, infp);
  794. }
  795.  
  796. static void
  797. do_bitmap(version, rowBytes, is_region, infp)
  798. u_sht    rowBytes;
  799. FILE*    infp;
  800. {
  801. Rect    Bounds,
  802.     srcRect,
  803.     dstRect;
  804. u_sht    mode;
  805. byte*    pm;
  806. static ct_entry colour_table[] = { {65535L, 65535L, 65535L}, {0, 0, 0} };
  807.  
  808.     read_rect(&Bounds, infp);
  809.     read_rect(&srcRect, infp);
  810.     read_rect(&dstRect, infp);
  811.     mode = read_u_sht(infp);
  812.  
  813.     if (is_region)
  814.         skip_poly_or_region(version, infp);
  815.  
  816.     /*    unpacking rectangle    */
  817.     pm = unpackbits(&Bounds, rowBytes, 1, infp);
  818.  
  819.     blit(&srcRect, &Bounds, Bounds.right - Bounds.left, pm, 8,
  820.         &dstRect, &picFrame, rowlen, colour_table, mode);
  821.  
  822.     free(pm);
  823. }
  824.  
  825. static void
  826. blit(srcRect, srcBounds, srcwid, srcplane, pixSize, dstRect, dstBounds, dstwid, colour_map, mode)
  827. Rect    *srcRect,
  828.     *srcBounds;
  829. int    srcwid;
  830. byte*    srcplane;
  831. int    pixSize;
  832. Rect    *dstRect,
  833.     *dstBounds;
  834. int    dstwid;
  835. ct_entry    *colour_map;
  836. int    mode;
  837. {
  838. Rect    clipsrc,
  839.     clipdst;
  840. register byte*    src;
  841. register u_sht    *reddst,
  842.         *greendst,
  843.         *bluedst;
  844. register int    i, j;
  845. int    dstoff, xsize, ysize,
  846.     srcadd, dstadd, pkpixsize;
  847. ct_entry* ct;
  848.  
  849.     /* almost got it.  clip source rect with source bounds.
  850.     * clip dest rect with dest bounds.
  851.     * If they're not the same size - die!
  852.     * (it would require zeroing some area!)
  853.     * co-ordinate translations are actually done!
  854.     */
  855.     rectinter(srcBounds, srcRect, &clipsrc);
  856.     rectinter(dstBounds, dstRect, &clipdst);
  857.  
  858.     if (DEBUGANY) {
  859.         dump_rect("copying from:", &clipsrc);
  860.         dump_rect("to:          ", &clipdst);
  861.     }
  862.  
  863.     if (!rectsamesize(&clipsrc, &clipdst))
  864.         message("warning, rectangles of different sizes after clipping!");
  865.  
  866.  
  867.     /* lots of assumptions about 8 bits per component, chunky bits, etc! */
  868.  
  869.     pkpixsize = 1;
  870.     if (pixSize == 16)
  871.         pkpixsize = 2;
  872.  
  873.     src = srcplane + (clipsrc.top - srcBounds->top) * srcwid +
  874.         (clipsrc.left - srcBounds->left) * pkpixsize;
  875.     dstoff = (clipdst.top - dstBounds->top) * dstwid +
  876.         (clipdst.left - dstBounds->left);
  877.  
  878.     reddst = red + dstoff;
  879.     greendst = green + dstoff;
  880.     bluedst = blue + dstoff;
  881.  
  882.     xsize = clipsrc.right - clipsrc.left;
  883.     ysize = clipsrc.bottom - clipsrc.top;
  884.     srcadd = srcwid - xsize * pkpixsize;
  885.     dstadd = dstwid - xsize;
  886.  
  887.     switch (pixSize) {
  888.     case 8:
  889.         for (i=0; i < ysize; i++) {
  890.             for (j=xsize; j--;) {
  891.                 ct = colour_map + *src++;
  892.                 *reddst++ = ct->red;
  893.                 *greendst++ = ct->green;
  894.                 *bluedst++ = ct->blue;
  895.             }
  896.             src += srcadd;
  897.             reddst += dstadd;
  898.             greendst += dstadd;
  899.             bluedst += dstadd;
  900.         }
  901.         break;
  902.     case 16:
  903.         for (i = 0; i < ysize; ++i) {
  904.             for (j = 0; j < xsize; ++j) {
  905.                 *reddst++ = (*src & 0x7c) << 9;
  906.                 *greendst = (*src++ & 3) << 14;
  907.                 *greendst++ |= (*src & 0xe0) << 6;
  908.                 *bluedst++ = (*src++ & 0x1f) << 11;
  909.             }
  910.             src += srcadd;
  911.             reddst += dstadd;
  912.             greendst += dstadd;
  913.             bluedst += dstadd;
  914.         }
  915.         break;
  916.     case 32:
  917.         srcadd = (srcwid / 3) - xsize;
  918.         for (i=0; i < ysize; ++i) {
  919.             for (j=xsize; j--;)
  920.                 *reddst++ = *src++ << 8;
  921.  
  922.             reddst += dstadd;
  923.             src += srcadd;
  924.  
  925.             for (j=xsize; j--;)
  926.                 *greendst++ = *src++ << 8;
  927.  
  928.             greendst += dstadd;
  929.             src += srcadd;
  930.  
  931.             for (j=xsize; j--;)
  932.                 *bluedst++ = *src++ << 8;
  933.  
  934.             bluedst += dstadd;
  935.             src += srcadd;
  936.         }
  937.     }
  938. }
  939.  
  940. static byte*
  941. expand_buf(buf, len, bits_per_pixel)
  942. byte*    buf;
  943. int*    len;
  944. int    bits_per_pixel;
  945. {
  946. static byte pixbuf[256 * 8];
  947. register byte    *src, *dst;
  948. register int    i;
  949.  
  950.     src = buf;
  951.     dst = pixbuf;
  952.  
  953.     switch (bits_per_pixel) {
  954.     case 8:
  955.     case 16:
  956.     case 32:
  957.         return    buf;
  958.     case 4:
  959.         for (i=0; i < *len; i++) {
  960.             *dst++ = (*src >> 4) & 15;
  961.             *dst++ = *src++ & 15;
  962.         }
  963.         *len <<= 1;
  964.         break;
  965.     case 2:
  966.         for (i=0; i < *len; i++) {
  967.             *dst++ = (*src >> 6) & 3;
  968.             *dst++ = (*src >> 4) & 3;
  969.             *dst++ = (*src >> 2) & 3;
  970.             *dst++ = *src++ & 3;
  971.         }
  972.         *len <<= 2;
  973.         break;
  974.     case 1:
  975.         for (i = 0; i < *len; i++) {
  976.             *dst++ = (*src >> 7) & 1;
  977.             *dst++ = (*src >> 6) & 1;
  978.             *dst++ = (*src >> 5) & 1;
  979.             *dst++ = (*src >> 4) & 1;
  980.             *dst++ = (*src >> 3) & 1;
  981.             *dst++ = (*src >> 2) & 1;
  982.             *dst++ = (*src >> 1) & 1;
  983.             *dst++ = *src++ & 1;
  984.         }
  985.         *len <<= 3;
  986.         break;
  987.     default:
  988.         prgmerr(0, "bad bits per pixel in expand_buf");
  989.         return    NULL;
  990.     }
  991. return    pixbuf;
  992. }
  993.  
  994. static void
  995. Clip(version, infp)
  996. FILE*    infp;
  997. {
  998.     skip(read_u_sht(infp) - 2, infp);
  999. }
  1000.  
  1001. static void
  1002. read_pixmap(p, rowBytes, infp)
  1003. pixMap    *p;
  1004. u_sht    *rowBytes;
  1005. FILE*    infp;
  1006. {
  1007.     /*    getting pixMap header    */
  1008.  
  1009.     if (rowBytes != NULL)
  1010.         *rowBytes = read_u_sht(infp);
  1011.  
  1012.     read_rect(&p->Bounds, infp);
  1013.     p->version = read_u_sht(infp);
  1014.     p->packType = read_u_sht(infp);
  1015.     p->packSize = read_long(infp);
  1016.     p->hRes = read_long(infp);
  1017.     p->vRes = read_long(infp);
  1018.     p->pixelType = read_u_sht(infp);
  1019.     p->pixelSize = read_u_sht(infp);
  1020.     p->cmpCount = read_u_sht(infp);
  1021.     p->cmpSize = read_u_sht(infp);
  1022.     p->planeBytes = read_long(infp);
  1023.     p->pmTable = read_long(infp);
  1024.     p->pmReserved = read_long(infp);
  1025.  
  1026.     DEBUGMESSAGE("pixelType:\t%d\npixelSize:\t%d\ncmpCount:\t%d\ncmpSize:\t%d",
  1027.         p->pixelType, p->pixelSize, p->cmpCount, p->cmpSize);
  1028.  
  1029.     if (p->pixelType)
  1030.         prgmerr(0, "sorry, I only do chunky format");
  1031.     if (p->cmpCount != 1)
  1032.         prgmerr(0, "sorry, cmpCount != 1");
  1033.     if (p->pixelSize != p->cmpSize)
  1034.         prgmerr(0, "oops, pixelSize != cmpSize");
  1035. }
  1036.  
  1037. static    ct_entry*
  1038. read_colour_table(infp)
  1039. FILE    *infp;
  1040. {
  1041. longword    ctSeed;
  1042. u_sht    ctFlags, ctSize,
  1043.     val;
  1044. int    i;
  1045. ct_entry    *colour_table;
  1046.  
  1047.     /*    getting color table info    */
  1048.  
  1049.     ctSeed = read_long(infp);
  1050.     ctFlags = read_u_sht(infp);
  1051.     ctSize = read_u_sht(infp);
  1052.  
  1053.     DEBUGMESSAGE("ctSeed:  %d\nctFlags: %d\nctSize:  %d",
  1054.             ctSeed, ctFlags, ctSize);
  1055.  
  1056.     /*    reading colour table    */
  1057.  
  1058.     colour_table = (ct_entry*) nzalloc(sizeof(ct_entry), ctSize + 1,
  1059.             "colour table");
  1060.  
  1061.     for (i=0; i <= ctSize; i++) {
  1062.         if ((val = read_u_sht(infp)) > ctSize)
  1063.             prgmerr(0, "pixel value greater than colour table size");
  1064.         /* seems that if we have a device colour table, the val is
  1065.          * always zero, so I assume we allocate up the list of colours.
  1066.          */
  1067.         if (ctFlags & 0x8000)
  1068.             val = i;
  1069.         colour_table[val].red = read_u_sht(infp);
  1070.         colour_table[val].green = read_u_sht(infp);
  1071.         colour_table[val].blue = read_u_sht(infp);
  1072.  
  1073.         DEBUGMESSAGE("%d: [%d,%d,%d]", val,
  1074.                 colour_table[val].red,
  1075.                 colour_table[val].green,
  1076.                 colour_table[val].blue, 0);
  1077.     }
  1078.  
  1079.     return(colour_table);
  1080. }
  1081.  
  1082. /* these 3 do nothing but skip over their data! */
  1083. static void
  1084. BkPixPat(version, infp)
  1085. FILE*    infp;
  1086. {
  1087.     read_pattern(infp);
  1088. }
  1089.  
  1090. static void
  1091. PnPixPat(version, infp)
  1092. FILE*    infp;
  1093. {
  1094.     read_pattern(infp);
  1095. }
  1096.  
  1097. static void
  1098. FillPixPat(version, infp)
  1099. FILE*    infp;
  1100. {
  1101.     read_pattern(infp);
  1102. }
  1103.  
  1104. /*    this just skips over a version 2 pattern.  Probabaly will return
  1105.     a pattern in the fabled complete version.
  1106. */
  1107. static void
  1108. read_pattern(infp)
  1109. FILE*    infp;
  1110. {
  1111. u_sht    PatType,
  1112.     rowBytes;
  1113. pixMap    p;
  1114. byte    *pm;
  1115. ct_entry    *ct;
  1116.  
  1117.     /*    Reading a pattern    */
  1118.  
  1119.     PatType = read_u_sht(infp);
  1120.  
  1121.     switch (PatType) {
  1122.     case 2:
  1123.         skip(8, infp); /* old pattern data */
  1124.         skip(5, infp); /* RGB for pattern */
  1125.         break;
  1126.     case 1:
  1127.         skip(8, infp); /* old pattern data */
  1128.         read_pixmap(&p, &rowBytes, infp);
  1129.         ct = read_colour_table(infp);
  1130.         pm = unpackbits(&p.Bounds, rowBytes, p.pixelSize, infp);
  1131.         free(pm);
  1132.         free(ct);
  1133.         break;
  1134.     default:
  1135.         prgmerr(0, "unknown pattern type in read_pattern");
  1136.     }
  1137. }
  1138.  
  1139. /* more stubs for text output */
  1140.  
  1141. #define    skip_text(fp)    skip(read_byte(fp), fp);
  1142.  
  1143. static void
  1144. LongText(version, infp)
  1145. FILE*    infp;
  1146. {
  1147.     skip(4, infp);
  1148.     skip_text(infp);
  1149. }
  1150.  
  1151. static void
  1152. DHText(version, infp)
  1153. FILE*    infp;
  1154. {
  1155.     skip(1, infp);
  1156.     skip_text(infp);
  1157. }
  1158.  
  1159. static void
  1160. DVText(version, infp)
  1161. {
  1162.     skip(1, infp);
  1163.     skip_text(infp);
  1164. }
  1165.  
  1166. static void
  1167. DHDVText(version, infp)
  1168. {
  1169.     skip(2, infp);
  1170.     skip_text(infp);
  1171. }
  1172.  
  1173. static void
  1174. skip_poly_or_region(version, infp)
  1175. {
  1176.     /*    skipping polygon or region    */
  1177.     skip(read_u_sht(infp) - 2, infp);
  1178. }
  1179.  
  1180. static void
  1181. LongComment(infp)
  1182. {
  1183.     /*    skipping longword comment    */
  1184.     skip(2, infp);
  1185.     skip(read_u_sht(infp), infp);
  1186. }
  1187.