1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
int main()
{
const size_t width = 256, height = 256;
const size_t no_elems = width * height * 4;
using Image = std::vector<unsigned char>;
std::vector<Image> Image_PNG(1000, Image(no_elems));
CString File_Path;
char sztmp[1024];
const char* filepath = " ";
cin.clear();
cout << "Enter Path to extract sprite graphics to: " << endl;
cin.getline(sztmp, sizeof(sztmp), '\n');
filepath = sztmp;
// Donkey Kong Pallette
static const unsigned char coloursB[16][4] = { // An array of colour values.
//BBB GGG RRR
{ 0, 0, 0, 0 }, /* White */
{ 24, 16, 0, 255 }, /* Index 1 */
{ 64, 32, 0, 255 }, /* Index 2 */
{ 96, 48, 0, 255 }, /* Index 3 */
{ 136, 64, 0, 255 }, /* Index 4 */
{ 168, 80, 0, 255 }, /* Index 5 */
{ 192, 96, 0, 255 }, /* Index 6 */
{ 208, 112, 0, 255 }, /* Index 7 */
{ 248, 0, 0, 255 }, /* Index 8 */
{ 128, 0, 0, 255 }, /* Index 9 */
{ 152, 48, 0, 255 }, /* Index 10 */
{ 248, 128, 112, 255 }, /* Index 11 */
{ 248, 160, 144, 255 }, /* Index 12 */
{ 248, 192, 184, 255 }, /* Index 13 */
{ 248, 224, 216, 255 }, /* Index 14 */
{ 248, 248, 248, 255 } /* Index 15 */
};
// Create the Bitplanes
int* Bitplane0__ROW = new int[10000];
int* Bitplane1__ROW = new int[10000];
int* Bitplane2__ROW = new int[10000];
int* Bitplane3__ROW = new int[10000];
long long int address = 0x381C46; // add 0xC00000 to get the SNES address.
int offset = 0; // The location of the next set of sprites.
int Data_Size = 0;
int x_coord = 0;
int y_coord = 0;
int X;
char oDataK[0x10000]; // Sprite buffer
ifstream inFileK;
inFileK.open("C:\\Users\\Chris\\Desktop\\dkc1.sfc", ios::binary); // Note. this opens a binary stream. This is needed. cuzz the program was using 0x1a values as a Substitute AscII charter which halts the program/Using it as End Of File.
inFileK.seekg(address + Data_Size, 1); // Seek to the current sprite header location.
inFileK.read(oDataK, 0x10000);
inFileK.close();
int Header = 8;
int tile_offset = 0;
int Size_of_coordenants = (oDataK[0] + oDataK[1]) * 2; // 0 contains the value of the number of 2x2 chars (16 x 16 pixel tiles). 1 contains the value of the number of 1x1 chars (8x8 pixel tiles). These two values are multiplied by 2 (two bytes for each set of coordenants).
int Start_Of_First_Tile = Header + Size_of_coordenants; // 8 is the size of the header. 6 is the total size of coordinates(3 chars (tiles) * 2 bytes for earch char) (these are also part of the header...)
// Assign each Bitplane Row the data from the buffer. oData is the buffer containing the bytes from the rom.
for (int p = 0, t = 0; t < 5; t++) // 16x16 Tiles
{
p = 24;
tile_offset = (32 * 17);
Bitplane0__ROW[p++] = oDataK[14 + Start_Of_First_Tile + tile_offset];
Bitplane0__ROW[p++] = oDataK[12 + Start_Of_First_Tile + tile_offset];
Bitplane0__ROW[p++] = oDataK[10 + Start_Of_First_Tile + tile_offset];
Bitplane0__ROW[p++] = oDataK[8 + Start_Of_First_Tile + tile_offset];
Bitplane0__ROW[p++] = oDataK[6 + Start_Of_First_Tile + tile_offset];
Bitplane0__ROW[p++] = oDataK[4 + Start_Of_First_Tile + tile_offset];
Bitplane0__ROW[p++] = oDataK[2 + Start_Of_First_Tile + tile_offset];
Bitplane0__ROW[p++] = oDataK[0 + Start_Of_First_Tile + tile_offset];
p = 24;
Bitplane1__ROW[p++] = oDataK[15 + Start_Of_First_Tile + tile_offset];
Bitplane1__ROW[p++] = oDataK[13 + Start_Of_First_Tile + tile_offset];
Bitplane1__ROW[p++] = oDataK[11 + Start_Of_First_Tile + tile_offset];
Bitplane1__ROW[p++] = oDataK[9 + Start_Of_First_Tile + tile_offset];
Bitplane1__ROW[p++] = oDataK[7 + Start_Of_First_Tile + tile_offset];
Bitplane1__ROW[p++] = oDataK[5 + Start_Of_First_Tile + tile_offset];
Bitplane1__ROW[p++] = oDataK[3 + Start_Of_First_Tile + tile_offset];
Bitplane1__ROW[p++] = oDataK[1 + Start_Of_First_Tile + tile_offset];
p = 24;
Bitplane2__ROW[p++] = oDataK[30 + Start_Of_First_Tile + tile_offset];
Bitplane2__ROW[p++] = oDataK[28 + Start_Of_First_Tile + tile_offset];
Bitplane2__ROW[p++] = oDataK[26 + Start_Of_First_Tile + tile_offset];
Bitplane2__ROW[p++] = oDataK[24 + Start_Of_First_Tile + tile_offset];
Bitplane2__ROW[p++] = oDataK[22 + Start_Of_First_Tile + tile_offset];
Bitplane2__ROW[p++] = oDataK[20 + Start_Of_First_Tile + tile_offset];
Bitplane2__ROW[p++] = oDataK[18 + Start_Of_First_Tile + tile_offset];
Bitplane2__ROW[p++] = oDataK[16 + Start_Of_First_Tile + tile_offset];
p = 24;
Bitplane3__ROW[p++] = oDataK[31 + Start_Of_First_Tile + tile_offset];
Bitplane3__ROW[p++] = oDataK[29 + Start_Of_First_Tile + tile_offset];
Bitplane3__ROW[p++] = oDataK[27 + Start_Of_First_Tile + tile_offset];
Bitplane3__ROW[p++] = oDataK[25 + Start_Of_First_Tile + tile_offset];
Bitplane3__ROW[p++] = oDataK[23 + Start_Of_First_Tile + tile_offset];
Bitplane3__ROW[p++] = oDataK[21 + Start_Of_First_Tile + tile_offset];
Bitplane3__ROW[p++] = oDataK[19 + Start_Of_First_Tile + tile_offset];
Bitplane3__ROW[p++] = oDataK[17 + Start_Of_First_Tile + tile_offset];
}
/////////////////////////////////////////////////////////////////////////////////////////////////
Start_Of_First_Tile = Start_Of_First_Tile + Data_Size; // the location of the curent sprite.
int c = 0;
for (int p = 24; p < 32; p++)
{
// Bottom Right of 16x16
if (p == 24) { c = 256 * (y_coord + 15) * 4 + x_coord + 0 + 0;; }
if (p == 25) { c = 256 * (y_coord + 14) * 4 + x_coord + 0 + 0;; }
if (p == 26) { c = 256 * (y_coord + 13) * 4 + x_coord + 0 + 0;; }
if (p == 27) { c = 256 * (y_coord + 12) * 4 + x_coord + 0 + 0;; }
if (p == 28) { c = 256 * (y_coord + 11) * 4 + x_coord + 0 + 0;; }
if (p == 29) { c = 256 * (y_coord + 10) * 4 + x_coord + 0 + 0;; }
if (p == 30) { c = 256 * (y_coord + 9) * 4 + x_coord + 0 + 0;; }
if (p == 31) { c = 256 * (y_coord + 8) * 4 + x_coord + 0 + 0;; }
// Write the PNG Images
if (p < 32)
{
for (int j = 0, N = 7; j < 8; j++, N--) // Check which bits are set for each pixel of the tiles. Then assign the index colour to the image Array location.
{
std::bitset<4> bs;
bs.set(0, (Bitplane0__ROW[p] >> N) & 1);
bs.set(1, (Bitplane1__ROW[p] >> N) & 1);
bs.set(2, (Bitplane2__ROW[p] >> N) & 1);
bs.set(3, (Bitplane3__ROW[p] >> N) & 1);
unsigned long Index = bs.to_ulong();
Image_PNG[X][c++] = coloursB[Index][0]; // Red
Image_PNG[X][c++] = coloursB[Index][1]; // Green
Image_PNG[X][c++] = coloursB[Index][2]; // Blue
Image_PNG[X][c++] = coloursB[Index][3]; // Alpha
}
}
}
string combined_file_path(string(filepath) + to_string(X) + ".png");
encodeOneStep(combined_file_path.c_str(), Image_PNG[X], width, height); // Write the .png image file.
return 0;
}
|