Professional Documents
Culture Documents
#Include #Include Typedef Unsigned Char Typedef Unsigned Short Using Namespace Struct
#Include #Include Typedef Unsigned Char Typedef Unsigned Short Using Namespace Struct
cpp
//
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
// MA 02110-1301, USA.
//
//
#include <iostream>
#include <fstream>
struct PCXHeader {
BYTE Identifier; /* PCX Id Number (Always 0x0A) */
BYTE Version; /* Version Number */
BYTE Encoding; /* Encoding Format */
BYTE BitsPerPixel; /* Bits per Pixel */
WORD XStart; /* Left of image */
WORD YStart; /* Top of Image */
WORD XEnd; /* Right of Image*/
WORD YEnd; /* Bottom of image */
WORD HorzRes; /* Horizontal Resolution */
WORD VertRes; /* Vertical Resolution */
BYTE Palette[48]; /* 16-Color EGA Palette */
BYTE Reserved1; /* Reserved (Always 0) */
BYTE NumBitPlanes; /* Number of Bit Planes */
WORD BytesPerLine; /* Bytes per Scan-line */
WORD PaletteType; /* Palette Type */
WORD HorzScreenSize; /* Horizontal Screen Size */
WORD VertScreenSize; /* Vertical Screen Size */
BYTE Reserved2[54]; /* Reserved (Always 0) */
};
struct CCYHeader {
BYTE id[3];
WORD frames;
WORD width;
WORD height;
BYTE pixelSize;
BYTE orientation;
BYTE method;
WORD paleteSize;
};
ifstream sStream;
PCXHeader pcxHeader;
// Parametros de entrada
//cout << "Caminho do Arquivo: ";
//cin >> caminho;
cout << "Numero Frames: ";
cin >> qtd;
int frame[qtd];
// Ler frames
for (int i = 0; i < qtd; i++) {
sprintf(nome_arq, "jungle%d.pcx",i);
sStream.open(nome_arq, ios::binary);
if (!sStream) {
cout << "Falha ao Carregar o Arquivo " << endl;
return 1;
}
if (i ==0){
FileBegin = sStream.tellg();
sStream.seekg(0, ios::end);
FileEnd = sStream.tellg();
FileBytes = FileEnd - FileBegin;
sStream.seekg(0, ios::beg);
sStream.read(reinterpret_cast<char*>(&pcxHeader), sizeof(pcxHeader));
sStream.seekg(128);
}
}
int cont=0;
sStream.seekg(FileBytes - 768);
iPalette = new unsigned int[768];
for (int i = 0; i < 768; i++) {
cBuffer = sStream.get();
iPalette[i] = cBuffer;
// if ((i+1)%3==0)
// printf("%3d - %3d %3d %3d\n", (i+1)/3, iPalette[i-2], iPalette[i-
1], iPalette[i]);
// if (cBuffer == 0)
// cont++;
}
// printf("%d", cont);
sStream.close();
bool cyclingColor[256];
for (int x = 0; x < qtd; x++) {
/*
ssStream.put(iPixels[i*ImageHeight+j]);
}
}
};
*/
/* Monta CCY */
ofstream ssStream;
CCYHeader ccyHeader;
ccyHeader.id[0] = 67; /* C */
ccyHeader.id[1] = 67; /* C */
ccyHeader.id[2] = 89; /* Y */
ccyHeader.frames = 1;
ccyHeader.width = ImageWidth;
ccyHeader.height = ImageHeight;
ccyHeader.pixelSize = pcxHeader.BitsPerPixel;
ccyHeader.orientation = 1;
ccyHeader.method = 0;
ccyHeader.paleteSize = 768;
// Cria CCY
ssStream.open("jungle.ccy", ios::binary);
if (!ssStream) {
cout << "Falha ao criar o Arquivo " << endl;
return 1;
}
// Cabeçalho
ssStream.write(reinterpret_cast<char*>(&ccyHeader), sizeof(ccyHeader));
// Imagem
for (int i = 0; i < ImageHeight; i++) {
for (int j = 0; j < ImageWidth; j++) {
ssStream.put(iPixels[i*ImageHeight+j]);
}
};
// Paleta
for (int i = 0; i < 768; i++) {
ssStream.put(iPalette[i]);
};
return 0;
}
PCXHeader Novo;
ifstream arq(Path,ios::binary);
//LEITURA HEADER
arq.read(reinterpret_cast<char*>(&Novo),sizeof(Novo)); //leitura do cabeçalho
ImageWidth = (Novo.XEnd - Novo.XStart + 1);
ImageHeight = (Novo.YEnd - Novo.YStart + 1);
nLines = (ImageWidth*ImageHeight)/Novo.BytesPerLine;