LCD LIB
Fork of RA8875 by
Diff: GraphicsDisplay.cpp
- Revision:
- 115:c9862fd0c689
- Parent:
- 114:dbfb996bfbf3
- Child:
- 119:d129b798f82f
diff -r dbfb996bfbf3 -r c9862fd0c689 GraphicsDisplay.cpp --- a/GraphicsDisplay.cpp Sun May 15 18:57:06 2016 +0000 +++ b/GraphicsDisplay.cpp Mon May 16 02:05:37 2016 +0000 @@ -9,14 +9,14 @@ #include "Bitmap.h" #include "string.h" -//#define DEBUG "GD " +#define DEBUG "GD " // ... // INFO("Stuff to show %d", var); // new-line is automatically appended // #if (defined(DEBUG) && !defined(TARGET_LPC11U24)) -#define INFO(x, ...) std::printf("[INF %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__); -#define WARN(x, ...) std::printf("[WRN %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__); -#define ERR(x, ...) std::printf("[ERR %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__); +#define INFO(x, ...) std::printf("[INF %s %4d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__); +#define WARN(x, ...) std::printf("[WRN %s %4d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__); +#define ERR(x, ...) std::printf("[ERR %s %4d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__); static void HexDump(const char * title, const uint8_t * p, int count) { int i; @@ -387,6 +387,8 @@ { if (mystrnicmp(FileName + strlen(FileName) - 4, ".bmp", 4) == 0) { return RenderBitmapFile(x,y,FileName); + } else if (mystrnicmp(FileName + strlen(FileName) - 4, ".jpg", 4) == 0) { + return RenderJpegFile(x,y,FileName); } else if (mystrnicmp(FileName + strlen(FileName) - 4, ".ico", 4) == 0) { return RenderIconFile(x,y,FileName); } else { @@ -394,6 +396,45 @@ } } + +RetCode_t GraphicsDisplay::RenderJpegFile(loc_t x, loc_t y, const char *Name_JPG) +{ + #define JPEG_WORK_SPACE_SIZE 3100 + JDEC * jdec; + uint16_t * work; + RetCode_t r = noerror; // start optimistic + FILE * fh = fopen(Name_JPG, "rb"); + + if (!fh) + return(file_not_found); + + work = (uint16_t *)malloc(JPEG_WORK_SPACE_SIZE/sizeof(uint16_t)); + if (work) { + jdec = (JDEC *)malloc(sizeof(JDEC)); + if (jdec) { + r = (RetCode_t)jd_prepare(jdec, NULL, work, JPEG_WORK_SPACE_SIZE, fh); + INFO("jd_prepare returned %d", r); + + if (r == noerror) { + SetGraphicsCursor(x,y); + r = (RetCode_t)jd_decomp(jdec, NULL, 0); + } else { + r = not_supported_format; // error("jd_prepare error:%d", r); + } + free(jdec); + } else { + WARN("checkpoint"); + r = not_enough_ram; + } + free(work); + } else { + WARN("checkpoint"); + r = not_enough_ram; + } + fclose(fh); + return r; // error("jd_decomp error:%d", r); +} + RetCode_t GraphicsDisplay::RenderBitmapFile(loc_t x, loc_t y, const char *Name_BMP) { BITMAPFILEHEADER BMP_Header;