lib/unigraphic/GraphicsDisplay.cpp

changeset 26
86f099bda525
parent 5
f1c85c2500f2
child 45
2da50a3d4e9f
equal deleted inserted replaced
25:5b1e0b384d31 26:86f099bda525
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE. 20 * THE SOFTWARE.
21 */ 21 */
22 22
23 23
24
25 #include "GraphicsDisplay.h" 24 #include "GraphicsDisplay.h"
25
26 #define SWAP(a, b) { a ^= b; b ^= a; a ^= b; } 26 #define SWAP(a, b) { a ^= b; b ^= a; a ^= b; }
27 GraphicsDisplay::GraphicsDisplay(const char *name):TextDisplay(name) { 27 GraphicsDisplay::GraphicsDisplay(const char *name):TextDisplay(name) {
28 set_font((unsigned char*)Terminal6x8,32,127,true); 28 set_font((unsigned char*)Terminal6x8,32,127,true);
29 // foreground(0xFFFF); 29 // foreground(0xFFFF);
30 // background(0x0000); 30 // background(0x0000);
34 oriented_height=0; 34 oriented_height=0;
35 fontzoomver=1; 35 fontzoomver=1;
36 fontzoomhor=1; 36 fontzoomhor=1;
37 auto_up = true; 37 auto_up = true;
38 } 38 }
39 39
40 void GraphicsDisplay::WindowMax (void) 40 void GraphicsDisplay::WindowMax (void)
41 { 41 {
42 window (0, 0, oriented_width, oriented_height); 42 window (0, 0, oriented_width, oriented_height);
43 } 43 }
44 void GraphicsDisplay::set_width(int width) 44 void GraphicsDisplay::set_width(int width)
208 } 208 }
209 void GraphicsDisplay::fillrect(int x0, int y0, int x1, int y1, unsigned short color) 209 void GraphicsDisplay::fillrect(int x0, int y0, int x1, int y1, unsigned short color)
210 { 210 {
211 if(x0 > x1) SWAP(x0,x1); 211 if(x0 > x1) SWAP(x0,x1);
212 if(y0 > y1) SWAP(y0,y1); 212 if(y0 > y1) SWAP(y0,y1);
213 213
214 int h = y1 - y0 + 1; 214 int h = y1 - y0 + 1;
215 int w = x1 - x0 + 1; 215 int w = x1 - x0 + 1;
216 unsigned int pixels = h * w; 216 unsigned int pixels = h * w;
217 window(x0,y0,w,h); 217 window(x0,y0,w,h);
218 // for (unsigned int p=0; p<pixels; p++) window_pushpixel(color); 218 // for (unsigned int p=0; p<pixels; p++) window_pushpixel(color);
324 // int cropX; 324 // int cropX;
325 char d; 325 char d;
326 if(x<0) x=0; 326 if(x<0) x=0;
327 if(y<0) y=0; 327 if(y<0) y=0;
328 int cropX = (x+bm.xSize)-oriented_width; 328 int cropX = (x+bm.xSize)-oriented_width;
329 if(cropX<0) cropX=0; 329 if(cropX<0) cropX=0;
330 window(x, y, bm.xSize-cropX, bm.ySize); 330 window(x, y, bm.xSize-cropX, bm.ySize);
331 for(v=0; v < bm.ySize; v++) { // lines 331 for(v=0; v < bm.ySize; v++) { // lines
332 if((v + y) >= oriented_height) break; // no need to crop Y 332 if((v + y) >= oriented_height) break; // no need to crop Y
333 for(h=0; h < bm.xSize; h++) { // pixel 333 for(h=0; h < bm.xSize; h++) { // pixel
334 if((h + x) >= oriented_width) break; 334 if((h + x) >= oriented_width) break;
345 } 345 }
346 void GraphicsDisplay::Bitmap(int x, int y, int w, int h,unsigned char *bitmap) 346 void GraphicsDisplay::Bitmap(int x, int y, int w, int h,unsigned char *bitmap)
347 { 347 {
348 int j; 348 int j;
349 unsigned char padd; 349 unsigned char padd;
350 unsigned short *bitmap_ptr = (unsigned short *)bitmap; 350 unsigned short *bitmap_ptr = (unsigned short *)bitmap;
351 351
352 padd = w%2; // the lines are padded to multiple of 4 bytes in a bitmap 352 padd = w%2; // the lines are padded to multiple of 4 bytes in a bitmap
353 if(x<0) x=0; 353 if(x<0) x=0;
354 else if(x>=oriented_width) return; 354 else if(x>=oriented_width) return;
355 if(y<0) y=0; 355 if(y<0) y=0;
389 // get the filename 389 // get the filename
390 i=0; 390 i=0;
391 while (*Name_BMP!='\0') { 391 while (*Name_BMP!='\0') {
392 filename[i++]=*Name_BMP++; 392 filename[i++]=*Name_BMP++;
393 } 393 }
394 filename[i] = 0; 394 filename[i] = 0;
395 395
396 FILE *Image = fopen((const char *)&filename[0], "rb"); // open the bmp file 396 FILE *Image = fopen((const char *)&filename[0], "rb"); // open the bmp file
397 if (!Image) { 397 if (!Image) {
398 return(0); // error file not found ! 398 return(0); // error file not found !
399 } 399 }
400 400
434 window(x, y,PixelWidth ,PixelHeigh); 434 window(x, y,PixelWidth ,PixelHeigh);
435 // wr_cmd(0x2C); // send pixel 435 // wr_cmd(0x2C); // send pixel
436 for (j = PixelHeigh - 1; j >= 0; j--) { //Lines bottom up 436 for (j = PixelHeigh - 1; j >= 0; j--) { //Lines bottom up
437 off = j * (PixelWidth * 2 + padd) + start_data; // start of line 437 off = j * (PixelWidth * 2 + padd) + start_data; // start of line
438 fseek(Image, off ,SEEK_SET); 438 fseek(Image, off ,SEEK_SET);
439 fread(line,1,PixelWidth * 2,Image); // read a line - slow 439 fread(line,1,PixelWidth * 2,Image); // read a line - slow
440 /* for (i = 0; i < PixelWidth; i++) 440 /* for (i = 0; i < PixelWidth; i++)
441 { // copy pixel data to TFT 441 { // copy pixel data to TFT
442 // wr_16(line[i]); // one 16 bit pixel 442 // wr_16(line[i]); // one 16 bit pixel
443 window_pushpixel(line[i]); 443 window_pushpixel(line[i]);
444 444
445 } */ 445 } */
446 window_pushpixelbuf(line, PixelWidth); 446 window_pushpixelbuf(line, PixelWidth);
447 } 447 }
448 free (line); 448 free (line);
449 fclose(Image); 449 fclose(Image);
467 } 467 }
468 bool GraphicsDisplay::get_auto_up(void) 468 bool GraphicsDisplay::get_auto_up(void)
469 { 469 {
470 return (auto_up); 470 return (auto_up);
471 } 471 }
472
473

mercurial