Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define MAXCOLORTC
- #include "wingraph.h"
- #include <iostream>
- using namespace std;
- typedef struct TPCXHeaderStruct {
- unsigned char ID;
- unsigned char Version;
- unsigned char Coding;
- unsigned char BitPerPixel;
- unsigned short XMin;
- unsigned short YMin;
- unsigned short XMax;
- unsigned short YMax;
- unsigned short HRes;
- unsigned short VRes;
- unsigned char Palette[16][3];
- unsigned char Reserved;
- unsigned char Planes;
- unsigned short BytePerLine;
- unsigned short PaletteInfo;
- unsigned short HScreenSize;
- unsigned short VScreenSize;
- unsigned char Filler[54];
- } TPCXHeader;
- typedef struct TPaletteStruct {
- unsigned char Red;
- unsigned char Green;
- unsigned char Blue;
- } TPalette;
- int main() {
- FILE *f = fopen("image_256.pcx", "rb");
- if(f != NULL) {
- TPCXHeader PCXHeader;
- fread(&PCXHeader, sizeof(TPCXHeader), 1, f);
- cout << "-----TPCX Header" << endl;
- cout << "ID - " << (int)PCXHeader.ID << endl;
- cout << "Version - " << (int)PCXHeader.Version << endl;
- cout << "Coding - " << (int)PCXHeader.Coding << endl;
- cout << "BitPerPixel - " << (int)PCXHeader.BitPerPixel << endl;
- cout << "XMin - " << PCXHeader.XMin << endl;
- cout << "YMin - " << PCXHeader.YMin << endl;
- cout << "XMax - " << PCXHeader.XMax << endl;
- cout << "YMax - " << PCXHeader.YMax << endl;
- cout << "HRes - " << PCXHeader.HRes << endl;
- cout << "VRes - " << PCXHeader.VRes << endl;
- cout << "Palette - " << sizeof(PCXHeader.Palette) << endl;
- cout << "Reserved - " << (int)PCXHeader.Reserved << endl;
- cout << "Planes - " << (int)PCXHeader.Planes << endl;
- cout << "BytePerLine - " << PCXHeader.BytePerLine << endl;
- cout << "PaletteInfo - " << PCXHeader.PaletteInfo << endl;
- cout << "HScreenSize - " << PCXHeader.HScreenSize << endl;
- cout << "VScreenSize - " << PCXHeader.VScreenSize << endl;
- cout << "Filler - " << sizeof(PCXHeader.Filler) << endl;
- int XSize = PCXHeader.XMax - PCXHeader.XMin + 1;
- int YSize = PCXHeader.YMax - PCXHeader.YMin + 1;
- int TotalBytes = PCXHeader.Planes * PCXHeader.BytePerLine;
- resize(XSize, YSize);
- cout << "TotalBytes - " << TotalBytes << endl;
- cout << "XSize - " << XSize << endl;
- cout << "YSize - " << YSize << endl;
- byte buffer;
- if(PCXHeader.Version == 5 || PCXHeader.BitPerPixel == 8) {
- fseek(f, -769, SEEK_END);
- fread(&buffer, 1, 1, f);
- if(buffer == 12) {
- TPalette PCXPalette[256];
- fread(PCXPalette, sizeof(PCXPalette), 1, f);
- fseek(f, sizeof(TPCXHeader), SEEK_SET);
- int count, x = 0, y = 0;
- //int planes = 0;
- while(fread(&buffer, 1, 1, f)) {
- if((buffer & 0xC0) == 0xC0) {
- count = (buffer & 0x3F);
- fread(&buffer, 1, 1, f);
- }else
- count = 1;
- do {
- putpixel(x, y, RGB(PCXPalette[buffer].Red, PCXPalette[buffer].Green, PCXPalette[buffer].Blue));
- if(x >= TotalBytes)
- x = 0, y++;
- if(y >= YSize) {
- // planes++;
- // if(planes != PCXHeader.Planes)
- // x = 0, y = 0;
- // else
- break;
- // cout << "planes - " << planes << endl;
- }
- x++;
- }while(--count);
- }
- }
- }else
- cout << "File does not contain palette" << endl;
- }else
- cout << "Could not open pcx file" << endl;
- fclose(f);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement