Library to control a Graphics TFT connected to 4-wire SPI - revised for the Raio RA8875 Display Controller.

Dependents:   FRDM_RA8875_mPaint RA8875_Demo RA8875_KeyPadDemo SignalGenerator ... more

Fork of SPI_TFT by Peter Drescher

See Components - RA8875 Based Display

Enhanced touch-screen support - where it previous supported both the Resistive Touch and Capacitive Touch based on the FT5206 Touch Controller, now it also has support for the GSL1680 Touch Controller.

Offline Help Manual (Windows chm)

/media/uploads/WiredHome/ra8875.zip.bin (download, rename to .zip and unzip)

Files at this revision

API Documentation at this revision

Comitter:
WiredHome
Date:
Wed Jul 17 03:02:31 2019 +0000
Parent:
176:4ab96d33a8ec
Child:
178:ae472eb22740
Commit message:
A little bit of work on GIF, and disable some debug printf's.

Changed in this revision

GraphicsDisplayGIF.cpp Show annotated file Show diff for this revision Revisions of this file
RA8875.h Show annotated file Show diff for this revision Revisions of this file
--- a/GraphicsDisplayGIF.cpp	Sun Mar 24 14:49:49 2019 +0000
+++ b/GraphicsDisplayGIF.cpp	Wed Jul 17 03:02:31 2019 +0000
@@ -14,7 +14,7 @@
 #include "GraphicsDisplay.h"
 
 
-#define DEBUG "GIF_"
+//#define DEBUG "GIF_"
 // 
 // INFO("Stuff to show %d", var); // new-line is automatically appended
 //
@@ -131,9 +131,12 @@
 
     // Create a dictionary large enough to hold "code_length" entries.
     // Once the dictionary overflows, code_length increases
-    dictionary = (dictionary_entry_t *) malloc(sizeof(dictionary_entry_t) * (1 << (code_length + 1)));
-    if (dictionary == NULL)
+    size_t bytes = sizeof(dictionary_entry_t) * (1 << (code_length + 1));
+    INFO("uncompress_gif malloc(%d)", bytes);
+    dictionary = (dictionary_entry_t *) malloc(bytes);
+    if (dictionary == NULL) {
         return not_enough_ram;
+    }
     // Initialize the first 2^code_len entries of the dictionary with their
     // indices.  The rest of the entries will be built up dynamically.
 
@@ -228,7 +231,7 @@
         while (code != -1) {
             int pos = dictionary[code].len - 1;
             out[pos] = dictionary[code].byte;
-            //INFO("%p out[%d] = %02X\r\n", out, pos, out[pos]);
+            //INFO("%p out[%d] = %02X", out, pos, out[pos]);
             if (dictionary[code].prev == code) {
                 free(dictionary);
                 return not_supported_format;
@@ -299,17 +302,17 @@
 RetCode_t GraphicsDisplay::readGIFImageDescriptor(FILE * fh, gif_image_descriptor_t * imageDescriptor) {
     if (read_filesystem_bytes(imageDescriptor, gif_image_descriptor_size, fh) < gif_image_descriptor_size)
         return not_supported_format;
-    INFO("gif_image_descriptor\r\n");
-    INFO("       left: %d\r\n", imageDescriptor->image_left_position);
-    INFO("        top: %d\r\n", imageDescriptor->image_top_position);
-    INFO("      width: %d\r\n", imageDescriptor->image_width);
-    INFO("     height: %d\r\n", imageDescriptor->image_height);
-    INFO("     fields: %02Xx\r\n", imageDescriptor->fields);
-    INFO("          lct: %2d\r\n", (imageDescriptor->fields & 0x80) ? 1 : 0);
-    INFO("          res: %2d\r\n", (imageDescriptor->fields & 0x40) ? 1 : 0);
-    INFO("         sort: %2d\r\n", (imageDescriptor->fields & 0x20) ? 1 : 0);
-    INFO("          res: %2d\r\n", ((imageDescriptor->fields & 0x18) >> 3));
-    INFO("      lct siz: %2d\r\n", 1 << ((imageDescriptor->fields & 0x07) + 1));
+    INFO("gif_image_descriptor");
+    INFO("       left: %d", imageDescriptor->image_left_position);
+    INFO("        top: %d", imageDescriptor->image_top_position);
+    INFO("      width: %d", imageDescriptor->image_width);
+    INFO("     height: %d", imageDescriptor->image_height);
+    INFO("     fields: %02Xx", imageDescriptor->fields);
+    INFO("          lct: %2d", (imageDescriptor->fields & 0x80) ? 1 : 0);
+    INFO("          res: %2d", (imageDescriptor->fields & 0x40) ? 1 : 0);
+    INFO("         sort: %2d", (imageDescriptor->fields & 0x20) ? 1 : 0);
+    INFO("          res: %2d", ((imageDescriptor->fields & 0x18) >> 3));
+    INFO("locclrtbl siz: %2d", 1 << ((imageDescriptor->fields & 0x07) + 1));
     if (imageDescriptor->fields & 0x80) {
         local_color_table_size = 1 << ((imageDescriptor->fields & 0x07) + 1);
         local_color_table = (color_t *) malloc(sizeof(color_t) * local_color_table_size);
@@ -321,6 +324,7 @@
             return not_supported_format;
         }
     }
+    INFO("gif_image_descriptor end.");
     return noerror;
 }
 
@@ -340,19 +344,20 @@
 
     if (read_filesystem_bytes(&lzw_code_size, 1, fh) < 1)
         goto done;
-    INFO("lzw_code_size\r\n");
-    INFO("   lzw code: %d\r\n", lzw_code_size);
+    INFO("lzw_code_size %d", lzw_code_size);
     compressed_data_length = read_gif_sub_blocks(fh, &compressed_data);
     if (compressed_data_length > 0) {
         uncompress_gifed_data_length = width * height;
-        *uncompress_gifed_data = (unsigned char *) malloc(uncompress_gifed_data_length);
-        if (*uncompress_gifed_data == NULL)
+        *uncompress_gifed_data = (unsigned char *)malloc(uncompress_gifed_data_length);
+        if (*uncompress_gifed_data == NULL) {
             return not_enough_ram;
+        }
         res = uncompress_gif(lzw_code_size, compressed_data, compressed_data_length, *uncompress_gifed_data);
     }
 done:
     if (compressed_data)
         free(compressed_data);
+    INFO("lzw_code_size end %d", res);
     return res;
 }
 
