diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugins/grayscale.c | 176 |
1 files changed, 102 insertions, 74 deletions
diff --git a/apps/plugins/grayscale.c b/apps/plugins/grayscale.c index 2a425852d6..fe50a5226e 100644 --- a/apps/plugins/grayscale.c +++ b/apps/plugins/grayscale.c | |||
@@ -334,7 +334,9 @@ int gray_init_buffer(unsigned char *gbuf, int gbuf_size, int width, | |||
334 | int possible_depth, plane_size; | 334 | int possible_depth, plane_size; |
335 | int i, j; | 335 | int i, j; |
336 | 336 | ||
337 | if (width > LCD_WIDTH || bheight > (LCD_HEIGHT >> 3) || depth < 1) | 337 | if ((unsigned) width > LCD_WIDTH |
338 | || (unsigned) bheight > (LCD_HEIGHT >> 3) | ||
339 | || depth < 1) | ||
338 | return 0; | 340 | return 0; |
339 | 341 | ||
340 | while ((unsigned long)gbuf & 3) /* the buffer has to be long aligned */ | 342 | while ((unsigned long)gbuf & 3) /* the buffer has to be long aligned */ |
@@ -569,7 +571,7 @@ void gray_scroll_left(int count, bool black_border) | |||
569 | unsigned char *src, *dest; | 571 | unsigned char *src, *dest; |
570 | unsigned char filler; | 572 | unsigned char filler; |
571 | 573 | ||
572 | if (graybuf == NULL || count >= graybuf->width) | 574 | if (graybuf == NULL || (unsigned) count >= (unsigned) graybuf->width) |
573 | return; | 575 | return; |
574 | 576 | ||
575 | if (black_border) | 577 | if (black_border) |
@@ -606,7 +608,7 @@ void gray_scroll_right(int count, bool black_border) | |||
606 | unsigned char *src, *dest; | 608 | unsigned char *src, *dest; |
607 | unsigned char filler; | 609 | unsigned char filler; |
608 | 610 | ||
609 | if (graybuf == NULL || count >= graybuf->width) | 611 | if (graybuf == NULL || (unsigned) count >= (unsigned) graybuf->width) |
610 | return; | 612 | return; |
611 | 613 | ||
612 | if (black_border) | 614 | if (black_border) |
@@ -850,8 +852,10 @@ void gray_scroll_down1(bool black_border) | |||
850 | */ | 852 | */ |
851 | void gray_drawpixel(int x, int y, int brightness) | 853 | void gray_drawpixel(int x, int y, int brightness) |
852 | { | 854 | { |
853 | if (graybuf == NULL || x >= graybuf->width || y >= graybuf->height | 855 | if (graybuf == NULL |
854 | || brightness > 255) | 856 | || (unsigned) x >= (unsigned) graybuf->width |
857 | || (unsigned) y >= (unsigned) graybuf->height | ||
858 | || (unsigned) brightness > 255) | ||
855 | return; | 859 | return; |
856 | 860 | ||
857 | graypixel(x, y, graybuf->bitpattern[(brightness | 861 | graypixel(x, y, graybuf->bitpattern[(brightness |
@@ -865,7 +869,9 @@ void gray_drawpixel(int x, int y, int brightness) | |||
865 | */ | 869 | */ |
866 | void gray_invertpixel(int x, int y) | 870 | void gray_invertpixel(int x, int y) |
867 | { | 871 | { |
868 | if (graybuf == NULL || x >= graybuf->width || y >= graybuf->height) | 872 | if (graybuf == NULL |
873 | || (unsigned) x >= (unsigned) graybuf->width | ||
874 | || (unsigned) y >= (unsigned) graybuf->height) | ||
869 | return; | 875 | return; |
870 | 876 | ||
871 | grayinvertmasked(x, (y >> 3), 1 << (y & 7)); | 877 | grayinvertmasked(x, (y >> 3), 1 << (y & 7)); |
@@ -885,8 +891,12 @@ void gray_drawline(int x1, int y1, int x2, int y2, int brightness) | |||
885 | int y, yinc1, yinc2; | 891 | int y, yinc1, yinc2; |
886 | unsigned long pattern; | 892 | unsigned long pattern; |
887 | 893 | ||
888 | if (graybuf == NULL || x1 >= graybuf->width || y1 >= graybuf->height | 894 | if (graybuf == NULL |
889 | || x2 >= graybuf->width || y2 >= graybuf->height|| brightness > 255) | 895 | || (unsigned) x1 >= (unsigned) graybuf->width |
896 | || (unsigned) y1 >= (unsigned) graybuf->height | ||
897 | || (unsigned) x2 >= (unsigned) graybuf->width | ||
898 | || (unsigned) y2 >= (unsigned) graybuf->height | ||
899 | || (unsigned) brightness > 255) | ||
890 | return; | 900 | return; |
891 | 901 | ||
892 | pattern = graybuf->bitpattern[(brightness * (graybuf->depth + 1)) >> 8]; | 902 | pattern = graybuf->bitpattern[(brightness * (graybuf->depth + 1)) >> 8]; |
@@ -966,8 +976,11 @@ void gray_invertline(int x1, int y1, int x2, int y2) | |||
966 | int x, xinc1, xinc2; | 976 | int x, xinc1, xinc2; |
967 | int y, yinc1, yinc2; | 977 | int y, yinc1, yinc2; |
968 | 978 | ||
969 | if (graybuf == NULL || x1 >= graybuf->width || y1 >= graybuf->height | 979 | if (graybuf == NULL |
970 | || x2 >= graybuf->width || y2 >= graybuf->height) | 980 | || (unsigned) x1 >= (unsigned) graybuf->width |
981 | || (unsigned) y1 >= (unsigned) graybuf->height | ||
982 | || (unsigned) x2 >= (unsigned) graybuf->width | ||
983 | || (unsigned) y2 >= (unsigned) graybuf->height) | ||
971 | return; | 984 | return; |
972 | 985 | ||
973 | deltax = abs(x2 - x1); | 986 | deltax = abs(x2 - x1); |
@@ -1041,8 +1054,12 @@ void gray_drawrect(int x1, int y1, int x2, int y2, int brightness) | |||
1041 | int x, y; | 1054 | int x, y; |
1042 | unsigned long pattern; | 1055 | unsigned long pattern; |
1043 | 1056 | ||
1044 | if (graybuf == NULL || x1 >= graybuf->width || y1 >= graybuf->height | 1057 | if (graybuf == NULL |
1045 | || x2 >= graybuf->width || y2 >= graybuf->height|| brightness > 255) | 1058 | || (unsigned) x1 >= (unsigned) graybuf->width |
1059 | || (unsigned) y1 >= (unsigned) graybuf->height | ||
1060 | || (unsigned) x2 >= (unsigned) graybuf->width | ||
1061 | || (unsigned) y2 >= (unsigned) graybuf->height | ||
1062 | || (unsigned) brightness > 255) | ||
1046 | return; | 1063 | return; |
1047 | 1064 | ||
1048 | pattern = graybuf->bitpattern[(brightness * (graybuf->depth + 1)) >> 8]; | 1065 | pattern = graybuf->bitpattern[(brightness * (graybuf->depth + 1)) >> 8]; |
@@ -1082,8 +1099,12 @@ void gray_fillrect(int x1, int y1, int x2, int y2, int brightness) | |||
1082 | int x, y; | 1099 | int x, y; |
1083 | unsigned long pattern; | 1100 | unsigned long pattern; |
1084 | 1101 | ||
1085 | if (graybuf == NULL || x1 >= graybuf->width || y1 >= graybuf->height | 1102 | if (graybuf == NULL |
1086 | || x2 >= graybuf->width || y2 >= graybuf->height || brightness > 255) | 1103 | || (unsigned) x1 >= (unsigned) graybuf->width |
1104 | || (unsigned) y1 >= (unsigned) graybuf->height | ||
1105 | || (unsigned) x2 >= (unsigned) graybuf->width | ||
1106 | || (unsigned) y2 >= (unsigned) graybuf->height | ||
1107 | || (unsigned) brightness > 255) | ||
1087 | return; | 1108 | return; |
1088 | 1109 | ||
1089 | if (y1 > y2) | 1110 | if (y1 > y2) |
@@ -1121,8 +1142,11 @@ void gray_invertrect(int x1, int y1, int x2, int y2) | |||
1121 | int x, yb, yb1, yb2; | 1142 | int x, yb, yb1, yb2; |
1122 | unsigned char mask; | 1143 | unsigned char mask; |
1123 | 1144 | ||
1124 | if (graybuf == NULL || x1 >= graybuf->width || y1 >= graybuf->height | 1145 | if (graybuf == NULL |
1125 | || x2 >= graybuf->width || y2 >= graybuf->height) | 1146 | || (unsigned) x1 >= (unsigned) graybuf->width |
1147 | || (unsigned) y1 >= (unsigned) graybuf->height | ||
1148 | || (unsigned) x2 >= (unsigned) graybuf->width | ||
1149 | || (unsigned) y2 >= (unsigned) graybuf->height) | ||
1126 | return; | 1150 | return; |
1127 | 1151 | ||
1128 | if (y1 > y2) | 1152 | if (y1 > y2) |
@@ -1174,7 +1198,7 @@ void gray_invertrect(int x1, int y1, int x2, int y2) | |||
1174 | * A grayscale bitmap contains one byte for every pixel that defines the | 1198 | * A grayscale bitmap contains one byte for every pixel that defines the |
1175 | * brightness of the pixel (0..255). Bytes are read in row-major order. | 1199 | * brightness of the pixel (0..255). Bytes are read in row-major order. |
1176 | * The <stride> parameter is useful if you want to show only a part of a | 1200 | * The <stride> parameter is useful if you want to show only a part of a |
1177 | * bitmap. It should always be set to the "line length" of the bitmap, so | 1201 | * bitmap. It should always be set to the "row length" of the bitmap, so |
1178 | * for displaying the whole bitmap, nx == stride. | 1202 | * for displaying the whole bitmap, nx == stride. |
1179 | */ | 1203 | */ |
1180 | void gray_drawgraymap(unsigned char *src, int x, int y, int nx, int ny, | 1204 | void gray_drawgraymap(unsigned char *src, int x, int y, int nx, int ny, |
@@ -1183,7 +1207,9 @@ void gray_drawgraymap(unsigned char *src, int x, int y, int nx, int ny, | |||
1183 | int xi, yi; | 1207 | int xi, yi; |
1184 | unsigned char *row; | 1208 | unsigned char *row; |
1185 | 1209 | ||
1186 | if (graybuf == NULL || x >= graybuf->width || y >= graybuf->height) | 1210 | if (graybuf == NULL |
1211 | || (unsigned) x >= (unsigned) graybuf->width | ||
1212 | || (unsigned) y >= (unsigned) graybuf->height) | ||
1187 | return; | 1213 | return; |
1188 | 1214 | ||
1189 | if ((y + ny) >= graybuf->height) /* clip bottom */ | 1215 | if ((y + ny) >= graybuf->height) /* clip bottom */ |
@@ -1206,14 +1232,19 @@ void gray_drawgraymap(unsigned char *src, int x, int y, int nx, int ny, | |||
1206 | 1232 | ||
1207 | /* Display a bitmap with specific foreground and background gray values | 1233 | /* Display a bitmap with specific foreground and background gray values |
1208 | * | 1234 | * |
1235 | * This (now) uses the same bitmap format as the core b&w graphics routines, | ||
1236 | * so you can use bmp2rb to generate bitmaps for use with this function as | ||
1237 | * well. | ||
1238 | * | ||
1209 | * A bitmap contains one bit for every pixel that defines if that pixel is | 1239 | * A bitmap contains one bit for every pixel that defines if that pixel is |
1210 | * foreground (1) or background (0). Bytes are read in row-major order, MSB | 1240 | * foreground (1) or background (0). Bits within a byte are arranged |
1211 | * first. A row consists of an integer number of bytes, extra bits past the | 1241 | * vertically, LSB at top. |
1212 | * right margin are ignored. | 1242 | * The bytes are stored in row-major order, with byte 0 being top left, |
1243 | * byte 1 2nd from left etc. The first row of bytes defines pixel rows | ||
1244 | * 0..7, the second row defines pixel row 8..15 etc. | ||
1245 | * | ||
1213 | * The <stride> parameter is useful if you want to show only a part of a | 1246 | * The <stride> parameter is useful if you want to show only a part of a |
1214 | * bitmap. It should always be set to the "line length" of the bitmap. | 1247 | * bitmap. It should always be set to the "row length" of the bitmap. |
1215 | * Beware that this is counted in bytes, so nx == 8 * stride for the whole | ||
1216 | * bitmap. | ||
1217 | * | 1248 | * |
1218 | * If draw_bg is false, only foreground pixels are drawn, so the background | 1249 | * If draw_bg is false, only foreground pixels are drawn, so the background |
1219 | * is transparent. In this case bg_brightness is ignored. | 1250 | * is transparent. In this case bg_brightness is ignored. |
@@ -1222,15 +1253,18 @@ void gray_drawbitmap(unsigned char *src, int x, int y, int nx, int ny, | |||
1222 | int stride, bool draw_bg, int fg_brightness, | 1253 | int stride, bool draw_bg, int fg_brightness, |
1223 | int bg_brightness) | 1254 | int bg_brightness) |
1224 | { | 1255 | { |
1225 | int xi, yi, i; | 1256 | int xi, dy; |
1257 | int bits = 0; /* Have to initialize to prevent warning */ | ||
1226 | unsigned long fg_pattern, bg_pattern; | 1258 | unsigned long fg_pattern, bg_pattern; |
1227 | unsigned long bits = 0; /* Have to initialize to prevent warning */ | 1259 | unsigned char *col; |
1228 | unsigned char *row; | ||
1229 | 1260 | ||
1230 | if (graybuf == NULL || x >= graybuf->width || y >= graybuf->height | 1261 | if (graybuf == NULL |
1231 | || fg_brightness > 255 || bg_brightness > 255) | 1262 | || (unsigned) x >= (unsigned) graybuf->width |
1263 | || (unsigned) y >= (unsigned) graybuf->height | ||
1264 | || (unsigned) fg_brightness > 255 | ||
1265 | || (unsigned) bg_brightness > 255) | ||
1232 | return; | 1266 | return; |
1233 | 1267 | ||
1234 | if ((y + ny) >= graybuf->height) /* clip bottom */ | 1268 | if ((y + ny) >= graybuf->height) /* clip bottom */ |
1235 | ny = graybuf->height - y; | 1269 | ny = graybuf->height - y; |
1236 | 1270 | ||
@@ -1243,25 +1277,24 @@ void gray_drawbitmap(unsigned char *src, int x, int y, int nx, int ny, | |||
1243 | bg_pattern = graybuf->bitpattern[(bg_brightness | 1277 | bg_pattern = graybuf->bitpattern[(bg_brightness |
1244 | * (graybuf->depth + 1)) >> 8]; | 1278 | * (graybuf->depth + 1)) >> 8]; |
1245 | 1279 | ||
1246 | for (yi = y; yi < y + ny; yi++) | 1280 | for (xi = x; xi < x + nx; xi++) |
1247 | { | 1281 | { |
1248 | i = 0; | 1282 | col = src++; |
1249 | row = src; | 1283 | for (dy = 0; dy < ny; dy++) |
1250 | src += stride; | ||
1251 | for (xi = x; xi < x + nx; xi++) | ||
1252 | { | 1284 | { |
1253 | if (i == 0) /* get next 8 bits */ | 1285 | if (!(dy & 7)) /* get next 8 bits */ |
1254 | bits = (unsigned long)(*row++); | 1286 | { |
1255 | 1287 | bits = (int)(*col); | |
1256 | if (bits & 0x80) | 1288 | col += stride; |
1257 | graypixel(xi, yi, fg_pattern); | 1289 | } |
1290 | |||
1291 | if (bits & 0x01) | ||
1292 | graypixel(xi, y + dy, fg_pattern); | ||
1258 | else | 1293 | else |
1259 | if (draw_bg) | 1294 | if (draw_bg) |
1260 | graypixel(xi, yi, bg_pattern); | 1295 | graypixel(xi, y + dy, bg_pattern); |
1261 | 1296 | ||
1262 | bits <<= 1; | 1297 | bits >>= 1; |
1263 | i++; | ||
1264 | i &= 7; | ||
1265 | } | 1298 | } |
1266 | } | 1299 | } |
1267 | } | 1300 | } |
@@ -1279,41 +1312,36 @@ int main(void) | |||
1279 | bool black_border; | 1312 | bool black_border; |
1280 | 1313 | ||
1281 | static unsigned char rockbox[] = { | 1314 | static unsigned char rockbox[] = { |
1282 | /* .... .... .... .... .... .... .... .... .... .... ... | 1315 | /* ........................................... |
1283 | * .### #... ###. ..## #..# ...# .### #... ###. .#.. .#. | 1316 | * .####...###...###..#...#.####...###..#...#. |
1284 | * .#.. .#.# ...# .#.. .#.# ..#. .#.. .#.# ...# ..#. #.. | 1317 | * .#...#.#...#.#...#.#..#..#...#.#...#..#.#.. |
1285 | * .### #..# ...# .#.. ...# ##.. .### #..# ...# ...# ... | 1318 | * .####..#...#.#.....###...####..#...#...#... |
1286 | * .#.. #..# ...# .#.. .#.# ..#. .#.. .#.# ...# ..#. #.. | 1319 | * .#..#..#...#.#...#.#..#..#...#.#...#..#.#.. |
1287 | * .#.. .#.. ###. ..## #..# ...# .### #... ###. .#.. .#. | 1320 | * .#...#..###...###..#...#.####...###..#...#. |
1288 | * .... .... .... .... .... .... .... .... .... .... ... | 1321 | * ........................................... |
1289 | * 43 x 7 pixel, 1 bpp | 1322 | * 43 x 7 pixel, 1 bpp |
1290 | */ | 1323 | */ |
1291 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1324 | 0x00, 0x3E, 0x0A, 0x0A, 0x1A, 0x24, 0x00, 0x1C, 0x22, 0x22, |
1292 | 0x78, 0xE3, 0x91, 0x78, 0xE4, 0x40, | 1325 | 0x22, 0x1C, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x14, 0x00, 0x3E, |
1293 | 0x45, 0x14, 0x52, 0x45, 0x12, 0x80, | 1326 | 0x08, 0x08, 0x14, 0x22, 0x00, 0x3E, 0x2A, 0x2A, 0x2A, 0x14, |
1294 | 0x79, 0x14, 0x1C, 0x79, 0x11, 0x00, | 1327 | 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x22, 0x14, 0x08, |
1295 | 0x49, 0x14, 0x52, 0x45, 0x12, 0x80, | 1328 | 0x14, 0x22, 0x00 |
1296 | 0x44, 0xE3, 0x91, 0x78, 0xE4, 0x40, | ||
1297 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
1298 | }; | 1329 | }; |
1299 | 1330 | ||
1300 | static unsigned char showing[] = { | 1331 | static unsigned char showing[] = { |
1301 | /* .... .... .... .... .... .... .... .... .... ... | 1332 | /* ....................................... |
1302 | * ..## ##.# ...# ..## #..# ...# .#.# ...# ..## ##. | 1333 | * ..####.#...#..###..#...#.#.#...#..####. |
1303 | * .#.. ...# ...# .#.. .#.# ...# .#.# #..# .#.. ... | 1334 | * .#.....#...#.#...#.#...#.#.##..#.#..... |
1304 | * ..## #..# #### .#.. .#.# .#.# .#.# .#.# .#.. ##. | 1335 | * ..###..#####.#...#.#.#.#.#.#.#.#.#..##. |
1305 | * .... .#.# ...# .#.. .#.# .#.# .#.# ..## .#.. .#. | 1336 | * .....#.#...#.#...#.#.#.#.#.#..##.#...#. |
1306 | * .### #..# ...# ..## #... #.#. .#.# ...# ..## ##. | 1337 | * .####..#...#..###...#.#..#.#...#..####. |
1307 | * .... .... .... .... .... .... .... .... .... ... | 1338 | * ....................................... |
1308 | * 39 x 7 pixel, 1 bpp | 1339 | * 39 x 7 pixel, 1 bpp |
1309 | */ | 1340 | */ |
1310 | 0x00, 0x00, 0x00, 0x00, 0x00, | 1341 | 0x00, 0x24, 0x2A, 0x2A, 0x2A, 0x12, 0x00, 0x3E, 0x08, 0x08, |
1311 | 0x3D, 0x13, 0x91, 0x51, 0x3C, | 1342 | 0x08, 0x3E, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x1E, |
1312 | 0x41, 0x14, 0x51, 0x59, 0x40, | 1343 | 0x20, 0x18, 0x20, 0x1E, 0x00, 0x3E, 0x00, 0x3E, 0x04, 0x08, |
1313 | 0x39, 0xF4, 0x55, 0x55, 0x4C, | 1344 | 0x10, 0x3E, 0x00, 0x1C, 0x22, 0x22, 0x2A, 0x3A, 0x00 |
1314 | 0x05, 0x14, 0x55, 0x53, 0x44, | ||
1315 | 0x79, 0x13, 0x8A, 0x51, 0x3C, | ||
1316 | 0x00, 0x00, 0x00, 0x00, 0x00 | ||
1317 | }; | 1345 | }; |
1318 | 1346 | ||
1319 | static unsigned char grayscale_gray[] = { | 1347 | static unsigned char grayscale_gray[] = { |
@@ -1405,8 +1433,8 @@ int main(void) | |||
1405 | gray_invertline(13, 27, 98, 27); /* invert a line */ | 1433 | gray_invertline(13, 27, 98, 27); /* invert a line */ |
1406 | 1434 | ||
1407 | /* show bitmaps (1 bit and 8 bit) */ | 1435 | /* show bitmaps (1 bit and 8 bit) */ |
1408 | gray_drawbitmap(rockbox, 14, 13, 43, 7, 6, true, 255, 100); /* opaque */ | 1436 | gray_drawbitmap(rockbox, 14, 13, 43, 7, 43, true, 255, 100); /* opaque */ |
1409 | gray_drawbitmap(showing, 58, 13, 39, 7, 5, false, 0, 0); /* transparent */ | 1437 | gray_drawbitmap(showing, 58, 13, 39, 7, 39, false, 0, 0); /* transparent */ |
1410 | gray_drawgraymap(grayscale_gray, 28, 35, 55, 7, 55); | 1438 | gray_drawgraymap(grayscale_gray, 28, 35, 55, 7, 55); |
1411 | 1439 | ||
1412 | time = *rb->current_tick - time; /* end time measurement */ | 1440 | time = *rb->current_tick - time; /* end time measurement */ |