Skip to content

Commit

Permalink
savestate before we go break things
Browse files Browse the repository at this point in the history
  • Loading branch information
counter185 committed Sep 10, 2024
1 parent c6c8721 commit 2b00cc1
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 1 deletion.
108 changes: 107 additions & 1 deletion freesprite/FileIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ enum VTFFORMAT
IMAGE_FORMAT_UVLX8888
};

int DeASTC(Layer* ret, int width, int height, uint64_t fileLength, FILE* infile, int blockWidth = 8, int blockHeight = 8) {
int DeASTC(Layer* ret, int width, int height, uint64_t fileLength, FILE* infile, int blockWidth, int blockHeight) {
uint32_t* pxd = (uint32_t*)ret->pixelData;
/*int skip = 232;
int skipHowMany = 24;
Expand Down Expand Up @@ -120,6 +120,79 @@ int DeASTC(Layer* ret, int width, int height, uint64_t fileLength, FILE* infile,
return astcErrors;
}

Layer* De4BPPBitplane(int width, int height, uint8_t* input)
{
Layer* ret = new Layer(width, height);
uint8_t* colorTable = (uint8_t*)malloc(width * height);
memset(colorTable, 0, width * height);
uint64_t colorTablePointer = 0;
uint8_t* inputPtr = input;

// X 0 0 0 bitplane
inputPtr = input;
colorTablePointer = 0;
for (uint64_t y = 0; y < height; y++) {
for (uint64_t i = 0; i < 32; i++) {
uint8_t byte = *inputPtr++;
for (int j = 0; j < 8; j++) {
colorTable[colorTablePointer++] |= (((byte >> (7 - j)) & 1) << 3);
}
inputPtr += 2;
}
//inputPtr += 128;
}

// 0 X 0 0 bitplane
inputPtr = input + 1;
colorTablePointer = 0;
for (uint64_t y = 0; y < height; y++) {
for (uint64_t i = 0; i < 32; i++) {
uint8_t byte = *inputPtr++;
for (int j = 0; j < 8; j++) {
colorTable[colorTablePointer++] |= (((byte >> (7 - j)) & 1) << 2);
}
inputPtr += 2;
}
//inputPtr += 128;
}

// 0 0 X 0 bitplane
inputPtr = input + (width/8 * height * 2);
colorTablePointer = 0;
for (uint64_t y = 0; y < height; y++) {
for (uint64_t i = 0; i < 32; i++) {
uint8_t byte = *inputPtr++;
for (int j = 0; j < 8; j++) {
colorTable[colorTablePointer++] |= (((byte >> (7 - j)) & 1) << 1);
}
inputPtr += 2;
}
//inputPtr += 128;
}

// 0 0 0 X bitplane
inputPtr = input + (width/8 * height * 2) + 1;
colorTablePointer = 0;
for (uint64_t y = 0; y < height; y++) {
for (uint64_t i = 0; i < 32; i++) {
uint8_t byte = *inputPtr++;
for (int j = 0; j < 8; j++) {
colorTable[colorTablePointer++] |= ((byte >> (7 - j)) & 1);
}
inputPtr += 2;
}
//inputPtr += 128;
}

uint32_t* pxd = (uint32_t*)ret->pixelData;
for (uint64_t i = 0; i < width * height; i++) {
pxd[i] = PackRGBAtoARGB(colorTable[i], colorTable[i], colorTable[i], 255);
}

free(colorTable);
return ret;
}

void DeXT1(Layer* ret, int width, int height, FILE* infile)
{
uint32_t* pxd = (uint32_t*)ret->pixelData;
Expand Down Expand Up @@ -1363,6 +1436,39 @@ Layer* readMSP(PlatformNativePathString path, uint64_t seek)
return NULL;
}

Layer* readMarioPaintSRM(PlatformNativePathString path, uint64_t seek)
{
FILE* f = platformOpenFile(path, PlatformFileModeRB);
if (f != NULL) {

fseek(f, 0x6000, SEEK_SET);
uint8_t* data = (uint8_t*)malloc(0xB800 - 0x6000);
fread(data, 0xB800 - 0x6000, 1, f);
Layer* l = De4BPPBitplane(256, 174, data);
l->replaceColor(0xFF000000, 0x00000000);
l->replaceColor(0xff010101, 0xFFFF0000);
l->replaceColor(0xff020202, 0xffFFA500);
l->replaceColor(0xff030303, 0xffFFFF00);
l->replaceColor(0xff040404, 0xff90EE90);
l->replaceColor(0xff050505, 0xff006400);
l->replaceColor(0xff060606, 0xff00FF00);
l->replaceColor(0xff070707, 0xff0000FF);
l->replaceColor(0xff080808, 0xff800000);
l->replaceColor(0xff090909, 0xffA52A2A);
l->replaceColor(0xff0A0A0A, 0xffFFC0CB);
l->replaceColor(0xff0B0B0B, 0xff800080);
l->replaceColor(0xff0C0C0C, 0xffFFFFFF);
l->replaceColor(0xff0D0D0D, 0xff000000);
l->replaceColor(0xff0E0E0E, 0xffA9A9A9);
l->replaceColor(0xff0F0F0F, 0xffD3D3D3);

free(data);
fclose(f);
return l;
}
return NULL;
}

MainEditor* readOpenRaster(PlatformNativePathString path)
{
FILE* f = platformOpenFile(path, PlatformFileModeRB);
Expand Down
8 changes: 8 additions & 0 deletions freesprite/FileIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ void DeXT1(Layer* ret, int width, int height, FILE* infile);
void DeXT23(Layer* ret, int width, int height, FILE* infile);
void DeXT45(Layer* ret, int width, int height, FILE* infile);

int DeASTC(Layer* ret, int width, int height, uint64_t fileLength, FILE* infile, int blockWidth = 8, int blockHeight = 8);

Layer* De4BPPBitplane(int width, int height, uint8_t* input);

Layer* _VTFseekToLargestMipmapAndRead(FILE* infile, int width, int height, int mipmapCount, int frames, int imageFormat);

//void _parseORAStacksRecursively(MainEditor* editor, pugi::xml_node rootNode, zip_t* zip, XY offset = {0,0});
Expand All @@ -23,6 +27,7 @@ Layer* readDDS(PlatformNativePathString path, uint64_t seek = 0);
Layer* readVTF(PlatformNativePathString path, uint64_t seek = 0);
Layer* readGCI(PlatformNativePathString path, uint64_t seek = 0);
Layer* readMSP(PlatformNativePathString path, uint64_t seek = 0);
Layer* readMarioPaintSRM(PlatformNativePathString path, uint64_t seek = 0);
MainEditor* readOpenRaster(PlatformNativePathString path);
MainEditor* readVOIDSN(PlatformNativePathString path);

Expand Down Expand Up @@ -183,6 +188,9 @@ inline std::vector<FileImportNPath> g_fileImportersNPaths = {
},
{
"MSP (voidsprite custom)", ".msp", &readMSP
},
{
"Mario Paint save file (voidsprite custom)", ".srm", &readMarioPaintSRM
}
};

Expand Down

0 comments on commit 2b00cc1

Please sign in to comment.