Index: screenshot/src/wpsdrawer.cpp =================================================================== --- screenshot/src/wpsdrawer.cpp (revision 0) +++ screenshot/src/wpsdrawer.cpp (revision 0) @@ -0,0 +1,183 @@ +#include "wpsdrawer.h" +#include "utils.h" +#include +#include +#include + + +class QWpsDrawer *drawer; +QPixmap *QWpsDrawer::pix = NULL; +QImage QWpsDrawer::backdrop; +proxy_api QWpsDrawer::api; + +extern bool verbose; + +QWpsDrawer::QWpsDrawer(char* model) + : QWidget() +{ + QLibrary lib(QString("proxy_%1").arg(model)); + if(!lib.load()) + qFatal("[ERR] Cannot find proxy_%s library!", model); + if(verbose) + api.verbose = 3; + else + api.verbose = 0; + 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, true); + 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); + p.setPen(Qt::gray); + + QFont font("Times", avp.fontheight, QFont::Bold); + p.setFont(font); + 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); + p.setPen(Qt::blue); + p.drawPoint(x, y); +} + +void QWpsDrawer::fillrect(int x, int y, int width, int height) +{ + QPainter p(pix); + DEBUGF2("fillrect(int x=%d, int y=%d, int width=%d, int height=%d)\n", x, y, width, height); + p.setPen(Qt::green); + //p.setOpacity(0.05); + //QImage img = backdrop.copy(x,y,width,height); + //p.drawImage(x,y,img); +} +void QWpsDrawer::hline(int x1, int x2, int y) +{ + QPainter p(pix); + p.setPen(Qt::black); + p.drawLine(x1, y, x2, y); +} +void QWpsDrawer::vline(int x, int y1, int y2) +{ + QPainter p(pix); + p.setPen(Qt::black); + 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* buff, struct proxy_api *api, bool isfile); +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,81 @@ +#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"); + printf(" %s <-> %s\n", model, drawer->api.get_model_name()); + return -1; + } + printf("[INFO] Model: %s\n", drawer->api.get_model_name()); + drawer->api.set_wpsstate(wpsdata); + drawer->api.set_mp3state(mp3data); + drawer->api.set_next_mp3state(mp3data); + drawer->api.set_audio_status(0x0002); /* AUDIO_STATUS_PAUSE */ + 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