Fork of David Smart's RA8875 library for the purpose of adding touch screen support

Fork of RA8875 by David Smart

Revision:
37:f19b7e7449dc
Parent:
34:c99ec28fac66
Child:
40:04aa280dfa39
--- a/GraphicsDisplay.cpp	Sat Jan 25 00:00:02 2014 +0000
+++ b/GraphicsDisplay.cpp	Sat Jan 25 19:47:33 2014 +0000
@@ -12,7 +12,7 @@
 // provided by the super-class.
 #define USE_HW
 
-//#define DEBUG "GD"
+#define DEBUG "GD"
 // ...
 // INFO("Stuff to show %d", var); // new-line is automatically appended
 //
@@ -47,8 +47,6 @@
 #define HexDump(a, b, c)
 #endif
 
-// #define LOCALFONT
-
 #ifdef LOCALFONT
 const unsigned char FONT8x8[97][8] = {
     0x08, 0x08, 0x08, 0X00, 0X00, 0X00, 0X00, 0X00, // columns, rows, num_bytes_per_char
@@ -155,21 +153,17 @@
     : TextDisplay(name)
 {
     font = NULL;
-    //foreground(0xFFFF);
-    //background(0x0000);
 }
 
 RetCode_t GraphicsDisplay::set_font(const unsigned char * _font)
 {
-    font = _font;
-    INFO("set_font(%lu) %lu", _font, font);
-    return noerror;     // trusting them, but it might be good to put some checks in here...
+    font = _font;     // trusting them, but it might be good to put some checks in here...
+    return noerror;
 }
 
 #ifdef LOCALFONT
 int GraphicsDisplay::character(int x, int y, int value)
 {
-    INFO("character(%d,%d,%c)", x, t, value);
     if (value <= 0x1F && value >= 7F)
         return 0;
     
@@ -190,7 +184,7 @@
 }
 #endif
 
-RetCode_t GraphicsDisplay::window(unsigned int x, unsigned int y, unsigned int w, unsigned int h)
+RetCode_t GraphicsDisplay::window(loc_t x, loc_t y, dim_t w, dim_t h)
 {
     // current pixel location
     _x = x;
@@ -210,7 +204,6 @@
 
 RetCode_t GraphicsDisplay::putp(color_t color)
 {
-    // put pixel at current pixel location
     pixel(_x, _y, color);
     // update pixel location based on window settings
     _x++;
@@ -230,9 +223,12 @@
     fillrect(x,y, x+w, y+h, color);
     #else
     window(x, y, w, h);
+    _StartGraphicsStream();
     for(int i=0; i<w*h; i++) {
         putp(color);
     }
+    _EndGraphicsStream();
+    WindowMax();
     #endif
 }
 
@@ -245,11 +241,15 @@
 void GraphicsDisplay::blit(int x, int y, int w, int h, const int * color)
 {
     window(x, y, w, h);
+    _StartGraphicsStream();
     for (int i=0; i<w*h; i++) {
         putp(color[i]);
     }
+    _EndGraphicsStream();
+    WindowMax();
 }
 
+#ifdef LOCALFONT
 int GraphicsDisplay::blitbit(int x, int y, int w, int h, const char * color)
 {
     _foreground = 0xFFFF;
@@ -259,6 +259,7 @@
         color[0], color[1], color[2], color[3], color[4], color[5], color[6], color[7], 
         color[8], color[9], color[10], color[11], color[12], color[13], color[14], color[15]);
     window(x, y, w, h);
+    _StartGraphicsStream();
     for (int i = 0; i < w*h; i++) {
         char byte = color[i >> 3];
         int offset = i & 0x7;
@@ -267,30 +268,42 @@
         int c = ((byte << offset) & 0x80) ? _foreground : _background;
         putp(c);
     }
+    _EndGraphicsStream();
+    WindowMax();
     return w;
 }
+#endif
 
 
 int GraphicsDisplay::fontblit(int x, int y, const unsigned char * fontTable, const unsigned char * fontChar)
 {
-    _foreground = 0xFFFF;
     //int fontWidth = font[1];                       // get hor size of font
     int fontHeight = font[2];                      // get vert size of font
     int bytesPerLine = font[3];                       // bytes per line
     int charWidth = fontChar[0];        // width of this character
     int px, py;
+    
+    //INFO("(%d,%d) %lu, %lu %X/%X", x,y, fontTable, fontChar, _foreground, _background);
+    //INFO("char size (%d,%d)", charWidth, fontHeight);
+    //HexDump("char", (uint8_t *)fontChar, 32);
+    //INFO("(f,b) = (%04X,%04X)", _foreground, _background)
     window(x, y, charWidth, fontHeight);
-    
+    _StartGraphicsStream();
+    //INFO("(f,b) = (%04X,%04X)", _foreground, _background)
     for (py = 0; py < fontHeight; py++) {
         int bitmask = 1 << (py & 7);
         
         for (px = 0; px < charWidth; px++) {
             int offset = (py / 8) + px * bytesPerLine;
             unsigned char byte = fontChar[offset + 1];  // skip the char's # bits wide value
-            int c = (byte & bitmask) ? _foreground : _background;
+            color_t c = (byte & bitmask) ? _foreground : _background;
+            //INFO("(%2d,%2d) %02X & %02X => %04X [%04X,%04X]", px, py, byte, bitmask, c, _foreground, _background);
+            //pixel(x+px, y+py, c);
             putp(c);
         }
     }
+    _EndGraphicsStream();
+    WindowMax();
     return charWidth;
 }
 
@@ -307,14 +320,11 @@
     c  = ((colorPalette[i].rgbBlue  >> 3) <<  0);
     c |= ((colorPalette[i].rgbGreen >> 2) <<  5);
     c |= ((colorPalette[i].rgbRed   >> 3) << 11);
-    c = (c >> 8) | (c << 8);
-    //INFO("B %02X G %02X R %02X c %04X", colorPalette[i].rgbBlue, colorPalette[i].rgbGreen, 
-    //    colorPalette[i].rgbRed, c);
     return c;
 }
 
 
