summaryrefslogtreecommitdiff
path: root/apps/plugins/rockpaint.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/rockpaint.c')
-rw-r--r--apps/plugins/rockpaint.c147
1 files changed, 79 insertions, 68 deletions
diff --git a/apps/plugins/rockpaint.c b/apps/plugins/rockpaint.c
index ae28258e3b..d762737ce4 100644
--- a/apps/plugins/rockpaint.c
+++ b/apps/plugins/rockpaint.c
@@ -399,7 +399,7 @@ extern fb_data rockpaint_hsvrgb[];
399/* Maximum string size allowed for the text tool */ 399/* Maximum string size allowed for the text tool */
400#define MAX_TEXT 256 400#define MAX_TEXT 256
401 401
402static union 402typedef union
403{ 403{
404 /* Used by fill and gradient algorithms */ 404 /* Used by fill and gradient algorithms */
405 struct 405 struct
@@ -433,7 +433,9 @@ static union
433 int fw_buf[30]; 433 int fw_buf[30];
434 char fontname_buf[30][MAX_PATH]; 434 char fontname_buf[30][MAX_PATH];
435 } text; 435 } text;
436} buffer; 436} buf;
437
438static buf *buffer;
437 439
438/* Current filename */ 440/* Current filename */
439static char filename[MAX_PATH]; 441static char filename[MAX_PATH];
@@ -655,7 +657,7 @@ static bool browse( char *dst, int dst_size, const char *start )
655 struct entry *dc; 657 struct entry *dc;
656 bool reload = true; 658 bool reload = true;
657 int dirfilter = SHOW_ALL; 659 int dirfilter = SHOW_ALL;
658 int *indexes = (int *) buffer.clipboard; 660 int *indexes = (int *) buffer->clipboard;
659 661
660 char *a; 662 char *a;
661 663
@@ -795,12 +797,12 @@ static bool browse_fonts( char *dst, int dst_size )
795 int cp = 0; /* current position */ 797 int cp = 0; /* current position */
796 int fh; /* font height */ 798 int fh; /* font height */
797 799
798 #define fh_buf buffer.text.fh_buf /* 30 might not be enough ... */ 800 #define fh_buf buffer->text.fh_buf /* 30 might not be enough ... */
799 #define fw_buf buffer.text.fw_buf 801 #define fw_buf buffer->text.fw_buf
800 int fw; 802 int fw;
801 #define fontname_buf buffer.text.fontname_buf 803 #define fontname_buf buffer->text.fontname_buf
802 804
803 rb->snprintf( buffer.text.old_font, MAX_PATH, 805 rb->snprintf( buffer->text.old_font, MAX_PATH,
804 FONT_DIR "/%s.fnt", 806 FONT_DIR "/%s.fnt",
805 rb->global_settings->font_file ); 807 rb->global_settings->font_file );
806 808
@@ -892,7 +894,7 @@ static bool browse_fonts( char *dst, int dst_size )
892 nvih = fh; 894 nvih = fh;
893 } 895 }
894 } 896 }
895 rb->font_load(NULL, buffer.text.old_font ); 897 rb->font_load(NULL, buffer->text.old_font );
896 rb->closedir( d ); 898 rb->closedir( d );
897 } 899 }
898 900
@@ -1285,7 +1287,7 @@ static void draw_select_rectangle( int x1, int y1, int x2, int y2 )
1285static void copy_to_clipboard( void ) 1287static void copy_to_clipboard( void )
1286{ 1288{
1287 /* This needs to be optimised ... but i'm lazy ATM */ 1289 /* This needs to be optimised ... but i'm lazy ATM */
1288 rb->memcpy( buffer.clipboard, save_buffer, COLS*ROWS*sizeof( fb_data ) ); 1290 rb->memcpy( buffer->clipboard, save_buffer, COLS*ROWS*sizeof( fb_data ) );
1289} 1291}
1290 1292
1291/* no preview mode handling atm ... do we need it ? (one if) */ 1293/* no preview mode handling atm ... do we need it ? (one if) */
@@ -1340,7 +1342,7 @@ static void draw_hflip( int x1, int y1, int x2, int y2 )
1340 for( i = 0; i <= y2 - y1; i++ ) 1342 for( i = 0; i <= y2 - y1; i++ )
1341 { 1343 {
1342 rb->memcpy( save_buffer+(y1+i)*COLS+x1, 1344 rb->memcpy( save_buffer+(y1+i)*COLS+x1,
1343 buffer.clipboard+(y2-i)*COLS+x1, 1345 buffer->clipboard+(y2-i)*COLS+x1,
1344 (x2-x1+1)*sizeof( fb_data ) ); 1346 (x2-x1+1)*sizeof( fb_data ) );
1345 } 1347 }
1346 restore_screen(); 1348 restore_screen();
@@ -1369,7 +1371,7 @@ static void draw_vflip( int x1, int y1, int x2, int y2 )
1369 { 1371 {
1370 for( i = 0; i <= x2 - x1; i++ ) 1372 for( i = 0; i <= x2 - x1; i++ )
1371 { 1373 {
1372 save_buffer[y1*COLS+x1+i] = buffer.clipboard[y1*COLS+x2-i]; 1374 save_buffer[y1*COLS+x1+i] = buffer->clipboard[y1*COLS+x2-i];
1373 } 1375 }
1374 } 1376 }
1375 restore_screen(); 1377 restore_screen();
@@ -1437,7 +1439,7 @@ static void draw_rot_90_deg( int x1, int y1, int x2, int y2, int direction )
1437 x = x1+width-j; 1439 x = x1+width-j;
1438 y = y1+i; 1440 y = y1+i;
1439 } 1441 }
1440 save_buffer[(y3+j)*COLS+x3+i] = buffer.clipboard[y*COLS+x]; 1442 save_buffer[(y3+j)*COLS+x3+i] = buffer->clipboard[y*COLS+x];
1441 } 1443 }
1442 } 1444 }
1443 restore_screen(); 1445 restore_screen();
@@ -1475,14 +1477,14 @@ static void draw_paste_rectangle( int src_x1, int src_y1, int src_x2,
1475 if( y1 + height > ROWS ) 1477 if( y1 + height > ROWS )
1476 height = ROWS - y1; 1478 height = ROWS - y1;
1477 1479
1478 rb->lcd_bitmap_part( buffer.clipboard, src_x1, src_y1, COLS, 1480 rb->lcd_bitmap_part( buffer->clipboard, src_x1, src_y1, COLS,
1479 x1, y1, width, height ); 1481 x1, y1, width, height );
1480 if( !preview ) 1482 if( !preview )
1481 { 1483 {
1482 for( i = 0; i < height; i++ ) 1484 for( i = 0; i < height; i++ )
1483 { 1485 {
1484 rb->memcpy( save_buffer+(y1+i)*COLS+x1, 1486 rb->memcpy( save_buffer+(y1+i)*COLS+x1,
1485 buffer.clipboard+(src_y1+i)*COLS+src_x1, 1487 buffer->clipboard+(src_y1+i)*COLS+src_x1,
1486 width*sizeof( fb_data ) ); 1488 width*sizeof( fb_data ) );
1487 } 1489 }
1488 } 1490 }
@@ -1510,8 +1512,8 @@ static void show_grid( bool update )
1510static void draw_text( int x, int y ) 1512static void draw_text( int x, int y )
1511{ 1513{
1512 int selected = 0; 1514 int selected = 0;
1513 buffer.text.text[0] = '\0'; 1515 buffer->text.text[0] = '\0';
1514 rb->snprintf( buffer.text.old_font, MAX_PATH, 1516 rb->snprintf( buffer->text.old_font, MAX_PATH,
1515 FONT_DIR "/%s.fnt", 1517 FONT_DIR "/%s.fnt",
1516 rb->global_settings->font_file ); 1518 rb->global_settings->font_file );
1517 while( 1 ) 1519 while( 1 )
@@ -1520,13 +1522,13 @@ static void draw_text( int x, int y )
1520 { 1522 {
1521 case TEXT_MENU_TEXT: 1523 case TEXT_MENU_TEXT:
1522 rb->lcd_set_foreground(COLOR_BLACK); 1524 rb->lcd_set_foreground(COLOR_BLACK);
1523 rb->kbd_input( buffer.text.text, MAX_TEXT ); 1525 rb->kbd_input( buffer->text.text, MAX_TEXT );
1524 break; 1526 break;
1525 1527
1526 case TEXT_MENU_FONT: 1528 case TEXT_MENU_FONT:
1527 if( browse_fonts( buffer.text.font, MAX_PATH ) ) 1529 if( browse_fonts( buffer->text.font, MAX_PATH ) )
1528 { 1530 {
1529 rb->font_load(NULL, buffer.text.font ); 1531 rb->font_load(NULL, buffer->text.font );
1530 } 1532 }
1531 break; 1533 break;
1532 1534
@@ -1536,7 +1538,7 @@ static void draw_text( int x, int y )
1536 { 1538 {
1537 int button; 1539 int button;
1538 restore_screen(); 1540 restore_screen();
1539 rb->lcd_putsxy( x, y, buffer.text.text ); 1541 rb->lcd_putsxy( x, y, buffer->text.text );
1540 rb->lcd_update(); 1542 rb->lcd_update();
1541 switch( button = rb->button_get( true ) ) 1543 switch( button = rb->button_get( true ) )
1542 { 1544 {
@@ -1579,11 +1581,11 @@ static void draw_text( int x, int y )
1579 case TEXT_MENU_APPLY: 1581 case TEXT_MENU_APPLY:
1580 rb->lcd_set_foreground( rp_colors[ drawcolor ] ); 1582 rb->lcd_set_foreground( rp_colors[ drawcolor ] );
1581 buffer_putsxyofs( save_buffer, COLS, ROWS, x, y, 0, 1583 buffer_putsxyofs( save_buffer, COLS, ROWS, x, y, 0,
1582 buffer.text.text ); 1584 buffer->text.text );
1583 case TEXT_MENU_CANCEL: 1585 case TEXT_MENU_CANCEL:
1584 default: 1586 default:
1585 restore_screen(); 1587 restore_screen();
1586 rb->font_load(NULL, buffer.text.old_font ); 1588 rb->font_load(NULL, buffer->text.old_font );
1587 return; 1589 return;
1588 } 1590 }
1589 } 1591 }
@@ -1699,23 +1701,23 @@ static void draw_curve( int x1, int y1, int x2, int y2,
1699 * This will currently only be used in preview mode */ 1701 * This will currently only be used in preview mode */
1700 { 1702 {
1701#define PUSH( a1, b1, a2, b2, a3, b3, d ) \ 1703#define PUSH( a1, b1, a2, b2, a3, b3, d ) \
1702 buffer.bezier[i].x1 = a1; \ 1704 buffer->bezier[i].x1 = a1; \
1703 buffer.bezier[i].y1 = b1; \ 1705 buffer->bezier[i].y1 = b1; \
1704 buffer.bezier[i].x2 = a2; \ 1706 buffer->bezier[i].x2 = a2; \
1705 buffer.bezier[i].y2 = b2; \ 1707 buffer->bezier[i].y2 = b2; \
1706 buffer.bezier[i].x3 = a3; \ 1708 buffer->bezier[i].x3 = a3; \
1707 buffer.bezier[i].y3 = b3; \ 1709 buffer->bezier[i].y3 = b3; \
1708 buffer.bezier[i].depth = d; \ 1710 buffer->bezier[i].depth = d; \
1709 i++; 1711 i++;
1710#define POP( a1, b1, a2, b2, a3, b3, d ) \ 1712#define POP( a1, b1, a2, b2, a3, b3, d ) \
1711 i--; \ 1713 i--; \
1712 a1 = buffer.bezier[i].x1; \ 1714 a1 = buffer->bezier[i].x1; \
1713 b1 = buffer.bezier[i].y1; \ 1715 b1 = buffer->bezier[i].y1; \
1714 a2 = buffer.bezier[i].x2; \ 1716 a2 = buffer->bezier[i].x2; \
1715 b2 = buffer.bezier[i].y2; \ 1717 b2 = buffer->bezier[i].y2; \
1716 a3 = buffer.bezier[i].x3; \ 1718 a3 = buffer->bezier[i].x3; \
1717 b3 = buffer.bezier[i].y3; \ 1719 b3 = buffer->bezier[i].y3; \
1718 d = buffer.bezier[i].depth; 1720 d = buffer->bezier[i].depth;
1719 PUSH( x1<<4, y1<<4, xb<<4, yb<<4, x2<<4, y2<<4, 0 ); 1721 PUSH( x1<<4, y1<<4, xb<<4, yb<<4, x2<<4, y2<<4, 0 );
1720 while( i ) 1722 while( i )
1721 { 1723 {
@@ -1746,27 +1748,27 @@ static void draw_curve( int x1, int y1, int x2, int y2,
1746 else /* We have the 4 points */ 1748 else /* We have the 4 points */
1747 { 1749 {
1748#define PUSH( a1, b1, a2, b2, a3, b3, a4, b4, d ) \ 1750#define PUSH( a1, b1, a2, b2, a3, b3, a4, b4, d ) \
1749 buffer.bezier[i].x1 = a1; \ 1751 buffer->bezier[i].x1 = a1; \
1750 buffer.bezier[i].y1 = b1; \ 1752 buffer->bezier[i].y1 = b1; \
1751 buffer.bezier[i].x2 = a2; \ 1753 buffer->bezier[i].x2 = a2; \
1752 buffer.bezier[i].y2 = b2; \ 1754 buffer->bezier[i].y2 = b2; \
1753 buffer.bezier[i].x3 = a3; \ 1755 buffer->bezier[i].x3 = a3; \
1754 buffer.bezier[i].y3 = b3; \ 1756 buffer->bezier[i].y3 = b3; \
1755 buffer.bezier[i].x4 = a4; \ 1757 buffer->bezier[i].x4 = a4; \
1756 buffer.bezier[i].y4 = b4; \ 1758 buffer->bezier[i].y4 = b4; \
1757 buffer.bezier[i].depth = d; \ 1759 buffer->bezier[i].depth = d; \
1758 i++; 1760 i++;
1759#define POP( a1, b1, a2, b2, a3, b3, a4, b4, d ) \ 1761#define POP( a1, b1, a2, b2, a3, b3, a4, b4, d ) \
1760 i--; \ 1762 i--; \
1761 a1 = buffer.bezier[i].x1; \ 1763 a1 = buffer->bezier[i].x1; \
1762 b1 = buffer.bezier[i].y1; \ 1764 b1 = buffer->bezier[i].y1; \
1763 a2 = buffer.bezier[i].x2; \ 1765 a2 = buffer->bezier[i].x2; \
1764 b2 = buffer.bezier[i].y2; \ 1766 b2 = buffer->bezier[i].y2; \
1765 a3 = buffer.bezier[i].x3; \ 1767 a3 = buffer->bezier[i].x3; \
1766 b3 = buffer.bezier[i].y3; \ 1768 b3 = buffer->bezier[i].y3; \
1767 a4 = buffer.bezier[i].x4; \ 1769 a4 = buffer->bezier[i].x4; \
1768 b4 = buffer.bezier[i].y4; \ 1770 b4 = buffer->bezier[i].y4; \
1769 d = buffer.bezier[i].depth; 1771 d = buffer->bezier[i].depth;
1770 1772
1771 PUSH( x1<<4, y1<<4, xa<<4, ya<<4, xb<<4, yb<<4, x2<<4, y2<<4, 0 ); 1773 PUSH( x1<<4, y1<<4, xa<<4, ya<<4, xb<<4, yb<<4, x2<<4, y2<<4, 0 );
1772 while( i ) 1774 while( i )
@@ -1932,13 +1934,13 @@ static void draw_fill( int x0, int y0 )
1932{ 1934{
1933#define PUSH( a, b ) \ 1935#define PUSH( a, b ) \
1934 draw_pixel( (int)a, (int)b ); \ 1936 draw_pixel( (int)a, (int)b ); \
1935 buffer.coord[i].x = a; \ 1937 buffer->coord[i].x = a; \
1936 buffer.coord[i].y = b; \ 1938 buffer->coord[i].y = b; \
1937 i++; 1939 i++;
1938#define POP( a, b ) \ 1940#define POP( a, b ) \
1939 i--; \ 1941 i--; \
1940 a = buffer.coord[i].x; \ 1942 a = buffer->coord[i].x; \
1941 b = buffer.coord[i].y; 1943 b = buffer->coord[i].y;
1942 1944
1943 unsigned int i=0; 1945 unsigned int i=0;
1944 short x = x0; 1946 short x = x0;
@@ -2125,13 +2127,13 @@ static void linear_gradient( int x1, int y1, int x2, int y2 )
2125 rgb2hsv( r2, g2, b2, &h2, &s2, &v2 ); 2127 rgb2hsv( r2, g2, b2, &h2, &s2, &v2 );
2126 2128
2127#define PUSH( x0, y0 ) \ 2129#define PUSH( x0, y0 ) \
2128 buffer.coord[i].x = (short)(x0); \ 2130 buffer->coord[i].x = (short)(x0); \
2129 buffer.coord[i].y = (short)(y0); \ 2131 buffer->coord[i].y = (short)(y0); \
2130 i++; 2132 i++;
2131#define POP( a, b ) \ 2133#define POP( a, b ) \
2132 i--; \ 2134 i--; \
2133 a = (int)buffer.coord[i].x; \ 2135 a = (int)buffer->coord[i].x; \
2134 b = (int)buffer.coord[i].y; 2136 b = (int)buffer->coord[i].y;
2135 2137
2136 PUSH( x, y ); 2138 PUSH( x, y );
2137 2139
@@ -2221,13 +2223,13 @@ static void radial_gradient( int x1, int y1, int x2, int y2 )
2221 rgb2hsv( r2, g2, b2, &h2, &s2, &v2 ); 2223 rgb2hsv( r2, g2, b2, &h2, &s2, &v2 );
2222 2224
2223#define PUSH( x0, y0 ) \ 2225#define PUSH( x0, y0 ) \
2224 buffer.coord[i].x = (short)(x0); \ 2226 buffer->coord[i].x = (short)(x0); \
2225 buffer.coord[i].y = (short)(y0); \ 2227 buffer->coord[i].y = (short)(y0); \
2226 i++; 2228 i++;
2227#define POP( a, b ) \ 2229#define POP( a, b ) \
2228 i--; \ 2230 i--; \
2229 a = (int)buffer.coord[i].x; \ 2231 a = (int)buffer->coord[i].x; \
2230 b = (int)buffer.coord[i].y; 2232 b = (int)buffer->coord[i].y;
2231 2233
2232 PUSH( x, y ); 2234 PUSH( x, y );
2233 2235
@@ -3016,10 +3018,10 @@ static int save_bitmap( char *file )
3016 int i; 3018 int i;
3017 for(i = 0; i < img_height; i++) 3019 for(i = 0; i < img_height; i++)
3018 { 3020 {
3019 rb->memcpy( buffer.clipboard+i*img_width, save_buffer+i*COLS, 3021 rb->memcpy( buffer->clipboard+i*img_width, save_buffer+i*COLS,
3020 sizeof( fb_data )*img_width ); 3022 sizeof( fb_data )*img_width );
3021 } 3023 }
3022 bm.data = (char*)buffer.clipboard; 3024 bm.data = (char*)buffer->clipboard;
3023 bm.height = img_height; 3025 bm.height = img_height;
3024 bm.width = img_width; 3026 bm.width = img_width;
3025 bm.format = FORMAT_NATIVE; 3027 bm.format = FORMAT_NATIVE;
@@ -3028,6 +3030,15 @@ static int save_bitmap( char *file )
3028 3030
3029enum plugin_status plugin_start(const void* parameter) 3031enum plugin_status plugin_start(const void* parameter)
3030{ 3032{
3033 size_t buffer_size;
3034 buffer = (buf*)
3035 (((uintptr_t)rb->plugin_get_audio_buffer(&buffer_size) + 3) & ~3);
3036 if (buffer_size < sizeof(*buffer) + 3)
3037 {
3038 rb->splash(HZ, "Not enough memory");
3039 return PLUGIN_ERROR;
3040 }
3041
3031 rb->lcd_set_foreground(COLOR_WHITE); 3042 rb->lcd_set_foreground(COLOR_WHITE);
3032 rb->lcd_set_backdrop(NULL); 3043 rb->lcd_set_backdrop(NULL);
3033 rb->lcd_fillrect(0,0,LCD_WIDTH,LCD_HEIGHT); 3044 rb->lcd_fillrect(0,0,LCD_WIDTH,LCD_HEIGHT);