Forked para SNOCC
Fork of RA8875 by
Diff: RA8875.cpp
- Revision:
- 85:022bba13c5c4
- Parent:
- 84:e102021864b5
- Child:
- 86:e86b355940f4
--- a/RA8875.cpp Mon Jan 12 01:10:35 2015 +0000 +++ b/RA8875.cpp Tue Jan 13 12:31:44 2015 +0000 @@ -1101,27 +1101,34 @@ RetCode_t RA8875::rect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, fill_t fillit) { + RetCode_t ret = noerror; PERFORMANCE_RESET; - if (x1 == x2 && y1 == y2) { - pixel(x1, y1); - } else if (x1 == x2) { - line(x1, y1, x2, y2); - } else if (y1 == y2) { - line(x1, y1, x2, y2); - } else { - WriteCommandW(0x91, x1); - WriteCommandW(0x93, y1); - WriteCommandW(0x95, x2); - WriteCommandW(0x97, y2); - unsigned char drawCmd = 0x10; // Rectangle - if (fillit == FILL) - drawCmd |= 0x20; - WriteCommand(0x90, drawCmd); - WriteCommand(0x90, 0x80 + drawCmd); // Start drawing. - _WaitWhileReg(0x90, 0x80); + // check for bad_parameter + if (x1 < 0 || x1 >= width() || x2 < 0 || x2 >= width() + || y1 < 0 || y1 >= height() || y2 < 0 || y2 >= height()) + ret = bad_parameter; + else { + if (x1 == x2 && y1 == y2) { + pixel(x1, y1); + } else if (x1 == x2) { + line(x1, y1, x2, y2); + } else if (y1 == y2) { + line(x1, y1, x2, y2); + } else { + WriteCommandW(0x91, x1); + WriteCommandW(0x93, y1); + WriteCommandW(0x95, x2); + WriteCommandW(0x97, y2); + unsigned char drawCmd = 0x10; // Rectangle + if (fillit == FILL) + drawCmd |= 0x20; + WriteCommand(0x90, drawCmd); + ret = WriteCommand(0x90, 0x80 + drawCmd); // Start drawing. + _WaitWhileReg(0x90, 0x80); + } } REGISTERPERFORMANCE(PRF_DRAWRECTANGLE); - return noerror; + return ret; } @@ -1147,7 +1154,10 @@ RetCode_t ret = noerror; PERFORMANCE_RESET; - if (x1 > x2 || y1 > y2 || (radius1 > (x2-x1)/2) || (radius2 > (y2-y1)/2) ) { + if (x1 < 0 || x1 >= width() || x2 < 0 || x2 >= width() + || y1 < 0 || y1 >= height() || y2 < 0 || y2 >= height()) { + ret = bad_parameter; + } else if (x1 > x2 || y1 > y2 || (radius1 > (x2-x1)/2) || (radius2 > (y2-y1)/2) ) { ret = bad_parameter; } else if (x1 == x2 && y1 == y2) { pixel(x1, y1); @@ -1182,6 +1192,9 @@ { RetCode_t ret; + if (x1 < 0 || x1 >= width() || x2 < 0 || x2 >= width() || x3 < 0 || x3 >= width() + || y1 < 0 || y1 >= height() || y2 < 0 || y2 >= height() || y3 < 0 || y3 >= height()) + ret = bad_parameter; foreground(color); ret = triangle(x1,y1,x2,y2,x3,y3,fillit); return ret; @@ -1269,7 +1282,8 @@ RetCode_t ret = noerror; PERFORMANCE_RESET; - if (radius <= 0) { + if (radius <= 0 || (x - radius) < 0 || (x + radius) > width() + || (y - radius) < 0 || (y + radius) > height()) { ret = bad_parameter; } else if (radius == 1) { pixel(x,y); @@ -1308,8 +1322,9 @@ RetCode_t ret = noerror; PERFORMANCE_RESET; - if (radius1 <= 0 || radius2 <= 0) { - ; // do nothing + if (radius1 <= 0 || radius2 <= 0 || (x - radius1) < 0 || (x + radius1) > width() + || (y - radius2) < 0 || (y + radius2) > height()) { + ret = bad_parameter; } else if (radius1 == 1 && radius2 == 1) { pixel(x, y); } else { @@ -1420,9 +1435,6 @@ RetCode_t RA8875::background(unsigned char r, unsigned char g, unsigned char b) { background(RGB(r,g,b)); -// WriteCommand(0x60, r); -// WriteCommand(0x61, g); -// WriteCommand(0x62, b); return noerror; } @@ -1440,9 +1452,6 @@ RetCode_t RA8875::foreground(unsigned char r, unsigned char g, unsigned char b) { foreground(RGB(r,g,b)); -// WriteCommand(0x63, r); -// WriteCommand(0x64, g); -// WriteCommand(0x65, b); return noerror; } @@ -1466,7 +1475,7 @@ Charcoal, BrightBlue, BrightGreen, BrightCyan, Orange, Pink, Yellow, White }; - if (i < 16) + if (i >= 0 && i < 16) return colors[i]; else return 0; @@ -1481,7 +1490,7 @@ "Charcoal", "BrightBlue", "BrightGreen", "BrightCyan", "Orange", "Pink", "Yellow", "White" }; - if (i < 16) + if (i >= 0 && i < 16) return names[i]; else return NULL; @@ -1523,19 +1532,8 @@ RetCode_t RA8875::PrintScreen(uint16_t layer, loc_t x, loc_t y, dim_t w, dim_t h, const char *Name_BMP) { -#if 1 (void)layer; return PrintScreen(x, y, w, h, Name_BMP); -#else - // This is the deprecated interface and with the changes it is no longer implemented correctly. - uint16_t curLayer = GetDrawingLayer(); - RetCode_t ret = SelectDrawingLayer(layer); - if (ret == noerror) { - ret = PrintScreen(x, y, w, h, Name_BMP); - } - SelectDrawingLayer(curLayer); - return ret; -#endif }