home *** CD-ROM | disk | FTP | other *** search
/ CD Direkt 1995 #1 / Image.iso / cdd / winanw / pman / readpcx.c < prev    next >
C/C++ Source or Header  |  1993-03-21  |  16KB  |  345 lines

  1. /************************************************************************\
  2.  *                                                                      *
  3.  *  readpcx.c                                                           *
  4.  *                                                                      *
  5.  *  This file is part of PICTURE MAN image file converter/processor     *
  6.  *                                                                      *
  7.  *  1992 Potapov WORKS, STOIK Ltd.                                      *
  8.  *                                                                      *
  9.  *  This file contains source code for PCX file reader                  *
  10.  *                                                                      *
  11.  *  Compiler: MS C v.6.00A                                              *
  12.  *                                                                      *
  13.  *  You may use, modify and distribute this code freely                 *
  14.  *                                                                      *
  15. \************************************************************************/
  16. #include <windows.h>
  17. #include "custconv.h"
  18.   
  19. #define BUFSIZE 4096
  20.   
  21. #define SEEK_SET 0
  22. #define SEEK_END 2
  23.  
  24. typedef struct {
  25.                 int file, bplin, pos, buflen, count;
  26.                 BYTE byte, buffer[BUFSIZE];
  27.                 int iCur;
  28.                 }PCXStruct;
  29.   
  30. /************************************************************************\
  31.  *                                                                      *
  32.  * ROUTINE: int FAR PASCAL LibMain(HANDLE hModule, WORD wDataSeg,       *
  33.  *                                 WORD cbHeapSize, LPSTR lpszCmdLine)  *
  34.  * PURPOSE: DLL entry point.                                            *
  35.  *                                                                      *
  36. \************************************************************************/
  37. int FAR PASCAL LibMain(HANDLE hModule, WORD wDataSeg,
  38. WORD cbHeapSize, LPSTR lpszCmdLine)
  39. {
  40.     return 1;
  41. }
  42.   
  43. /************************************************************************\
  44.  *                                                                      *
  45.  * ROUTINE: int FAR PASCAL WEP(int bSystemExit)                         *
  46.  *                                                                      *
  47.  * PURPOSE: DLL exit procedure                                          *
  48.  *                                                                      *
  49. \************************************************************************/
  50. int FAR PASCAL WEP(int bSystemExit)
  51. {
  52.     return 1;
  53. }
  54.   
  55. /************************************************************************\
  56.  *                                                                      *
  57.  * ROUTINE: WORD FAR PASCAL Magic(void)                                 *
  58.  *                                                                      *
  59.  * PURPOSE: Identification routine                                      *
  60.  * RETURNS: 'Magic number' SRC_MAGIC                                    *
  61.  *                                                                      *
  62. \************************************************************************/
  63. WORD FAR PASCAL Magic(void)
  64. {
  65.     return SRC_MAGIC;
  66. }
  67.   
  68. /************************************************************************\
  69.  *                                                                      *
  70.  * ROUTINE: DWORD FAR PASCAL GetFlags(void)                             *
  71.  *                                                                      *
  72.  * PURPOSE: Sets flag for SetOptions Dialog box                         *
  73.  *                                                                      *
  74.  * PARAMETERS: None                                                     *
  75.  *                                                                      *
  76.  * RETURNS:                                                             *
  77.  *          INFO_HASOPTIONS if converter supports SetOptions dialog box *
  78.  *          0ul  otherwise                                              *
  79.  *                                                                      *
  80. \************************************************************************/
  81. DWORD FAR PASCAL GetFlags(void)
  82. {
  83.     return 0ul;
  84. }
  85.   
  86. /************************************************************************\
  87.  *                                                                      *
  88.  * ROUTINE: void FAR PASCAL GetDescription(LPSTR str)                   *
  89.  *                                                                      *
  90.  * PURPOSE: Sets format name                                            *
  91.  *                                                                      *
  92.  * PARAMETERS: LPSTR str - pointer for format name storage. The length  *
  93.  *             name must be less than 40!                               *
  94.  *                                                                      *
  95. \************************************************************************/
  96. void FAR PASCAL GetDescription(LPSTR str)
  97. {
  98.     lstrcpy(str,"ZSoft PaintBrush PCX");
  99. }
  100.   
  101. /************************************************************************\
  102.  *                                                                      *
  103.  * ROUTINE: void FAR PASCAL GetExtension(LPSTR str)                     *
  104.  *                                                                      *
  105.  * PURPOSE: Sets format file extension                                  *
  106.  *                                                                      *
  107.  * PARAMETERS: LPSTR str - pointer for format file extension.           *
  108.  *                                                                      *
  109. \************************************************************************/
  110. void FAR PASCAL GetExtension(LPSTR str)
  111. {
  112.     lstrcpy(str,"PCX");
  113. }
  114.  
  115. /************************************************************************\
  116.  *                                                                      *
  117.  * ROUTINE: int FAR PASCAL GetPrivateSize()                             *
  118.  *                                                                      *
  119.  * PURPOSE: Returns size of private memory block                        *
  120.  *                                                                      *
  121.  *                                                                      *
  122. \************************************************************************/
  123. int FAR PASCAL GetPrivateSize()
  124. {
  125.    return sizeof(PCXStruct);
  126. }
  127.   
  128. /************************************************************************/
  129. /************************************************************************/
  130. /************************************************************************/
  131. /* PCX File Header */
  132. typedef struct {
  133.     char         manuf;          /* Always =10 for Paintbrush   */
  134.     char         hard;           /* Version information         */
  135.     char         encod;          /* Run-length encoding (=1)    */
  136.     char         bitpx;          /* Bits per pixel              */
  137.     unsigned     x1;             /* Picture dimensions (incl)   */
  138.     unsigned     y1;
  139.     unsigned     x2;
  140.     unsigned     y2;
  141.     unsigned     hres;           /* Display horiz resolution    */
  142.     unsigned     vres;           /* Display vert  resolution    */
  143.     char         clrma[48];      /* Pallete                     */
  144.     char         vmode;          /* (ignored)                   */
  145.     char         nplanes;        /* Number of planes (ver 2.5=0)*/
  146.     unsigned     bplin;          /* Bytes per line              */
  147.     unsigned     palinfo;        /* Palette Info (1=col, 2=gray)*/
  148.     unsigned     shres;          /* Scanner resolution          */
  149.     unsigned     svres;          /*                             */
  150.     char         xtra[54];       /* Extra space (filler)        */
  151. } pcxheader;
  152.   
  153. /************************************************************************\
  154.  *                                                                      *
  155.  * ROUTINE: int FAR PASCAL ReadHeader(LPINF