- Main Page
- Classes
- Files

- File List
- File Members

# flTexturePNG.c

Go to the documentation of this file.

    00001 #include "flGlobal.h"
    00002 #if FL_TEXTURE_PNG != 0
    00003 #include <stdlib.h>
    00004 #include <string.h>
    00005 #include <pspgu.h>
    00006
    00007 #if FL_INCLUDE_ALL_C == 0
    00008 #include "flTexturePNG.h"
    00009 #include "flFile.h"
    00010 #include "flMemory.h"
    00011
    00012 #if FL_DEBUG != 0
    00013 #include "flDebug.h"
    00014 #endif
    00015 #endif
    00016
    00017 Texture* texLoadPNG(char* inPath) {
    00018      #if FL_FILE != 0
    00019      File* tempFile = fileOpen(inPath, FILE_MODE_READ | FILE_MODE_BINARY);
    00020      #else
    00021      FILE* tempFile = fopen(inPath, "rb");
    00022      #endif
    00023      if(!tempFile) {
    00024           #if FL_DEBUG_WARNING != 0
    00025           char tempString[256];
    00026           sprintf(tempString, "PNG load error (%s).\nFile cannot be opened.", inPath);
    00027           debugWarning(tempString);
    00028           #endif
    00029           return NULL;
    00030      }
    00031
    00032      u8* tempPngHeader[8];
    00033      fileRead(tempPngHeader, 8, tempFile);
    00034      if(png_sig_cmp(tempPngHeader, 0, 8);) {
    00035           #if FL_DEBUG_WARNING != 0
    00036           char tempString[256];
    00037           sprintf(tempString, "PNG load error (%s).\nFile is not in png format.", inPath);
    00038           debugWarning(tempString);
    00039           #endif
    00040           return NULL;
    00041      }
    00042
    00043
    00044      fileClose(tempFile);
    00045
    00046      Texture* tempOut = texCreate(inWidth, inHeight, inPixelFormat);
    00047      if(!tempOut) {
    00048           fileClose(tempFile);
    00049           #if FL_DEBUG_ERROR != 0
    00050           char tempString[256];
    00051           sprintf(tempString, "Couldn't create texture struct, while loading \"%s\".\nOut of memory.", inPath);
    00052           debugError(tempString);
    00053           #endif
    00054           return NULL;
    00055      }
    00056
    00057      return tempOut;
    00058 }
    00059
    00060 bool texSavePNG(Texture* inTex, char* inPath) {
    00061      #if FL_DEBUG_ERROR != 0
    00062      debugError("PNG saving not yet supported.");
    00063      #endif
    00064
    00065      return false;
    00066 }
    00067
    00068 #endif