KSM edits to RA8875

Dependents:   Liz_Test_Code

Revision:
145:5eb2492acdda
Parent:
136:224e03d5c31f
Child:
146:373d59f08357
--- a/GraphicsDisplay.cpp	Thu Dec 29 20:06:00 2016 +0000
+++ b/GraphicsDisplay.cpp	Sat May 06 20:27:44 2017 +0000
@@ -9,6 +9,12 @@
 #include "Bitmap.h"
 #include "string.h"
 
+//#include "Utility.h"            // private memory manager
+#ifndef UTILITY_H
+#define swMalloc malloc         // use the standard
+#define swFree free
+#endif
+
 //#define DEBUG "GD  "
 // ...
 // INFO("Stuff to show %d", var); // new-line is automatically appended
@@ -303,7 +309,7 @@
         // Read the color palette
         colorCount = 1 << BMP_Info.biBitCount;
         paletteSize = sizeof(RGBQUAD) * colorCount;
-        colorPalette = (RGBQUAD *)malloc(paletteSize);
+        colorPalette = (RGBQUAD *)swMalloc(paletteSize);
         if (colorPalette == NULL) {
             fclose(Image);
             return(not_enough_ram);
@@ -314,17 +320,17 @@
 
     int lineBufSize = ((BPP_t * PixelWidth + 7)/8);
     INFO("BPP_t %d, PixelWidth %d, lineBufSize %d", BPP_t, PixelWidth, lineBufSize);
-    lineBuffer = (uint8_t *)malloc(lineBufSize);
+    lineBuffer = (uint8_t *)swMalloc(lineBufSize);
     if (lineBuffer == NULL) {
-        free(colorPalette);
+        swFree(colorPalette);
         fclose(Image);
         return(not_enough_ram);
     }
-    pixelBuffer = (color_t *)malloc(PixelWidth * sizeof(color_t));
+    pixelBuffer = (color_t *)swMalloc(PixelWidth * sizeof(color_t));
     if (pixelBuffer == NULL) {
-        free(lineBuffer);
+        swFree(lineBuffer);
         if (colorPalette)
-            free(colorPalette);
+            swFree(colorPalette);
         fclose(Image);
         return(not_enough_ram);
     }
@@ -374,10 +380,10 @@
     }
 //    _EndGraphicsStream();
     window(restore);
-    free(pixelBuffer);      // don't leak memory
-    free(lineBuffer);
+    swFree(pixelBuffer);      // don't leak memory
+    swFree(lineBuffer);
     if (colorPalette)
-        free(colorPalette);
+        swFree(colorPalette);
     return (noerror);
 }
 
@@ -397,7 +403,7 @@
 
 RetCode_t GraphicsDisplay::RenderJpegFile(loc_t x, loc_t y, const char *Name_JPG)
 {
-    #define JPEG_WORK_SPACE_SIZE 3100
+    #define JPEG_WORK_SPACE_SIZE 3100   // Worst case requirements for the decompression
     JDEC * jdec;
     uint16_t * work;
     RetCode_t r = noerror;  // start optimistic
@@ -405,12 +411,10 @@
     
     if (!fh)
         return(file_not_found);
-    
     //INFO("RenderJpegFile(%d,%d,%s)", x,y, Name_JPG);
-    work = (uint16_t *)malloc(JPEG_WORK_SPACE_SIZE);
-    
+    work = (uint16_t *)swMalloc(JPEG_WORK_SPACE_SIZE);
     if (work) {
-        jdec = (JDEC *)malloc(sizeof(JDEC));
+        jdec = (JDEC *)swMalloc(sizeof(JDEC));
         if (jdec) {
             memset(work, 0, JPEG_WORK_SPACE_SIZE/sizeof(uint16_t));
             memset(jdec, 0, sizeof(JDEC));
@@ -424,12 +428,12 @@
             } else {
                 r = not_supported_format;   // error("jd_prepare error:%d", r);
             }
-            free(jdec);
+            swFree(jdec);
         } else {
             WARN("checkpoint");
             r = not_enough_ram;
         }
-        free(work);
+        swFree(work);
     } else {
         WARN("checkpoint");
         r = not_enough_ram;