Draft implementation of our bitmap to display format.
1.1 --- a/inc/MainWindow.h Thu May 22 21:32:45 2014 +0200
1.2 +++ b/inc/MainWindow.h Thu May 22 22:36:43 2014 +0200
1.3 @@ -123,6 +123,8 @@
1.4 FXFontDesc iCurrentFontDesc;
1.5 FXFont* iCurrentFont;
1.6 FXTGAImage* iFontImage;
1.7 + ///Used the following to convert our bitmap into display format
1.8 + unsigned char* iPixelBuffer;
1.9
1.10 struct hid_device_info *devices;
1.11 hid_device *connected_device;
2.1 --- a/src/test.cpp Thu May 22 21:32:45 2014 +0200
2.2 +++ b/src/test.cpp Thu May 22 22:36:43 2014 +0200
2.3 @@ -55,7 +55,8 @@
2.4 MainWindow::MainWindow(FXApp *app)
2.5 : FXMainWindow(app, "HIDAPI Test Application", NULL, NULL, DECOR_ALL, 200,100, 600,900),
2.6 iCurrentFont(NULL),
2.7 - iFontImage(NULL)
2.8 + iFontImage(NULL),
2.9 + iPixelBuffer(NULL)
2.10 {
2.11 iBrightness=iVfd01.MaxBrightness();
2.12 devices = NULL;
2.13 @@ -173,6 +174,9 @@
2.14 delete iFontImage;
2.15 iFontImage = NULL;
2.16
2.17 + delete[] iPixelBuffer;
2.18 + iPixelBuffer = NULL;
2.19 +
2.20 if (connected_device)
2.21 hid_close(connected_device);
2.22 hid_exit();
2.23 @@ -754,9 +758,13 @@
2.24 delete iFontImage;
2.25 iFontImage = NULL;
2.26 //
2.27 - FXString text="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-[]{}();%$£&~#|_";
2.28 + delete[] iPixelBuffer;
2.29 + iPixelBuffer=NULL;
2.30 +
2.31 + //FXString text="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-[]{}();%$£&~#|_";
2.32 + FXString text="0123456789ABCDEF";
2.33 //Create an image the proper size for our text
2.34 - iFontImage = new FXTGAImage(getApp(),NULL,IMAGE_SHMI|IMAGE_SHMP,iCurrentFont->getTextWidth(text),iCurrentFont->getFontHeight());
2.35 + iFontImage = new FXTGAImage(getApp(),NULL,IMAGE_KEEP/*IMAGE_SHMI|IMAGE_SHMP*/,iCurrentFont->getTextWidth(text),iCurrentFont->getFontHeight());
2.36 iFontImage->create();
2.37 //Perform our drawing
2.38 {
2.39 @@ -771,13 +779,39 @@
2.40 dc.drawText(0,iCurrentFont->getFontAscent(),text);
2.41 //dc.end();
2.42 }
2.43 +
2.44 + //Save to file
2.45 FXFileStream file;
2.46 file.open("fonttest.tga",FXStreamSave);
2.47 iFontImage->restore();
2.48 iFontImage->savePixels(file);
2.49 file.close();
2.50
2.51 - //
2.52 + //Create display pixel buffer from our image pixels
2.53 + int w=iFontImage->getWidth();
2.54 + int h=iFontImage->getHeight();
2.55 + int pixelBufferSize=(w*h)/8;
2.56 + iPixelBuffer = new unsigned char[pixelBufferSize];
2.57 + memset(iPixelBuffer,0x00,pixelBufferSize);
2.58 + for (int i=0;i<w;i++)
2.59 + {
2.60 + for (int j=0;j<h;j++)
2.61 + {
2.62 + int byteOffset=(i*h+j)/8;
2.63 + int bitOffset=(i*h+j)%8;
2.64 + FXColor color=iFontImage->getPixel(i,j);
2.65 + if (color!=0xffffffff)
2.66 + {
2.67 + iPixelBuffer[byteOffset] |= ( 1 << bitOffset );
2.68 + }
2.69 + }
2.70 + }
2.71 +
2.72 + if (iVfd01.IsOpen())
2.73 + {
2.74 + iVfd01.SetPixelBlock(0,0,h-1,pixelBufferSize,iPixelBuffer);
2.75 + iVfd01.SwapBuffers();
2.76 + }
2.77
2.78 }
2.79