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); |
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; |
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); |