home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / pascal / rehack / graphics / pcx.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-26  |  2.9 KB  |  99 lines

  1. //---------------------------------------------------------------------------
  2. //
  3. //      File:           PCX.HPP
  4. //      Path:           ...\REHACK\graphics
  5. //      Version:                2.0
  6. //      Author:            Dave Boynton
  7. //      CIS Id:            71043,317
  8. //      Created On:     January 1992
  9. //      Modified On:    7/25/93
  10. //      Description:    header file for PcxFile & PcxFile256 classes
  11. //      Tabs:           4
  12. //
  13. //---------------------------------------------------------------------------
  14. // extracted/modified from pcxlib 2.0 (c) 1992,1993 David Boynton
  15. // All rights reserved.
  16. //-----------------------------------------------------------------------//
  17. #ifndef _PCX_HPP
  18. #define _PCX_HPP
  19.  
  20. #include <stdio.h>
  21. #include "..\general\types.hpp"
  22.  
  23. #define ALIGN_DWORD(x) (((x)+3)/4 * 4)
  24.  
  25. struct PCXRGB {
  26.        unsigned char r, g, b;
  27. };
  28.  
  29. const word PCXMAGICID=0x0a;
  30.  
  31. typedef struct { // begining of all .pcx files
  32.     char               magicId;
  33.     char               version; // 5 means 256 color w/palette at end
  34.     char               encoding; // 1 means RLE, readLine's description
  35.     char               bitsPixel; // must be 8 for Version 5
  36.     word               xMin, yMin;
  37.     word               xMax, yMax;
  38.     word               hRes, vRes;
  39.     struct PCXRGB      palette[16];   /* used only on 16 color pcx's */
  40.     char               reserved;
  41.     char               planes; // must be 1 for Version 5
  42.     word               bytesLine; // double-word aligned
  43.     word               paletteInfo;
  44.     char               filler[58]; // there's other stuff in here, but it's
  45.                                     // used for anything useful.
  46. } PCXH;
  47.  
  48. typedef    struct PCXRGB Palette[256];
  49.  
  50. class PcxFile {
  51.     public:
  52.         PCXH    *header;
  53.         FILE    *fp;
  54.         long    filestart; // for use with resource files
  55.         byte    *lineBuffer;
  56.         bool    validFlag;
  57.         word    hPixels, vPixels;
  58.         word    bytesPerLine;
  59.  
  60.         ~PcxFile(); // closes file, deletes lineBuffer;
  61.         bool    isValid(void) { return validFlag; }
  62.  
  63.         PcxFile(char *filename); // input file
  64.         PcxFile(FILE *fp);         // for resource files, sets filestart
  65.         PcxFile(char *filename, word xSize, word ySize); //output file
  66.  
  67.         bool readHeader(void);
  68.         bool writeHeader(void);
  69. };
  70.  
  71. class PcxFile256 : public PcxFile {
  72.     public:
  73.         struct PCXRGB * palette;
  74.  
  75.         PcxFile256(char *filename); // input file
  76.         PcxFile256(FILE *fp);         // for resource files, sets filestart
  77.         PcxFile256(char *filename, word xSize, word ySize); //output file
  78.         ~PcxFile256();
  79.  
  80.         bool    readPalette(void);
  81.         bool    writePalette(void);
  82.  
  83.         void    shiftPaletteDown(void);
  84.         void    shiftPaletteUp(void);
  85.  
  86.         bool skipLine(void);
  87.         bool seekLine(word line);
  88.         bool readLine(byte * destBuffer, word x0, word x1);
  89.         bool writeLine(byte * srcBuffer, word x0, word x1, byte fill=0);
  90.         bool readLine(void) { return readLine(lineBuffer, 0, hPixels-1); }
  91.         bool writeLine(void) { return writeLine(lineBuffer, 0, hPixels-1); }
  92.  
  93. };
  94.  
  95. #endif   // _PCX_HPP
  96.  
  97.  
  98.  
  99.