@@ -368,18 +373,18 @@
     if (read_filesystem_bytes(&extension, extension_size, fh) < extension_size) {
         return 0;
     }
-    INFO("extension\r\n");
-    INFO("        code: %d\r\n", extension.extension_code);
-    INFO("  block size: %d\r\n", extension.block_size);
+    INFO("extension");
+    INFO("        code: %d", extension.extension_code);
+    INFO("  block size: %d", extension.block_size);
     switch (extension.extension_code) {
         case GRAPHIC_CONTROL:
             if (read_filesystem_bytes(&gce, graphic_control_extension_size, fh) < graphic_control_extension_size) {
                 return 0;
             }
-            INFO("graphic_control_extension\r\n");
-            INFO("      fields: %d\r\n", gce.fields);
-            INFO("  delay time: %d\r\n", gce.delay_time);
-            INFO(" transparent: %d\r\n", gce.transparent_color_index);
+            INFO("graphic_control_extension");
+            INFO("      fields: %d", gce.fields);
+            INFO("  delay time: %d", gce.delay_time);
+            INFO(" transparent: %d", gce.transparent_color_index);
             break;
         case APPLICATION_EXTENSION:
             if (read_filesystem_bytes(&application, application_extension_size, fh) < application_extension_size) {
@@ -437,27 +442,36 @@
             return not_supported_format;
         INFO("block type: %02X", block_type);
         
+        RetCode_t r_pgid = noerror;
         switch (block_type) {
             case IMAGE_DESCRIPTOR:
-                if (readGIFImageDescriptor(fh, &gif_image_descriptor) != noerror)
+                if (readGIFImageDescriptor(fh, &gif_image_descriptor) != noerror) {
+                    INFO("not supported format");
                     return not_supported_format;
-                if (process_gif_image_descriptor(fh, &uncompress_gifed_data, gif_image_descriptor.image_width, gif_image_descriptor.image_height) == noerror) {
+                }
+                r_pgid = process_gif_image_descriptor(fh, &uncompress_gifed_data, gif_image_descriptor.image_width, gif_image_descriptor.image_height);
+                if (r_pgid != noerror) {
+                    INFO("error %d", r_pgid);
+                    return r_pgid;
+                } else {
                     if (uncompress_gifed_data) {
                         // Ready to render to the screen
-                        INFO("Render to (%d,%d)\r\n", ScreenX, ScreenY);
+                        INFO("Render to (%d,%d)", ScreenX, ScreenY);
                         color_t * active_color_table = (local_color_table) ? local_color_table : global_color_table;
 
                         // create a local image buffer for this fragment
                         color_t * cbmp = (color_t *) malloc(sizeof(color_t) * gif_image_descriptor.image_width * gif_image_descriptor.image_height);
-                        if (cbmp == NULL)
+                        if (cbmp == NULL) {
+                            INFO("not enough ram");
                             return not_enough_ram;
+                        }
                         for (int i = 0; i < gif_image_descriptor.image_width * gif_image_descriptor.image_height; i++) {
                             int cIndex = uncompress_gifed_data[i];
                             cbmp[i] = active_color_table[cIndex];
                         }
                         // Write Fragment to Screen
                         #if 0
-                        INFO("Render fragment: (%d,%d), offset: (%d,%d), w x h (%d,%d)\r\n",
+                        INFO("Render fragment: (%d,%d), offset: (%d,%d), w x h (%d,%d)",
                             ScreenX, ScreenY,
                             gif_image_descriptor.image_left_position,
                             gif_image_descriptor.image_top_position,
@@ -467,7 +481,7 @@
                             for (uint16_t x = 0; x < gif_image_descriptor.image_width; x++) {
                                 INFO("%04X ", cbmp[y * gif_image_descriptor.image_height + x]);
                             }
-                            INFO("\r\n");
+                            INFO("");
                         }
                         #else
                         rect_t restore = windowrect;
@@ -487,20 +501,22 @@
                         free(local_color_table);
                         local_color_table = NULL;
                     }
-                } else {
-                    return not_supported_format;
                 }
                 break;
             case EXTENSION_INTRODUCER:
-                if (!process_gif_extension(fh))
+                if (!process_gif_extension(fh)) {
+                    INFO("not supported format");
                     return not_supported_format;
+                }
                 break;
             case TRAILER:
                 break;
             default:
+                INFO("not supported format");
                 return not_supported_format;
         }
     }
+    INFO("no error");
     return noerror;
 }
 
@@ -528,16 +544,16 @@
         return not_supported_format;
     }
     screen_descriptor_isvalid = true;
-    INFO("screen_descriptor\r\n");
-    INFO("      width: %d\r\n", screen_descriptor.width);
-    INFO("     height: %d\r\n", screen_descriptor.height);
-    INFO("     fields: %02Xx\r\n", screen_descriptor.fields);
-    INFO("          gct: %2d\r\n", (screen_descriptor.fields & 0x80) ? 1 : 0);
-    INFO("          res: %2d\r\n", ((screen_descriptor.fields & 0x70) >> 4) + 1);
-    INFO("         sort: %2d\r\n", (screen_descriptor.fields & 0x08) ? 1 : 0);
-    INFO("      gct siz: %2d\r\n", 1 << ((screen_descriptor.fields & 0x07) + 1));
-    INFO("   back clr: %d\r\n", screen_descriptor.background_color_index);
-    INFO("    pix rat: %d\r\n", screen_descriptor.pixel_aspect_ratio);
+    INFO("screen_descriptor");
+    INFO("      width: %d", screen_descriptor.width);
+    INFO("     height: %d", screen_descriptor.height);
+    INFO("     fields: %02Xx", screen_descriptor.fields);
+    INFO("          gct: %2d", (screen_descriptor.fields & 0x80) ? 1 : 0);
+    INFO("          res: %2d", ((screen_descriptor.fields & 0x70) >> 4) + 1);
+    INFO("         sort: %2d", (screen_descriptor.fields & 0x08) ? 1 : 0);
+    INFO("      gct siz: %2d", 1 << ((screen_descriptor.fields & 0x07) + 1));
+    INFO("   back clr: %d", screen_descriptor.background_color_index);
+    INFO("    pix rat: %d", screen_descriptor.pixel_aspect_ratio);
     return noerror;
 }
 
--- a/RA8875.h	Sun Mar 24 14:49:49 2019 +0000
+++ b/RA8875.h	Wed Jul 17 03:02:31 2019 +0000
@@ -38,6 +38,9 @@
 /// (GIF) images. These are implemented primarily in software, taking advantage of the 
 /// hardware acceleration where it can. 
 ///
+/// @note GIF support is quite limited, because it has RAM allcoation needs that
+///         exceed the capability of many of the MBED micros.
+///
 /// When you are satisfied with what appears on screen, there is a PrintScreen method 
 /// to pull that image back out and write it to a file system as a BitMap image.
 ///