00001 #include "flGlobal.h" 00002 #if FL_TEXTURE_RAW != 0 00003 #include <stdlib.h> 00004 #include <string.h> 00005 #include <pspgu.h> 00006 00007 #if FL_INCLUDE_ALL_C == 0 00008 #include "flTextureRAW.h" 00009 #include "flFile.h" 00010 00011 #if FL_DEBUG != 0 00012 #include "flDebug.h" 00013 #endif 00014 #endif 00015 00016 Texture* texLoadRAW(char* inPath, u32 inWidth, u32 inHeight, u8 inPixelFormat) { 00017 #if FL_FILE != 0 00018 File* tempFile = fileOpen(inPath, FILE_MODE_READ | FILE_MODE_BINARY); 00019 #else 00020 FILE* tempFile = fopen(inPath, "rb"); 00021 #endif 00022 if(!tempFile) { 00023 #if FL_DEBUG_ERROR != 0 00024 char tempString[256]; 00025 sprintf(tempString, "RAW load error (%s).\nFile cannot be opened", inPath); 00026 debugError(tempString); 00027 #endif 00028 return NULL; 00029 } 00030 00031 Texture* tempOut = texCreate(inWidth, inHeight, inPixelFormat); 00032 if(!tempOut) { 00033 fileClose(tempFile); 00034 #if FL_DEBUG_ERROR != 0 00035 char tempString[256]; 00036 sprintf(tempString, "Couldn't create texture struct, while loading \"%s\".\nOut of memory.", inPath); 00037 debugError(tempString); 00038 #endif 00039 return NULL; 00040 } 00041 00042 u32 i; 00043 for(i = 0; i < inHeight; i++) 00044 fileRead(&tempOut->texData[(i * tempOut->texDataWidth * texBPP(tempOut)) >> 3], ((texBPP(tempOut) * inWidth) >> 3), tempFile); 00045 00046 fileClose(tempFile); 00047 00048 return tempOut; 00049 } 00050 00051 bool texSaveRAW(Texture* inTex, char* inPath) { 00052 if(texPalettized(inTex) && !inTex->texPalette) { 00053 #if FL_DEBUG != 0 00054 debugError("Trying to save palettized texture without palette."); 00055 #endif 00056 return false; 00057 } 00058 00059 #if FL_FILE != 0 00060 File* tempFile = fileOpen(inPath, FILE_MODE_WRITE | FILE_MODE_BINARY); 00061 #else 00062 FILE* tempFile = fopen(inPath, "wb"); 00063 #endif 00064 if(!tempFile) { 00065 fileClose(tempFile); 00066 #if FL_DEBUG_ERROR != 0 00067 char tempString[256]; 00068 sprintf(tempString, "RAW save error (%s).\nFile cannot be opened", inPath); 00069 debugError(tempString); 00070 #endif 00071 return false; 00072 } 00073 00074 #if FL_GRAPHICS != 0 00075 bool tempReswizzle = false; 00076 if(inTex->texSwizzled) { 00077 if(texUnswizzle(inTex)) { 00078 tempReswizzle = true; 00079 } else { 00080 #if FL_DEBUG != 0 00081 debugWarning("Can't un-swizzle texture for saving."); 00082 #endif 00083 return false; 00084 } 00085 } 00086 #else 00087 if(inTex->texSwizzled) { 00088 #if FL_DEBUG != 0 00089 debugWarning("Can't un-swizzle texture for saving, because flGraphics isn't compiled in."); 00090 #endif 00091 return false; 00092 } 00093 #endif 00094 00095 if(texPalettized(inTex)) 00096 fileWrite(tempOut->texPalette->palData, ((tempOut->texPalette->palEntries * palBPP(inTex->texPalette)) >> 3), tempFile); 00097 00098 u32 i; 00099 for(i = 0; i < inHeight; i++) 00100 fileWrite(&tempOut->texData[(i * tempOut->texDataWidth * texBPP(tempOut)) >> 3], ((texBPP(tempOut) * inWidth) >> 3), tempFile); 00101 00102 fileClose(tempFile); 00103 00104 #if FL_GRAPHICS != 0 00105 if(tempReswizzle) 00106 texSwizzle(inTex); 00107 #endif 00108 00109 return true; 00110 } 00111 00112 #endif