-RetCode_t GraphicsDisplay::RenderBitmapFile(unsigned int x, unsigned int y, const char *Name_BMP)
+RetCode_t GraphicsDisplay::RenderBitmapFile(loc_t x, loc_t y, const char *Name_BMP)
 {
     #define OffsetPixelWidth    18
     #define OffsetPixelHeight   22
@@ -327,7 +337,6 @@
     RGBQUAD * colorPalette = NULL;
     int colorCount;
     uint8_t * lineBuffer = NULL;
-    
     uint16_t BPP_t;
     uint32_t PixelWidth, PixelHeight;
     uint32_t start_data;
@@ -410,15 +419,12 @@
     
     start_data = BMP_Header.bfOffBits;
     HexDump("Raw Data", (uint8_t *)&start_data, 32);
-    //bool tag = true;
     //INFO("(%d,%d) (%d,%d), [%d,%d]", x,y, PixelWidth,PixelHeight, lineBufSize, padd);
     for (j = PixelHeight - 1; j >= 0; j--) {                //Lines bottom up
         offset = start_data + j * (lineBufSize + padd);     // start of line
         fseek(Image, offset, SEEK_SET);
         fread(lineBuffer, 1, lineBufSize, Image);           // read a line - slow !
         //INFO("offset: %6X", offset);
-        //if (tag)
-        //    HexDump("Line", (uint8_t *)lineBuffer, lineBufSize);
         for (i = 0; i < PixelWidth; i++) {                  // copy pixel data to TFT
             if (BPP_t == 4) {
                 uint8_t dPix = lineBuffer[i/2];
@@ -431,16 +437,11 @@
             } else if (BPP_t == 16) {
                 putp(lineBuffer[i]);
             } else if (BPP_t == 24) {
-                color_t color;  // BGR
+                color_t color;
                 color = RGB(lineBuffer[i*3+2], lineBuffer[i*3+1], lineBuffer[i*3+0]);
-                //if (tag) 
-                //    INFO("color[%2d]: RGB(%02X,%02X,%02X) => %04X", 
-                //        i, lineBuffer[i*2], lineBuffer[i*3+1], lineBuffer[i*3+0], color);
-                color = (color >> 8) | (color << 8);
                 putp(color);
             }
         }
-        //tag = false;
     }
     free(lineBuffer);
     free(colorPalette);