Skip to content

Commit

Permalink
i don't care i can't make this work
Browse files Browse the repository at this point in the history
  • Loading branch information
counter185 committed Jun 3, 2024
1 parent b181457 commit aac67d5
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 6 deletions.
66 changes: 66 additions & 0 deletions freesprite/FileIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,72 @@ Layer* readGCI(PlatformNativePathString path, uint64_t seek)
return NULL;
}

Layer* readMSP(PlatformNativePathString path, uint64_t seek)
{
struct MSPHeader
{
uint16_t Key1; /* Magic number */
uint16_t Key2; /* Magic number */
uint16_t Width; /* Width of the bitmap in pixels */
uint16_t Height; /* Height of the bitmap in pixels */
uint16_t XARBitmap; /* X Aspect ratio of the bitmap */
uint16_t YARBitmap; /* Y Aspect ratio of the bitmap */
uint16_t XARPrinter; /* X Aspect ratio of the printer */
uint16_t YARPrinter; /* Y Aspect ratio of the printer */
uint16_t PrinterWidth; /* Width of the printer in pixels */
uint16_t PrinterHeight; /* Height of the printer in pixels */
uint16_t XAspectCorr; /* X aspect correction (unused) */
uint16_t YAspectCorr; /* Y aspect correction (unused) */
uint16_t Checksum; /* Checksum of previous 24 bytes */
uint16_t Padding[3]; /* Unused padding */
};

FILE* infile = platformOpenFile(path, PlatformFileModeRB);
if (infile != NULL) {
fseek(infile, 0, SEEK_END);
uint64_t fileLength = ftell(infile);
fseek(infile, 0, SEEK_SET);

MSPHeader hdr;
printf("%i\n", sizeof(MSPHeader));
fread(&hdr, sizeof(MSPHeader), 1, infile);
//fseek(infile, 1, SEEK_CUR);
Layer* ret = new Layer(hdr.Width, hdr.Height);
ret->name = "MSP1.0/2.0 Layer";
uint32_t* pxd = (uint32_t*)ret->pixelData;
uint64_t dataPointer = 0;
while (dataPointer < hdr.Width*hdr.Height && ftell(infile) < fileLength) {
uint8_t RunType;
fread(&RunType, 1, 1, infile);
if (RunType == 0){
uint8_t RunCount;
fread(&RunCount, 1, 1, infile);
uint8_t RunValue;
fread(&RunValue, 1, 1, infile);
for (int x = 0; x < RunCount; x++) {
for (int bit = 0; bit < 8; bit++) {
pxd[dataPointer++] = 0xFF000000 | (0xFFFFFF * ((RunValue >> (7 - bit)) & 0b1));
}
//pxd[dataPointer++] = 0xFF000000 | (0x010101 * RunValue);
}
} else {
for (int x = 0; x < RunType; x++) {
uint8_t RunValue;
fread(&RunValue, 1, 1, infile);
for (int bit = 0; bit < 8; bit++) {
pxd[dataPointer++] = 0xFF000000 | (0xFFFFFF * ((RunValue >> (7 - bit)) & 0b1));
}
//pxd[dataPointer++] = 0xFF000000 | (0x010101 * RunValue);
}
}
}

fclose(infile);
return ret;
}
return NULL;
}

MainEditor* readOpenRaster(PlatformNativePathString path)
{
FILE* f = platformOpenFile(path, PlatformFileModeRB);
Expand Down
4 changes: 4 additions & 0 deletions freesprite/FileIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Layer* readNES(PlatformNativePathString path, uint64_t seek = 0);
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);
MainEditor* readOpenRaster(PlatformNativePathString path);
MainEditor* readVOIDSN(PlatformNativePathString path);

Expand Down Expand Up @@ -164,6 +165,9 @@ inline std::vector<FileImportNPath> g_fileImportersNPaths = {
},
{
"VTF (voidsprite custom)", ".vtf", &readVTF
},
{
"MSP (voidsprite custom)", ".msp", &readMSP
}
};

Expand Down
6 changes: 3 additions & 3 deletions freesprite/StartScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void StartScreen::tryLoadFile(std::string path)
#endif

for (FileSessionImportNPath importer : g_fileSessionImportersNPaths) {
if (stringEndsWith(path, importer.extension) && importer.canImport(fPath)) {
if (stringEndsWithIgnoreCase(path, importer.extension) && importer.canImport(fPath)) {
MainEditor* session = importer.importFunction(fPath);
if (session != NULL) {
g_addScreen(session);
Expand All @@ -94,7 +94,7 @@ void StartScreen::tryLoadFile(std::string path)

Layer* l = NULL;
for (FileImportNPath importer : g_fileImportersNPaths) {
if (stringEndsWith(path, importer.extension) && importer.canImport(fPath)) {
if (stringEndsWithIgnoreCase(path, importer.extension) && importer.canImport(fPath)) {
l = importer.importFunction(fPath, 0);
if (l != NULL) {
break;
Expand All @@ -106,7 +106,7 @@ void StartScreen::tryLoadFile(std::string path)
}
if (l == NULL) {
for (FileImportUTF8Path importer : g_fileImportersU8Paths) {
if (stringEndsWith(path, importer.extension) && importer.canImport(path)) {
if (stringEndsWithIgnoreCase(path, importer.extension) && importer.canImport(path)) {
l = importer.importFunction(path, 0);
if (l != NULL) {
break;
Expand Down
7 changes: 5 additions & 2 deletions freesprite/mathops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ PlatformNativePathString convertStringOnWin32(std::string a) {
#endif
}

bool stringEndsWith(std::string c, std::string endsWith)
bool stringEndsWithIgnoreCase(std::string c, std::string endsWith)
{
if (c.size() < endsWith.size()) {
return false;
}
return c.substr(c.size() - endsWith.size()) == endsWith;
std::string otherString = c.substr(c.size() - endsWith.size());
std::transform(otherString.begin(), otherString.end(), otherString.begin(), ::tolower);
std::transform(endsWith.begin(), endsWith.end(), endsWith.begin(), ::tolower);
return otherString == endsWith;
}

void rasterizeLine(XY from, XY to, std::function<void(XY)> forEachPixel)
Expand Down
2 changes: 1 addition & 1 deletion freesprite/mathops.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ XY xySubtract(XY p1, XY p2);

std::wstring utf8StringToWstring(std::string a);
PlatformNativePathString convertStringOnWin32(std::string a);
bool stringEndsWith(std::string c, std::string endsWith);
bool stringEndsWithIgnoreCase(std::string c, std::string endsWith);

void rasterizeLine(XY from, XY to, std::function<void(XY)> forEachPixel);
void rasterizeEllipse(XY posMin, XY posMax, std::function<void(XY)> forEachPixel);
Expand Down

0 comments on commit aac67d5

Please sign in to comment.