Index: screenshot/src/wpsdrawer.cpp =================================================================== --- screenshot/src/wpsdrawer.cpp (revision 0) +++ screenshot/src/wpsdrawer.cpp (revision 0) @@ -0,0 +1,235 @@ +#include "wpsdrawer.h" +#include "utils.h" +#include +#include +#include + + +class QWpsDrawer *drawer; +QPixmap *QWpsDrawer::pix = NULL; +QImage QWpsDrawer::backdrop; +proxy_api QWpsDrawer::api; + +QWpsDrawer::QWpsDrawer(char* model) + : QWidget() +{ + QLibrary lib(QString("proxy_%1").arg(model)); + if(!lib.load()) + qFatal("[ERR] Cannot find proxy_%s library!", model); + api.verbose = 2; + wps_init = (pfwps_init)lib.resolve("wps_init"); + wps_display = (pfwps_display)lib.resolve("wps_display"); + wps_refresh = (pfwps_refresh)lib.resolve("wps_refresh"); + + if (! wps_init && !wps_display && !wps_refresh) + qFatal("[ERR] Failed to resolve funcs!"); + + memset(&api, 0, sizeof(struct proxy_api)); + + api.putsxy = &QWpsDrawer::putsxy; + api.transparent_bitmap_part = &QWpsDrawer::transparent_bitmap_part; + api.bitmap_part = &QWpsDrawer::bitmap_part; + api.drawpixel = &QWpsDrawer::drawpixel; + api.fillrect = &QWpsDrawer::fillrect; + api.hline = &QWpsDrawer::hline; + api.vline = &QWpsDrawer::vline; + api.clear_viewport = &QWpsDrawer::clear_viewport; + api.load_wps_backdrop = &QWpsDrawer::load_wps_backdrop; + api.read_bmp_file = &QWpsDrawer::read_bmp_file; + api.debugf = &qlogger; +} + +void QWpsDrawer::WpsInit(QString wpsfile) +{ + DEBUGF1( QString("QWpsDrawer::WpsInit("+wpsfile+")").toAscii() ); + wps_init(wpsfile.toAscii(), &api); + pix = new QPixmap(api.getwidth(), api.getheight()); + + drawBackdrop(); + + setMinimumWidth(api.getwidth()); + setMinimumHeight(api.getheight()); + + update(); +} + +void QWpsDrawer::putsxy(int x, int y, const unsigned char *str) +{ + QPainter p(pix); + viewport_api avp; + api.get_current_vp(&avp); + DEBUGF2("putsx(int x=%d, int y=%d, const unsigned char *str='%s')", x, y + avp.fontheight, str); + int r, g, b; + api.lcd_unpack(avp.fg_pattern, &r, &g, &b); + p.setPen( QColor(r, g, b, 255) ); + + QFont font("times", avp.fontheight, QFont::Bold); + p.setFont(font); + /* TODO: +font.height */ + p.drawText(x + avp.x, y + avp.fontheight + avp.y, (char*)str); +} + +void QWpsDrawer::transparent_bitmap_part(const void *src, int src_x, int src_y, + int stride, int x, int y, int width, int height) +{ + QImage img; + + DEBUGF2("transparent_bitmap_part(const void *src=%s, int src_x=%d, int src_y=%d, int stride=%d, int x=%d, int y=%d, int width=%d, int height=%d", (char*)src, src_x, src_y, stride, x, y, width, height); + + if(!img.load((char*)src, "BMP")) + DEBUGF1("Cannot load bitmap %s", (char*)src); + QPainter p(pix); + QPoint target(x, y); + QRectF source(src_x, src_y, width, height); + + QImage pink = img.createMaskFromColor(qRgb(255,0,255), Qt::MaskOutColor); + img.setAlphaChannel(pink); + + p.drawImage(target, img, source); +} + +void QWpsDrawer::bitmap_part(const void *src, int src_x, int src_y, + int stride, int x, int y, int width, int height) +{ + QImage img; + + DEBUGF2("bitmap_part(const void *src=%s, int src_x=%d, int src_y=%d, int stride=%d, int x=%d, int y=%d, int width=%d, int height=%d", (char*)src, src_x, src_y, stride, x, y, width, height); + + if(!img.load((char*)src, "BMP")) + DEBUGF1("Cannot load bitmap %s", (char*)src); + QPainter p(pix); + QPoint target(x, y); + QRectF source(src_x, src_y, width, height); + + p.drawImage(target, img, source); +} + +void QWpsDrawer::drawpixel(int x, int y) +{ + QPainter p(pix); + viewport_api avp; + api.get_current_vp(&avp); + + if(avp.drawmode & 4 || avp.drawmode & 1) /* DRMODE_INVERSEVID, DRMODE_BG */ + { + QImage img = backdrop.copy(x, y, 1, 1); + p.drawImage(x, y, img); + } + else if(avp.drawmode & 2) /* DRMODE_FG */ + { + int r, g, b; + api.lcd_unpack(avp.fg_pattern, &r, &g, &b); + p.setPen(QColor(r, g, b, 255)); + p.drawPoint(x, y); + } +} + +void QWpsDrawer::fillrect(int x, int y, int width, int height) +{ + QPainter p(pix); + viewport_api avp; + api.get_current_vp(&avp); + + DEBUGF2("fillrect(int x=%d, int y=%d, int width=%d, int height=%d)\n", x, y, width, height); + + if(avp.drawmode & 4 || avp.drawmode & 1) /* DRMODE_INVERSEVID, DRMODE_BG */ + { + QImage img = backdrop.copy(x, y, width, height); + p.drawImage(x, y, img); + } + else if(avp.drawmode & 2) /* DRMODE_FG */ + { + DEBUGF1("fillrect(int x=%d, int y=%d, int width=%d, int height=%d)\n", x, y, width, height); + int r, g, b; + api.lcd_unpack(avp.fg_pattern, &r, &g, &b); + p.fillRect(x, y, width, height, QColor(r, g, b, 255)); + } +} + +void QWpsDrawer::hline(int x1, int x2, int y) +{ + QPainter p(pix); + viewport_api avp; + api.get_current_vp(&avp); + + if(avp.drawmode & 4 || avp.drawmode & 1) /* DRMODE_INVERSEVID, DRMODE_BG */ + { + QImage img = backdrop.copy(x1, y, x2-x1, 1); + p.drawImage(x1, y, img); + } + else if(avp.drawmode & 2) /* DRMODE_FG */ + { + int r, g, b; + api.lcd_unpack(avp.fg_pattern, &r, &g, &b); + p.setPen(QColor(r, g, b, 255)); + p.drawLine(x1, y, x2, y); + } +} + +void QWpsDrawer::vline(int x, int y1, int y2) +{ + QPainter p(pix); + viewport_api avp; + api.get_current_vp(&avp); + + if(avp.drawmode & 4 || avp.drawmode & 1) /* DRMODE_INVERSEVID, DRMODE_BG */ + { + QImage img = backdrop.copy(x, y1, 1, y2-y1); + p.drawImage(x, y1, img); + } + else if(avp.drawmode & 2) /* DRMODE_FG */ + { + int r, g, b; + api.lcd_unpack(avp.fg_pattern, &r, &g, &b); + p.setPen(QColor(r, g, b, 255)); + p.drawLine(x, y1, x, y2); + } +} + +void QWpsDrawer::updatepix(void) +{ + if (pix==NULL) + return; + + QPainter p(this); + + drawBackdrop(); + wps_refresh(); + + p.drawPixmap(pix->width(), pix->height(), *pix); + +} + +void QWpsDrawer::clear_viewport(int x, int y, int w, int h, int color) +{ + DEBUGF2("clear_viewport(int x=%d,int y=%d,int w=%d,int h=%d, int color=%d)",x, y, w, h, color); + QPainter p(pix); + + QImage img = backdrop.copy(x, y, w, h); + p.drawImage(x, y, img); +} + +bool QWpsDrawer::load_wps_backdrop(char* filename) +{ + DEBUGF2("load backdrop: %s", filename); + backdrop.load(filename, "BMP"); + return true; +} + +int QWpsDrawer::read_bmp_file(const char* filename, int *width, int *height) +{ + QImage img; + if(!img.load(filename, "BMP")) + return 0; + *width = img.width(); + *height = img.height(); + return 1; +} + +void QWpsDrawer::drawBackdrop() +{ + QPainter b(pix); + QImage pink = backdrop.createMaskFromColor(qRgb(255,0,255), Qt::MaskOutColor); + backdrop.setAlphaChannel(pink); + b.drawImage(0, 0, backdrop); +} Property changes on: screenshot/src/wpsdrawer.cpp ___________________________________________________________________ Name: svn:eol-style + native Index: screenshot/src/utils.cpp =================================================================== --- screenshot/src/utils.cpp (revision 0) +++ screenshot/src/utils.cpp (revision 0) @@ -0,0 +1,15 @@ +#include "utils.h" + +int qlogger(const char* fmt,...) +{ + va_list ap; + QString s; + + va_start(ap, fmt); + s.vsprintf(fmt, ap); + va_end(ap); + + qDebug()< +#include +#include "api.h" +// + +typedef int (*pfwps_init)(const char* filename,struct proxy_api *api); +typedef int (*pfwps_display)(); +typedef int (*pfwps_refresh)(); + +extern class QWpsDrawer *drawer; + +class QWpsDrawer : public QWidget +{ + Q_OBJECT + + pfwps_init wps_init; + pfwps_display wps_display; + pfwps_refresh wps_refresh; + + static QImage backdrop; + +protected: + void drawBackdrop(); +public: + QWpsDrawer(char* model); + void WpsInit(QString wpsfile); + void updatepix(void); + static proxy_api api; + + static QPixmap *pix; + + + +/***********Drawing api******************/ + static void putsxy(int x, int y, const unsigned char *str); + static void transparent_bitmap_part(const void *src, int src_x, int src_y, + int stride, int x, int y, int width, int height); + static void bitmap_part(const void *src, int src_x, int src_y, + int stride, int x, int y, int width, int height); + static void drawpixel(int x, int y); + static void fillrect(int x, int y, int width, int height); + static void hline(int x1, int x2, int y); + static void vline(int x, int y1, int y2); + static void clear_viewport(int x,int y,int w,int h, int color); + static bool load_wps_backdrop(char* filename); + static int read_bmp_file(const char* filename,int *width, int *height); +/****************************************/ +}; +#endif Property changes on: screenshot/src/wpsdrawer.h ___________________________________________________________________ Name: svn:eol-style + native Index: screenshot/src/main.cpp =================================================================== --- screenshot/src/main.cpp (revision 0) +++ screenshot/src/main.cpp (revision 0) @@ -0,0 +1,78 @@ +#include +#include +#include "wpsdrawer.h" +#include "utils.h" + +static struct mp3state mp3data = +{ +"Test title", +"Test artist", +"Test album", +"Test genre", +"Test disc", +"Test track", +"Test year", +"Test composer", +"Test comment", +"Test album artist", +"Test grouping", +1, /* int discnum */ +1, /* int tracknum */ +1, /* int version */ +1, /* int layer */ +2008, /* int year */ +100, /* int length */ +70 /* int elapsed */ +}; + +static struct wpsstate wpsdata = {-20, 8, 5, 70}; + /* volume, fontheight, fontwidth, battery_level */ + +bool verbose = false; + +void usage(void) +{ + printf("Usage: screenshot [-V] \n"); + printf("Example: screenshot h10_5gb iCatcher.128x128x16.wps out.png\n"); +} + +int main(int argc, char ** argv) +{ + QApplication app( argc, argv ); + char *model, *wps, *png; + if(argc < 4) + { + usage(); + return -1; + } + + if(strcmp(argv[1], "-V") == 0) + { + verbose = true; + model = argv[2]; + wps = argv[3]; + png = argv[4]; + } + else + { + verbose = false; + model = argv[1]; + wps = argv[2]; + png = argv[3]; + } + drawer = new QWpsDrawer(model); + drawer->WpsInit(wps); + if(strcmp(drawer->api.get_model_name(), model) != 0) + { + printf("[ERR] Model name doesn't match the one supplied by the library\n"); + return -1; + } + printf("[INFO] Model: %s\n", drawer->api.get_model_name()); + drawer->api.set_wpsstate(wpsdata); + drawer->api.set_mp3state(mp3data); + drawer->updatepix(); + drawer->pix->save(png, "PNG", 100); + printf("[INFO] Image written\n"); + + return 0; +} Property changes on: screenshot/src/main.cpp ___________________________________________________________________ Name: svn:eol-style + native Index: screenshot/src/utils.h =================================================================== --- screenshot/src/utils.h (revision 0) +++ screenshot/src/utils.h (revision 0) @@ -0,0 +1,13 @@ +#ifndef __UTILS_H__ +#define __UTILS_H__ + +#include + +#define DEBUGF1 qlogger +#define DEBUGF2 if(verbose) qlogger + +extern int qlogger(const char* fmt,...); + +extern bool verbose; + +#endif // __UTILS_H__ Property changes on: screenshot/src/utils.h ___________________________________________________________________ Name: svn:eol-style + native Index: screenshot/screenshot.pro =================================================================== --- screenshot/screenshot.pro (revision 0) +++ screenshot/screenshot.pro (revision 0) @@ -0,0 +1,30 @@ +TEMPLATE = app +TARGET = +DEPENDPATH += . build src +INCLUDEPATH += . ../proxy/src +DESTDIR = bin +OBJECTS_DIR = build +MOC_DIR = build +UI_DIR = build +QMAKE_LIBDIR += lib +QT = gui core +CONFIG += qt warn_on console debug +proxy.commands = @$(MAKE) -C ../proxy shared +QMAKE_EXTRA_TARGETS += proxy +PRE_TARGETDEPS += proxy +HEADERS += src/wpsdrawer.h \ + ../proxy/src/api.h \ + ../proxy/src/defs.h \ + src/utils.h +SOURCES += src/main.cpp \ + src/wpsdrawer.cpp \ + src/utils.cpp +LIBS += -Lbin +CONFIG(debug, debug|release) +{ + TARGET = screenshotd +} +CONFIG(release, debug|release) +{ + TARGET = screenshot +} Property changes on: screenshot/screenshot.pro ___________________________________________________________________ Name: svn:eol-style + native Index: proxy/src/api.c =================================================================== --- proxy/src/api.c (revision 70) +++ proxy/src/api.c (working copy) @@ -9,6 +9,7 @@ #include "scroll_engine.h" #include "wpsstate.h" #include +#include "lcd.h" struct proxy_api *xapi; @@ -139,6 +140,14 @@ //dbgf = printf; } +#define swap16(w) ((((w)&0xffff) << 8) | (((w)&0xffff) >> 8)) +void lcd_unpack(unsigned int rgb, int *r, int *g, int *b) +{ + *r = RGB_UNPACK_RED(rgb); + *g = RGB_UNPACK_GREEN(rgb); + *b = RGB_UNPACK_BLUE(rgb); +} + /************************************************************** **************************************************************/ @@ -208,6 +217,7 @@ api->get_current_vp = get_current_vp; api->set_wpsstate = set_wpsstate; api->set_mp3state = set_mp3state; + api->lcd_unpack = lcd_unpack; xapi = api; return 0; } Index: proxy/src/api.h =================================================================== --- proxy/src/api.h (revision 70) +++ proxy/src/api.h (working copy) @@ -60,6 +60,8 @@ void (*set_wpsstate)(struct wpsstate state); void (*set_mp3state)(struct mp3state state); + void (*lcd_unpack)(unsigned int rgb, int *r, int *g, int *b); + pfdebugf debugf; int verbose;