]> code.delx.au - refind/blobdiff - libeg/lodepng.c
Support for multiple screen shot files using screenshot_###.bmp
[refind] / libeg / lodepng.c
index 54c36ab0491020f03641fe19b10195e8e58afc93..99895fe849f881b0a0692db605142fd2995a6b4a 100644 (file)
@@ -66,10 +66,18 @@ with the "LODEPNG_COMPILE_" #defines divide this up further in an intermixed way
 name, so that you can easily change them to others related to your platform in
 this one location if needed. Everything else in the code calls these.*/
 
+// EFI's equivalent of realloc requires the original buffer's size as an
+// input parameter, which the standard libc realloc does not require. Thus,
+// I've modified mymalloc() to allocate more memory to store this data,
+// and myrealloc() can then read it when required. Because the size is
+// stored at the start of the allocated area, these functions are NOT
+// interchangeable with the standard EFI functions; memory allocated via
+// mymalloc() should be freed via myfree(), and myfree() should NOT be
+// used with memory allocated via AllocatePool() or AllocateZeroPool()!
+
 static void *mymalloc(size_t size) {
    void *ptr;
 
-//   size += sizeof (size_t);
    ptr = AllocateZeroPool(size + sizeof(size_t));
    if (ptr) {
       *(size_t *) ptr = size;
@@ -6273,19 +6281,12 @@ unsigned encode(const std::string& filename,
 
 
 typedef struct _lode_color {
-   UINT16 red;
-   UINT16 green;
-   UINT16 blue;
-   UINT16 alpha;
+   UINT8 red;
+   UINT8 green;
+   UINT8 blue;
+   UINT8 alpha;
 } lode_color;
 
-// typedef struct _lode_color8 {
-//    UINT16 red;
-//    UINT16 green;
-//    UINT16 blue;
-//    UINT16 alpha;
-// } lode_color8;
-
 EG_IMAGE * egDecodePNG(IN UINT8 *FileData, IN UINTN FileDataLength, IN UINTN IconSize, IN BOOLEAN WantAlpha) {
    EG_IMAGE *NewImage = NULL;
    unsigned Error, Width, Height;
@@ -6294,7 +6295,7 @@ EG_IMAGE * egDecodePNG(IN UINT8 *FileData, IN UINTN FileDataLength, IN UINTN Ico
    UINTN i;
 
    Error = lodepng_decode_memory((unsigned char **) &PixelData, &Width, &Height, (unsigned char*) FileData,
-                                 (size_t) FileDataLength, LCT_RGBA, 16);
+                                 (size_t) FileDataLength, LCT_RGBA, 8);
 
    if (Error) {
       return NULL;
@@ -6302,9 +6303,6 @@ EG_IMAGE * egDecodePNG(IN UINT8 *FileData, IN UINTN FileDataLength, IN UINTN Ico
 
    // allocate image structure and buffer
    NewImage = egCreateImage(Width, Height, WantAlpha);
-//    Print(L"Have created image; it %s NULL\n", NewImage ? L"is not" : L"is");
-//    Print(L"NewImage's size is %d x %d\n", NewImage->Width, NewImage->Height);
-//    PauseForKey();
    if ((NewImage == NULL) || (NewImage->Width != Width) || (NewImage->Height != Height))
       return NULL;