home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / xloadimg.zip / xloadimage.4.1 / img.c < prev    next >
C/C++ Source or Header  |  1993-10-28  |  19KB  |  784 lines

  1. /* GEM-Images
  2.  *
  3.  * dieter fiebelkorn GEM image type
  4.  *
  5.  * dieter fiebelkorn 19.12.90
  6.  *
  7.  * jimf 10.29.93 - lots of reworking to handle different byte-orders and
  8.  *                 32-bit integers.  no color images to test it with...
  9.  *
  10.  */
  11.  
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <math.h>
  17. #include "image.h"
  18.  
  19. extern int errno;
  20.  
  21. #define TRUE  1
  22. #define FALSE 0
  23.  
  24. #define MAX_PLANES 8
  25. #define ALL_PLANES 8
  26.  
  27.  
  28. #define LEAVE {\
  29.          errorInLoad = errno;\
  30.          printf("  Short read within image data\n");\
  31.              return;\
  32.           }
  33.  
  34. #define LEAVE_ON_ERROR(func) if ((func) <= 0) LEAVE
  35.  
  36.  
  37.  
  38. static int           vdiColorOrder = 0;
  39. static char         *depthError = "Unsupported depth (%d) in IMG-file.\n";
  40. static unsigned int  out_depthError = 0;
  41. int                  errorInLoad;
  42.  
  43.  
  44. typedef struct IMGHEADER
  45. {
  46.   byte im_version[2];
  47.   byte im_headlength[2];
  48.   byte im_nplanes[2];
  49.   byte im_patlen[2];
  50.   byte im_pixwidth[2];
  51.   byte im_pixheight[2];
  52.   byte im_scanwidth[2];
  53.   byte im_nlines[2];
  54. } IMGHEADER;
  55.  
  56.  
  57. typedef struct ximg_header
  58. {
  59.   byte im_version[2];
  60.   byte im_headlength[2];
  61.   byte im_nplanes[2];
  62.   byte im_patlen[2];
  63.   byte im_pixwidth[2];
  64.   byte im_pixheight[2];
  65.   byte im_scanwidth[2];
  66.   byte im_nlines[2];
  67.   char x_id [4];         /* must contain "XIMG" */
  68.   byte color_model[2];   /* 0 = RGB,1 = CYM,2 = HLS, etc. */
  69. } XIMG_HEADER;
  70.  
  71. void (*transf)    ();
  72.  
  73. static int vdi2pli();
  74. static int pli2vdi();
  75.  
  76. static void   transf0    ();
  77. static void   transf1    ();
  78. static void   transf2    ();
  79. static void   transf3    ();
  80. static void   xread_img  ();
  81. static void   xread_line ();
  82. static int    ident_img  ();
  83. static Image *load_img   ();
  84. static int    ident_ximg ();
  85. static Image *load_ximg  ();
  86.  
  87. IMGHEADER               header;
  88. XIMG_HEADER             xheader;
  89. unsigned int            ScanByteBreite, max_planes,
  90.                         pattern_len, plane, x, y, ByteNr, height;
  91. unsigned char           *ptr, Muster[ALL_PLANES][BUFSIZ], tmp[BUFSIZ];
  92. static unsigned char    *bitplane[ALL_PLANES], *lastbitplane;
  93.  
  94.  
  95.  
  96. static void transf0(bitimage, plane, value, planes)
  97.      unsigned char *bitimage;
  98.      unsigned int   plane;
  99.      unsigned char  value;
  100.      unsigned int   planes;
  101. {
  102.   bitimage[x] = value;
  103.   x++;
  104. }
  105.  
  106.  
  107.  
  108. static void transf1(bitimage, plane, value, planes)
  109.      unsigned char *bitimage;
  110.      unsigned int   plane;
  111.      unsigned char  value;
  112.      unsigned int   planes;
  113. {
  114.   unsigned char  bit;
  115.   unsigned long  off;
  116.  
  117.   bit= 0x80;
  118.   off= 0;
  119.   do
  120.   {
  121.     if (bit & value)
  122.       bitimage[off + 8*x] |= (unsigned char)0x01 << plane;
  123.     bit >>= 1;
  124.     off++;
  125.   }
  126.   while (bit > 0);
  127.   x++;
  128. }
  129.  
  130.  
  131.  
  132. static void transf2(bitimage, plane, value, planes)
  133.      unsigned char *bitimage;
  134.      unsigned int   plane;
  135.      unsigned char  value;
  136.      unsigned int   planes;
  137. {
  138.   int    i;
  139.   
  140.   if (bitimage != lastbitplane)
  141.   {
  142.     lastbitplane = bitimage;
  143.     for (i = 0; i < planes; i++)
  144.       bitplane[i] += ScanByteBreite + (ScanByteBreite % 2);
  145.   }
  146.   bitplane[plane][x] = value;
  147.   x++;
  148. }
  149.  
  150. static void transf3(bitimage, plane, value, planes)
  151.      unsigned char *bitimage;
  152.      unsigned int   plane;
  153.      unsigned char  value;
  154.      unsigned int   planes;
  155. {
  156.   unsigned char  bit;
  157.   unsigned long  off;
  158.  
  159.   bit= 0x80;
  160.   off= 0;
  161.   do
  162.   {
  163.     if (bit & value)
  164.     {
  165.       if (plane <  8)
  166.         bitimage[off + 24*x+2] |= (unsigned char)0x01 << plane;
  167.       if (plane >=  8 && plane < 16)
  168.         bitimage[off + 24*x+1] |= (unsigned char)0x01 << (plane-8);
  169.       if (plane >= 16 && plane < 24)
  170.         bitimage[off + 24*x  ] |= (unsigned char)0x01 << (plane-16);
  171.     }
  172.     bit >>= 1;
  173.     off+=3;
  174.   }
  175.   while (bit > 0);
  176.   x++;
  177. }
  178.   
  179. static void xread_line (file, planes)
  180. ZFILE   *file;
  181. int     planes;
  182. {
  183.   ByteNr= 0;
  184.   for (plane= 0; plane < planes; plane++)
  185.   {
  186.     do
  187.       xread_img (file, TRUE, planes);
  188.     while (ByteNr < ScanByteBreite);
  189.     ByteNr= 0;
  190.     x= 0;
  191.   }
  192. }
  193.  
  194.  
  195.  
  196. static void xread_img (file, linie, planes)
  197. ZFILE           *file;
  198. unsigned int    linie;
  199. int             planes;
  200. {
  201.   unsigned int    wert, i, k;
  202.   unsigned char   status;
  203.  
  204.   wert = zgetc(file);
  205.   switch (wert)
  206.   {
  207.     case EOF:
  208.       LEAVE;
  209.     case 0x00:
  210.       wert = zgetc(file);
  211.       switch (wert)
  212.       {
  213.         case EOF:
  214.       LEAVE;
  215.         case 0x00: /* Vertical Run */
  216.           LEAVE_ON_ERROR(zread(file, tmp, 2L));
  217.           if (tmp[0] == 0xFF && !linie)
  218.           {
  219.             wert = tmp[1];
  220.             xread_line (file, planes);
  221.           }
  222.           else
  223.           {
  224.             errorInLoad = 1;
  225.             printf("  Wrong (X)IMG format!");
  226.             return;
  227.           }
  228.           if (y + wert > height)
  229.             wert = height - y;
  230.           if (planes == 1)
  231.           {
  232.             for (k= 0; k < wert; k++)
  233.             {
  234.               for (i= 0; i < ScanByteBreite; i++)
  235.                 *ptr++ = Muster[0][i];
  236.               if (ScanByteBreite % 2 == 1)
  237.                 *ptr++ = 0x00;
  238.             }
  239.             ByteNr = ScanByteBreite;
  240.             if (ByteNr % 2 == 1)
  241.               ByteNr++;
  242.             x = 0;
  243.             y += (wert - 1);
  244.           }
  245.           else
  246.           {
  247.             for (k= 0; k < wert; k++)
  248.             {
  249.               int plane;
  250.               for (plane= 0; plane < planes; plane++)
  251.               {
  252.                 x= 0;
  253.                 for (ByteNr= 0; ByteNr < ScanByteBreite; ByteNr++)
  254.                   (*transf)(ptr, plane, Muster[plane][ByteNr], planes);
  255.               }
  256.               ptr += max_planes * (ScanByteBreite + (ScanByteBreite % 2));
  257.               y++;
  258.             }
  259.             x = 0;
  260.             ptr -= max_planes * (ScanByteBreite + (ScanByteBreite % 2));
  261.             y--;
  262.           }
  263.           break;
  264.         default  : /* Pattern Run */
  265.           if (!linie)
  266.           {
  267.             LEAVE_ON_ERROR(zread(file, tmp, (long)pattern_len));
  268.             if (planes == 1)
  269.             {
  270.               for (k= 0; k < wert && ByteNr < ScanByteBreite; k++)
  271.               {
  272.                 for (i= 0; i < pattern_len; i++)
  273.                   *ptr++ = tmp[i];
  274.                 ByteNr += pattern_len;
  275.               }
  276.             }
  277.             else
  278.             {
  279.               for (k= 0; k < wert && ByteNr < ScanByteBreite; k++)
  280.               {
  281.                 for (i= 0; i < pattern_len; i++)
  282.                   (*transf)(ptr, plane, tmp[i], planes);
  283.                 ByteNr += pattern_len;
  284.               }
  285.             }
  286.           }
  287.           else
  288.           {
  289.         LEAVE_ON_ERROR(zread(file, tmp, (long)pattern_len));
  290.  
  291.             for (k= 0; k < wert && ByteNr < ScanByteBreite; k++)
  292.               for (i= 0; i < pattern_len; i++)
  293.                 Muster[plane][ByteNr++] = tmp[i];
  294.           }
  295.       }
  296.       break;
  297.     case 0x80:
  298.       wert = zgetc(file);
  299.       if (wert == EOF)
  300.     LEAVE;
  301.  
  302.       i = wert;
  303.       if (ByteNr + i > ScanByteBreite)
  304.         i = ScanByteBreite - ByteNr;
  305.       wert -= i;
  306.       if (!linie)
  307.       {
  308.         if (planes == 1)
  309.         {
  310.           zread(file, ptr, (long)i);
  311.           ptr += i;
  312.           ByteNr += i;
  313.           if (wert)
  314.         LEAVE_ON_ERROR(zread(file, tmp, (long)wert));
  315.  
  316.         }
  317.         else
  318.         {
  319.           zread(file, tmp, (long)i);
  320.           for (k = 0; k < i; k++)
  321.           {
  322.             (*transf)(ptr, plane, tmp[k], planes);
  323.             ByteNr++;
  324.           }
  325.           if (wert)
  326.             LEAVE_ON_ERROR(zread(file, tmp, (long)wert));
  327.         }
  328.       }
  329.       else
  330.       {
  331.         zread(file, &Muster[plane][ByteNr], (long)i);
  332.         ByteNr += i;
  333.         if (wert)
  334.           LEAVE_ON_ERROR(zread(file, tmp, (long)wert));
  335.       }
  336.       break;
  337.     default  :
  338.       if (wert & 0x80)
  339.         status = 0xff;
  340.       else
  341.         status = 0x00;
  342.       wert &= 0x7f;
  343.       if (!linie)
  344.       {
  345.         if (planes == 1)
  346.           for (i= 0; i < wert && ByteNr < ScanByteBreite; i++)
  347.           {
  348.             *ptr++ = status;
  349.             ByteNr++;
  350.           }
  351.         else
  352.           for (i= 0; i < wert && ByteNr < ScanByteBreite; i++)
  353.           {
  354.             (*transf)(ptr, plane, status, planes);
  355.             ByteNr++;
  356.           }
  357.       }
  358.       else
  359.         for (i= 0; i < wert && ByteNr < ScanByteBreite; i++)
  360.           Muster[plane][ByteNr++] = status;
  361.   }
  362. }
  363.  
  364. static int ident_img(name)
  365.      char *name;
  366. {
  367.   ZFILE   *file;
  368.   long    size = 0;
  369.   int     w, h, nplanes;
  370.   char    extention[5];
  371.  
  372. #if 0
  373.   strncpy (extention, name+strlen(name)-4, 4);
  374.   extention[4] = '\0';
  375.   if (strcmp(extention, ".IMG") != 0 && strcmp(extention, ".img") != 0)
  376.     return (0);
  377. #endif
  378.  
  379.   if ((file= zopen(name)) == NULL)
  380.   {
  381.     printf("  Error reading IMG!");
  382.     return(0);
  383.   }
  384.   size = zread(file, (byte *)&header, sizeof(header));
  385.   zclose(file);
  386.  
  387.   if (size < sizeof(header) || memToVal(header.im_version, 2) > 2)
  388.     return (0);
  389.  
  390.   w = memToVal(header.im_scanwidth, 2);
  391.   h = memToVal(header.im_nlines, 2);
  392.   nplanes = memToVal(header.im_nplanes, 2);
  393.  
  394.   if ((nplanes > 4 && nplanes != 24) || nplanes == 0)
  395.   {
  396.     if (out_depthError == 0)
  397.       printf(depthError, header.im_nplanes);
  398.     return(0);
  399.   }
  400.  
  401.   if (nplanes == 1)
  402.     printf("%s is a %dx%d monochrome IMG-file\n",name , w, h);
  403.   else
  404.     if (nplanes != 24)
  405.       printf("%s is a %dx%d IMG-file with %ld colors\n",name , w, h,
  406.          (1 << nplanes));
  407.     else
  408.       printf("%s is a %dx%d %d-bit IMG-file\n",name , w, h, nplanes);
  409.   return (1);
  410. }
  411.  
  412. static Image *load_img(name)
  413.      char *name;
  414. {
  415.   ZFILE           *file;
  416.   Image           *image;
  417.   unsigned long    w, h, nplanes, headlength, scanwidth;
  418.   int              colors;
  419.   long             i, dummy;
  420.  
  421.   if ((file = zopen(name)) == NULL)
  422.   {
  423.     printf("  Error reading IMG!");
  424.     return(NULL);
  425.   }
  426.   zread(file, (byte *)&header, sizeof(header));
  427.  
  428.   headlength = memToVal(header.im_headlength, 2);
  429.   for (i=0; i<(headlength-(int)(sizeof(header)/2)); i++)
  430.     zread(file, (byte *)&dummy, 2L);
  431.  
  432.   w = memToVal(header.im_scanwidth, 2);
  433.   w = 16L * (w / 16L + (w % 16L ? 1 : 0));
  434.   h = memToVal(header.im_nlines, 2);
  435.   pattern_len = memToVal(header.im_patlen, 2);
  436.   max_planes = 8;
  437.   nplanes = memToVal(header.im_nplanes, 2);
  438.   scanwidth = memToVal(header.im_scanwidth, 2);
  439.  
  440.   if (nplanes == 1)
  441.   {
  442.     transf = transf0;
  443.     image= newBitImage(w, h);
  444.     if (!image)
  445.     {
  446.       zclose(file);
  447.       return(image);
  448.     }
  449.     plane = 0;
  450.  
  451.     ptr= image->data;
  452.     x = y = ByteNr = 0;
  453.     height = (int) h;
  454.     ScanByteBreite = (scanwidth + 7) / 8;
  455.     do
  456.     {
  457.       xread_img (file, FALSE, 1);
  458.       if (ByteNr >= ScanByteBreite)
  459.       {
  460.         if (ByteNr % 2 == 1)
  461.           *ptr++ = 0x00;
  462.         ByteNr = 0;
  463.         y++;
  464.         x = 0;
  465.       }
  466.     }
  467.     while (y < height && !errorInLoad);
  468.   }
  469.   if ((nplanes > 1 && nplanes <= 8) || nplanes == 24)
  470.   {
  471.     if (nplanes <= 8)
  472.     {
  473.       image= newRGBImage(w, h, nplanes);
  474.       if (!image)
  475.       {
  476.         zclose(file);
  477.         return(image);
  478.       }
  479.       transf = transf1;
  480.       colors = 1 << nplanes;
  481.     }
  482.     else
  483.     {
  484.       image= newTrueImage(w, h);
  485.       if (!image)
  486.       {
  487.         zclose(file);
  488.         return(image);
  489.       }
  490.       transf = transf3;
  491.       colors = 0;
  492.       max_planes = 24;
  493.     }
  494.     if (nplanes >= 2 && nplanes <= 8)
  495.     {
  496.       image->rgb.red[ 0]= 0xFF00; image->rgb.green[ 0]= 0xFF00; image->rgb.blue[ 0]= 0xFF00;
  497.       image->rgb.red[ 1]= 0xFF00; image->rgb.green[ 1]= 0x0000; image->rgb.blue[ 1]= 0x0000;
  498.       image->rgb.red[ 2]= 0x0000; image->rgb.green[ 2]= 0xFF00; image->rgb.blue[ 2]= 0x0000;
  499.       image->rgb.red[ 3]= 0x0000; image->rgb.green[ 3]= 0x0000; image->rgb.blue[ 3]= 0x0000;
  500.     }
  501.     if (nplanes >= 3 && nplanes <= 8)
  502.     {
  503.       image->rgb.red[ 3]= 0xFF00; image->rgb.green[ 3]= 0xFF00; image->rgb.blue[ 3]= 0x0000;
  504.       image->rgb.red[ 4]= 0x0000; image->rgb.green[ 4]= 0x0000; image->rgb.blue[ 4]= 0xFF00;
  505.       image->rgb.red[ 5]= 0xFF00; image->rgb.green[ 5]= 0x0000; image->rgb.blue[ 5]= 0xFF00;
  506.       image->rgb.red[ 6]= 0x0000; image->rgb.green[ 6]= 0xFF00; image->rgb.blue[ 6]= 0xFF00;
  507.       image->rgb.red[ 7]= 0x0000; image->rgb.green[ 7]= 0x0000; image->rgb.blue[ 7]= 0x0000;
  508.     }
  509.     if (nplanes >= 4 && nplanes <= 8)
  510.     {
  511.       image->rgb.red[ 7]= 0xDA00; image->rgb.green[ 7]= 0xDA00; image->rgb.blue[ 7]= 0xDA00;
  512.       image->rgb.red[ 8]= 0x6D00; image->rgb.green[ 8]= 0x6D00; image->rgb.blue[ 8]= 0x6D00;
  513.       image->rgb.red[ 9]= 0xB600; image->rgb.green[ 9]= 0x0000; image->rgb.blue[ 9]= 0x0000;
  514.       image->rgb.red[10]= 0x0000; image->rgb.green[10]= 0xB600; image->rgb.blue[10]= 0x0000;
  515.       image->rgb.red[11]= 0xB600; image->rgb.green[11]= 0xB600; image->rgb.blue[11]= 0x0000;
  516.       image->rgb.red[12]= 0x0000; image->rgb.green[12]= 0x0000; image->rgb.blue[12]= 0xB600;
  517.       image->rgb.red[13]= 0xB600; image->rgb.green[13]= 0x0000; image->rgb.blue[13]= 0xB600;
  518.       image->rgb.red[14]= 0x0000; image->rgb.green[14]= 0xB600; image->rgb.blue[14]= 0xB600;
  519.       image->rgb.red[15]= 0x0000; image->rgb.green[15]= 0x0000; image->rgb.blue[15]= 0x0000;
  520.     }
  521.     /* colors 17 to 255 undefined in this kind of IMG-File */
  522.     
  523.     image->rgb.used= colors;
  524.  
  525.     ptr= image->data;
  526.     x = y = ByteNr = 0;
  527.     height = (int) h;
  528.     ScanByteBreite = (scanwidth + 7) / 8;
  529.     do
  530.     {
  531.       for (plane= 0; plane < nplanes && !errorInLoad; plane++)
  532.       {
  533.         do
  534.           xread_img (file, FALSE, nplanes);
  535.         while (ByteNr < ScanByteBreite && !errorInLoad);
  536.         ByteNr = 0;
  537.         x = 0;
  538.       }
  539.       if (nplanes != 1)
  540.         ptr += max_planes * (ScanByteBreite + (ScanByteBreite % 2));
  541.       y++;
  542.     }
  543.     while (y < height && !errorInLoad);
  544.   }
  545.  
  546.   if (errorInLoad > 0)
  547.   {
  548.     freeImage(image);
  549.     image = NULL;
  550.     zclose(file);
  551.     return(image);
  552.   }
  553.  
  554.   image->title= dupString(name);
  555.   zclose(file);
  556.   return(image);
  557. }
  558.  
  559.  
  560.  
  561. static int ident_ximg(name)
  562.      char *name;
  563. {
  564.   ZFILE  *file;
  565.   long    size = 0;
  566.   int     w, h, nplanes;
  567.   char    extention[5];
  568.  
  569.   if ((file = zopen(name)) == NULL)
  570.   {
  571.     printf("  Error reading XIMG!");
  572.     return(0);
  573.   }
  574.   size = zread(file, (byte *)&xheader, sizeof(xheader));
  575.   zclose(file);
  576.  
  577.   if (size < sizeof(xheader))
  578.     return (0);
  579.  
  580.   if (strncmp(xheader.x_id, "XIMG", 4)) /* || (xheader.color_model != 0 &&
  581.                                            xheader.color_model != 'TC')) */
  582.     return (0);
  583.  
  584.   w = memToVal(xheader.im_scanwidth, 2);
  585.   h = memToVal(xheader.im_nlines, 2);
  586.   nplanes = memToVal(xheader.im_nplanes, 2);
  587.   if ((nplanes > MAX_PLANES && nplanes != 24) || nplanes == 0)
  588.   {
  589.     printf(depthError, xheader.im_nplanes);
  590.     out_depthError = 1;
  591.     return(0);
  592.   }
  593.  
  594.   printf("%s\n  is a %dx%d ",name, w, h);
  595.   if (nplanes != 24)
  596.     printf("RGB XIMG-file with %ld colors\n", 1<<nplanes);
  597.   else
  598.     printf("24-bit XIMG-file\n");
  599.   return (1);
  600. }
  601.  
  602. static int vdi2pli(vdi, plimax)
  603.      int vdi, plimax;
  604. {
  605.   extern unsigned char indexToCode[];
  606.   extern int           work_ext[];
  607.   static char          vdi2pli[] = {0, 15, 1, 2, 4, 6, 3, 5, 7, 8, 9, 10, 12, 14, 11, 13 };
  608.   
  609.   if (vdi == 1)
  610.     return(plimax-1);
  611.   if (vdi >= 16)
  612.     return(vdi);
  613.   return(vdi2pli[vdi]);
  614. }
  615.  
  616.  
  617.  
  618. static int pli2vdi(pli, plimax)
  619.      int pli, plimax;
  620. {
  621.   static char pli2vdi[] = {0, 2, 3, 6, 4, 7, 5, 8, 9, 10, 11, 14, 12, 15, 13, 1 };
  622.   
  623.   if (pli == plimax-1)
  624.     return(1);
  625.   if (pli >= 16)
  626.     return(pli);
  627.   return(pli2vdi[pli]);
  628. }
  629.  
  630. static Image *load_ximg(name)
  631.      char *name;
  632. {
  633.   void            transferRGBMap();
  634.   ZFILE          *file;
  635.   Image          *image;
  636.   unsigned long   w, h, nplanes, scanwidth;
  637.   int             i, color, colors;
  638.   struct RGB_LIST
  639.   {
  640.     unsigned int red;
  641.     unsigned int green;
  642.     unsigned int blue;
  643.   } rgb_list;
  644.  
  645.   if ((file = zopen(name)) == NULL)
  646.   {
  647.     printf("  Error reading XIMG!");
  648.     return(NULL);
  649.   }
  650.   zread(file, (byte *)&xheader, sizeof(xheader));
  651.   
  652.   w = scanwidth = memToVal(xheader.im_scanwidth, 2);
  653.   w = 16L * (w / 16L + (w % 16L ? 1 : 0));
  654.   h = memToVal(xheader.im_nlines, 2);
  655.   nplanes = memToVal(xheader.im_nplanes, 2);
  656.   pattern_len = memToVal(xheader.im_patlen, 2);
  657.   max_planes = 8;
  658.  
  659.   if (nplanes == 1)
  660.   {
  661.     image= newBitImage(w, h);
  662.     if (!image)
  663.     {
  664.       zclose(file);
  665.       return(image);
  666.     }
  667.     transf = transf0;
  668.   }
  669.   if (nplanes > 1 && nplanes <= 8)
  670.   {
  671.     image= newRGBImage(w, h, nplanes);
  672.     if (!image)
  673.     {
  674.       zclose(file);
  675.       return(image);
  676.     }
  677.     transf = transf1;
  678.   }
  679.  
  680.   colors = 1 << nplanes;
  681.  
  682.   if (nplanes == 24)
  683.   {
  684.     image= newTrueImage(w, h);
  685.     if (!image)
  686.     {
  687.       zclose(file);
  688.       return(image);
  689.     }
  690.     transf = transf0;
  691.     nplanes = 1;
  692.     colors = 0;
  693.     max_planes =24;
  694.   }
  695.  
  696.   for (color = 0; color < colors; color++)
  697.   {
  698.     zread (file, (byte *)&rgb_list, sizeof(rgb_list));
  699.     if (vdiColorOrder)
  700.     {
  701.       image->rgb.red[vdi2pli(color, colors)]   = ((unsigned int) (255 * rgb_list.red   / 1000)) << 8;
  702.       image->rgb.green[vdi2pli(color, colors)] = ((unsigned int) (255 * rgb_list.green / 1000)) << 8;
  703.       image->rgb.blue[vdi2pli(color, colors)]  = ((unsigned int) (255 * rgb_list.blue  / 1000)) << 8;
  704.     }
  705.     else
  706.     {
  707.       image->rgb.red[color]   = ((unsigned int) (255 * rgb_list.red   / 1000)) << 8;
  708.       image->rgb.green[color] = ((unsigned int) (255 * rgb_list.green / 1000)) << 8;
  709.       image->rgb.blue[color]  = ((unsigned int) (255 * rgb_list.blue  / 1000)) << 8;
  710.     }
  711.   }
  712.   if (colors != 0)
  713.     image->rgb.used= (unsigned int) 1<<nplanes;
  714.   else
  715.     image->rgb.used= 0;
  716.   
  717.   ptr= image->data;
  718.   x = y = ByteNr = 0;
  719.   height = (int) h;
  720.   
  721.   if (colors != 0)
  722.     ScanByteBreite = (scanwidth + 7) / 8;
  723.   else
  724.     ScanByteBreite = 24 * ((scanwidth + 7) / 8);
  725.   do
  726.   {
  727.     for (plane= 0; plane < nplanes && !errorInLoad; plane++)
  728.     {
  729.       do
  730.         xread_img (file, FALSE, nplanes);
  731.       while (ByteNr < ScanByteBreite && !errorInLoad);
  732.       if (nplanes == 1 && ByteNr % 2 == 1)
  733.         *ptr++ = 0x00;
  734.       ByteNr = 0;
  735.       x = 0;
  736.     }
  737.     if (nplanes != 1)
  738.       ptr += max_planes * (ScanByteBreite + (ScanByteBreite % 2));
  739.     y++;
  740.   }
  741.   while (y < height && !errorInLoad);
  742.  
  743.   if (errorInLoad > 0)
  744.   {
  745.     freeImage(image);
  746.     image = NULL;
  747.     zclose(file);
  748.     return(image);
  749.   }
  750.   image->title= dupString(name);
  751.  
  752.   zclose(file);
  753.   return(image);
  754. }
  755.  
  756. int imgIdent(name, name2, verbose)
  757.      char *name;
  758.      char *name2;
  759.      int   verbose;
  760. {
  761.   int  identified;
  762.  
  763.   if ((identified = ident_ximg(name)) != 0)
  764.     return(identified);
  765.   identified = ident_img(name);
  766.  
  767.   return(identified);
  768. }
  769.  
  770. Image *imgLoad(name, name2, verbose)
  771.      char *name;
  772.      char *name2;
  773.      int   verbose;
  774. {
  775.   errorInLoad = 0;
  776.   out_depthError = 0;
  777.   if (ident_ximg(name) != 0)
  778.     return(load_ximg(name));
  779.   if (ident_img(name) != 0)
  780.     return(load_img(name));
  781.  
  782.   return(NULL);
  783. }
  784.