From f2d8f433391919bc13041fe850aefb502fa6f348 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Tue, 1 Sep 2015 15:05:27 +0100 Subject: add decode test suite --- examples/bmp_display | 3 + examples/bmpsuite/g01bg.bmp | Bin 1086 -> 0 bytes examples/bmpsuite/g01bw.bmp | Bin 1086 -> 0 bytes examples/bmpsuite/g01p1.bmp | Bin 1082 -> 0 bytes examples/bmpsuite/g01wb.bmp | Bin 1086 -> 0 bytes examples/bmpsuite/g04.bmp | Bin 4214 -> 0 bytes examples/bmpsuite/g04p4.bmp | Bin 4166 -> 0 bytes examples/bmpsuite/g04rle.bmp | Bin 922 -> 0 bytes examples/bmpsuite/g08.bmp | Bin 9270 -> 0 bytes examples/bmpsuite/g08offs.bmp | Bin 9370 -> 0 bytes examples/bmpsuite/g08os2.bmp | Bin 8986 -> 0 bytes examples/bmpsuite/g08p256.bmp | Bin 9270 -> 0 bytes examples/bmpsuite/g08p64.bmp | Bin 8502 -> 0 bytes examples/bmpsuite/g08pi256.bmp | Bin 9270 -> 0 bytes examples/bmpsuite/g08pi64.bmp | Bin 9270 -> 0 bytes examples/bmpsuite/g08res11.bmp | Bin 9270 -> 0 bytes examples/bmpsuite/g08res21.bmp | Bin 9270 -> 0 bytes examples/bmpsuite/g08res22.bmp | Bin 9270 -> 0 bytes examples/bmpsuite/g08rle.bmp | Bin 1820 -> 0 bytes examples/bmpsuite/g08s0.bmp | Bin 9270 -> 0 bytes examples/bmpsuite/g08w124.bmp | Bin 8642 -> 0 bytes examples/bmpsuite/g08w125.bmp | Bin 9014 -> 0 bytes examples/bmpsuite/g08w126.bmp | Bin 9142 -> 0 bytes examples/bmpsuite/g16bf555.bmp | Bin 16450 -> 0 bytes examples/bmpsuite/g16bf565.bmp | Bin 16450 -> 0 bytes examples/bmpsuite/g16def555.bmp | Bin 16438 -> 0 bytes examples/bmpsuite/g24.bmp | Bin 24630 -> 0 bytes examples/bmpsuite/g32bf.bmp | Bin 32578 -> 0 bytes examples/bmpsuite/g32def.bmp | Bin 32566 -> 0 bytes examples/bmpsuite/png/01bg.png | Bin 281 -> 0 bytes examples/bmpsuite/png/01bw.png | Bin 281 -> 0 bytes examples/bmpsuite/png/01p1.png | Bin 139 -> 0 bytes examples/bmpsuite/png/04.png | Bin 280 -> 0 bytes examples/bmpsuite/png/04p4.png | Bin 223 -> 0 bytes examples/bmpsuite/png/08.png | Bin 1447 -> 0 bytes examples/bmpsuite/png/08p64.png | Bin 694 -> 0 bytes examples/bmpsuite/png/08w124.png | Bin 1434 -> 0 bytes examples/bmpsuite/png/08w125.png | Bin 1450 -> 0 bytes examples/bmpsuite/png/08w126.png | Bin 1461 -> 0 bytes examples/bmpsuite/png/16bf555.png | Bin 525 -> 0 bytes examples/bmpsuite/png/16bf565.png | Bin 580 -> 0 bytes examples/bmpsuite/png/24.png | Bin 433 -> 0 bytes examples/bmpsuite/png/reference.html | 54 ---------- examples/bmpsuite/readme.txt | 38 ------- examples/bmpsuite/test.html | 54 ---------- examples/decode_bmp.c | 192 --------------------------------- examples/decode_ico.c | 203 ----------------------------------- examples/ico_display | 3 + examples/monitor.ico | Bin 102758 -> 0 bytes 49 files changed, 6 insertions(+), 541 deletions(-) create mode 100755 examples/bmp_display delete mode 100644 examples/bmpsuite/g01bg.bmp delete mode 100644 examples/bmpsuite/g01bw.bmp delete mode 100644 examples/bmpsuite/g01p1.bmp delete mode 100644 examples/bmpsuite/g01wb.bmp delete mode 100644 examples/bmpsuite/g04.bmp delete mode 100644 examples/bmpsuite/g04p4.bmp delete mode 100644 examples/bmpsuite/g04rle.bmp delete mode 100644 examples/bmpsuite/g08.bmp delete mode 100644 examples/bmpsuite/g08offs.bmp delete mode 100644 examples/bmpsuite/g08os2.bmp delete mode 100644 examples/bmpsuite/g08p256.bmp delete mode 100644 examples/bmpsuite/g08p64.bmp delete mode 100644 examples/bmpsuite/g08pi256.bmp delete mode 100644 examples/bmpsuite/g08pi64.bmp delete mode 100644 examples/bmpsuite/g08res11.bmp delete mode 100644 examples/bmpsuite/g08res21.bmp delete mode 100644 examples/bmpsuite/g08res22.bmp delete mode 100644 examples/bmpsuite/g08rle.bmp delete mode 100644 examples/bmpsuite/g08s0.bmp delete mode 100644 examples/bmpsuite/g08w124.bmp delete mode 100644 examples/bmpsuite/g08w125.bmp delete mode 100644 examples/bmpsuite/g08w126.bmp delete mode 100644 examples/bmpsuite/g16bf555.bmp delete mode 100644 examples/bmpsuite/g16bf565.bmp delete mode 100644 examples/bmpsuite/g16def555.bmp delete mode 100644 examples/bmpsuite/g24.bmp delete mode 100644 examples/bmpsuite/g32bf.bmp delete mode 100644 examples/bmpsuite/g32def.bmp delete mode 100644 examples/bmpsuite/png/01bg.png delete mode 100644 examples/bmpsuite/png/01bw.png delete mode 100644 examples/bmpsuite/png/01p1.png delete mode 100644 examples/bmpsuite/png/04.png delete mode 100644 examples/bmpsuite/png/04p4.png delete mode 100644 examples/bmpsuite/png/08.png delete mode 100644 examples/bmpsuite/png/08p64.png delete mode 100644 examples/bmpsuite/png/08w124.png delete mode 100644 examples/bmpsuite/png/08w125.png delete mode 100644 examples/bmpsuite/png/08w126.png delete mode 100644 examples/bmpsuite/png/16bf555.png delete mode 100644 examples/bmpsuite/png/16bf565.png delete mode 100644 examples/bmpsuite/png/24.png delete mode 100644 examples/bmpsuite/png/reference.html delete mode 100644 examples/bmpsuite/readme.txt delete mode 100644 examples/bmpsuite/test.html delete mode 100644 examples/decode_bmp.c delete mode 100644 examples/decode_ico.c create mode 100755 examples/ico_display delete mode 100644 examples/monitor.ico (limited to 'examples') diff --git a/examples/bmp_display b/examples/bmp_display new file mode 100755 index 0000000..dd0458c --- /dev/null +++ b/examples/bmp_display @@ -0,0 +1,3 @@ +set -e +make +bin/decode_bmp $1 | display diff --git a/examples/bmpsuite/g01bg.bmp b/examples/bmpsuite/g01bg.bmp deleted file mode 100644 index a720347..0000000 Binary files a/examples/bmpsuite/g01bg.bmp and /dev/null differ diff --git a/examples/bmpsuite/g01bw.bmp b/examples/bmpsuite/g01bw.bmp deleted file mode 100644 index 06189a6..0000000 Binary files a/examples/bmpsuite/g01bw.bmp and /dev/null differ diff --git a/examples/bmpsuite/g01p1.bmp b/examples/bmpsuite/g01p1.bmp deleted file mode 100644 index 706b4a1..0000000 Binary files a/examples/bmpsuite/g01p1.bmp and /dev/null differ diff --git a/examples/bmpsuite/g01wb.bmp b/examples/bmpsuite/g01wb.bmp deleted file mode 100644 index 2f05b43..0000000 Binary files a/examples/bmpsuite/g01wb.bmp and /dev/null differ diff --git a/examples/bmpsuite/g04.bmp b/examples/bmpsuite/g04.bmp deleted file mode 100644 index a064f66..0000000 Binary files a/examples/bmpsuite/g04.bmp and /dev/null differ diff --git a/examples/bmpsuite/g04p4.bmp b/examples/bmpsuite/g04p4.bmp deleted file mode 100644 index 4c1096b..0000000 Binary files a/examples/bmpsuite/g04p4.bmp and /dev/null differ diff --git a/examples/bmpsuite/g04rle.bmp b/examples/bmpsuite/g04rle.bmp deleted file mode 100644 index 7239fa6..0000000 Binary files a/examples/bmpsuite/g04rle.bmp and /dev/null differ diff --git a/examples/bmpsuite/g08.bmp b/examples/bmpsuite/g08.bmp deleted file mode 100644 index 3be9a20..0000000 Binary files a/examples/bmpsuite/g08.bmp and /dev/null differ diff --git a/examples/bmpsuite/g08offs.bmp b/examples/bmpsuite/g08offs.bmp deleted file mode 100644 index 71def41..0000000 Binary files a/examples/bmpsuite/g08offs.bmp and /dev/null differ diff --git a/examples/bmpsuite/g08os2.bmp b/examples/bmpsuite/g08os2.bmp deleted file mode 100644 index f7f9f57..0000000 Binary files a/examples/bmpsuite/g08os2.bmp and /dev/null differ diff --git a/examples/bmpsuite/g08p256.bmp b/examples/bmpsuite/g08p256.bmp deleted file mode 100644 index a129bbc..0000000 Binary files a/examples/bmpsuite/g08p256.bmp and /dev/null differ diff --git a/examples/bmpsuite/g08p64.bmp b/examples/bmpsuite/g08p64.bmp deleted file mode 100644 index 9d3affd..0000000 Binary files a/examples/bmpsuite/g08p64.bmp and /dev/null differ diff --git a/examples/bmpsuite/g08pi256.bmp b/examples/bmpsuite/g08pi256.bmp deleted file mode 100644 index 45df3f8..0000000 Binary files a/examples/bmpsuite/g08pi256.bmp and /dev/null differ diff --git a/examples/bmpsuite/g08pi64.bmp b/examples/bmpsuite/g08pi64.bmp deleted file mode 100644 index 52baf91..0000000 Binary files a/examples/bmpsuite/g08pi64.bmp and /dev/null differ diff --git a/examples/bmpsuite/g08res11.bmp b/examples/bmpsuite/g08res11.bmp deleted file mode 100644 index f03d0f3..0000000 Binary files a/examples/bmpsuite/g08res11.bmp and /dev/null differ diff --git a/examples/bmpsuite/g08res21.bmp b/examples/bmpsuite/g08res21.bmp deleted file mode 100644 index 61198e5..0000000 Binary files a/examples/bmpsuite/g08res21.bmp and /dev/null differ diff --git a/examples/bmpsuite/g08res22.bmp b/examples/bmpsuite/g08res22.bmp deleted file mode 100644 index 1af0ecc..0000000 Binary files a/examples/bmpsuite/g08res22.bmp and /dev/null differ diff --git a/examples/bmpsuite/g08rle.bmp b/examples/bmpsuite/g08rle.bmp deleted file mode 100644 index 082f7f4..0000000 Binary files a/examples/bmpsuite/g08rle.bmp and /dev/null differ diff --git a/examples/bmpsuite/g08s0.bmp b/examples/bmpsuite/g08s0.bmp deleted file mode 100644 index 4b2c521..0000000 Binary files a/examples/bmpsuite/g08s0.bmp and /dev/null differ diff --git a/examples/bmpsuite/g08w124.bmp b/examples/bmpsuite/g08w124.bmp deleted file mode 100644 index 1896035..0000000 Binary files a/examples/bmpsuite/g08w124.bmp and /dev/null differ diff --git a/examples/bmpsuite/g08w125.bmp b/examples/bmpsuite/g08w125.bmp deleted file mode 100644 index b348a7c..0000000 Binary files a/examples/bmpsuite/g08w125.bmp and /dev/null differ diff --git a/examples/bmpsuite/g08w126.bmp b/examples/bmpsuite/g08w126.bmp deleted file mode 100644 index 3628d66..0000000 Binary files a/examples/bmpsuite/g08w126.bmp and /dev/null differ diff --git a/examples/bmpsuite/g16bf555.bmp b/examples/bmpsuite/g16bf555.bmp deleted file mode 100644 index 639a57f..0000000 Binary files a/examples/bmpsuite/g16bf555.bmp and /dev/null differ diff --git a/examples/bmpsuite/g16bf565.bmp b/examples/bmpsuite/g16bf565.bmp deleted file mode 100644 index cb0ea24..0000000 Binary files a/examples/bmpsuite/g16bf565.bmp and /dev/null differ diff --git a/examples/bmpsuite/g16def555.bmp b/examples/bmpsuite/g16def555.bmp deleted file mode 100644 index a5a3195..0000000 Binary files a/examples/bmpsuite/g16def555.bmp and /dev/null differ diff --git a/examples/bmpsuite/g24.bmp b/examples/bmpsuite/g24.bmp deleted file mode 100644 index d6d9e6a..0000000 Binary files a/examples/bmpsuite/g24.bmp and /dev/null differ diff --git a/examples/bmpsuite/g32bf.bmp b/examples/bmpsuite/g32bf.bmp deleted file mode 100644 index 0f41534..0000000 Binary files a/examples/bmpsuite/g32bf.bmp and /dev/null differ diff --git a/examples/bmpsuite/g32def.bmp b/examples/bmpsuite/g32def.bmp deleted file mode 100644 index 9524f76..0000000 Binary files a/examples/bmpsuite/g32def.bmp and /dev/null differ diff --git a/examples/bmpsuite/png/01bg.png b/examples/bmpsuite/png/01bg.png deleted file mode 100644 index 0b9cf9a..0000000 Binary files a/examples/bmpsuite/png/01bg.png and /dev/null differ diff --git a/examples/bmpsuite/png/01bw.png b/examples/bmpsuite/png/01bw.png deleted file mode 100644 index 9f2e57a..0000000 Binary files a/examples/bmpsuite/png/01bw.png and /dev/null differ diff --git a/examples/bmpsuite/png/01p1.png b/examples/bmpsuite/png/01p1.png deleted file mode 100644 index 0103e79..0000000 Binary files a/examples/bmpsuite/png/01p1.png and /dev/null differ diff --git a/examples/bmpsuite/png/04.png b/examples/bmpsuite/png/04.png deleted file mode 100644 index 14beb91..0000000 Binary files a/examples/bmpsuite/png/04.png and /dev/null differ diff --git a/examples/bmpsuite/png/04p4.png b/examples/bmpsuite/png/04p4.png deleted file mode 100644 index 8dbcafa..0000000 Binary files a/examples/bmpsuite/png/04p4.png and /dev/null differ diff --git a/examples/bmpsuite/png/08.png b/examples/bmpsuite/png/08.png deleted file mode 100644 index 06545a0..0000000 Binary files a/examples/bmpsuite/png/08.png and /dev/null differ diff --git a/examples/bmpsuite/png/08p64.png b/examples/bmpsuite/png/08p64.png deleted file mode 100644 index 49f0802..0000000 Binary files a/examples/bmpsuite/png/08p64.png and /dev/null differ diff --git a/examples/bmpsuite/png/08w124.png b/examples/bmpsuite/png/08w124.png deleted file mode 100644 index 8da58fb..0000000 Binary files a/examples/bmpsuite/png/08w124.png and /dev/null differ diff --git a/examples/bmpsuite/png/08w125.png b/examples/bmpsuite/png/08w125.png deleted file mode 100644 index 6ebb4f8..0000000 Binary files a/examples/bmpsuite/png/08w125.png and /dev/null differ diff --git a/examples/bmpsuite/png/08w126.png b/examples/bmpsuite/png/08w126.png deleted file mode 100644 index ca9c9b9..0000000 Binary files a/examples/bmpsuite/png/08w126.png and /dev/null differ diff --git a/examples/bmpsuite/png/16bf555.png b/examples/bmpsuite/png/16bf555.png deleted file mode 100644 index aaa0dff..0000000 Binary files a/examples/bmpsuite/png/16bf555.png and /dev/null differ diff --git a/examples/bmpsuite/png/16bf565.png b/examples/bmpsuite/png/16bf565.png deleted file mode 100644 index 52d90e3..0000000 Binary files a/examples/bmpsuite/png/16bf565.png and /dev/null differ diff --git a/examples/bmpsuite/png/24.png b/examples/bmpsuite/png/24.png deleted file mode 100644 index e9fc4db..0000000 Binary files a/examples/bmpsuite/png/24.png and /dev/null differ diff --git a/examples/bmpsuite/png/reference.html b/examples/bmpsuite/png/reference.html deleted file mode 100644 index 7117b6c..0000000 --- a/examples/bmpsuite/png/reference.html +++ /dev/null @@ -1,54 +0,0 @@ - - - -BMP Suite Reference Images - - - -

BMP Suite Reference Images

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FilebppCommentsReference
g01bw.bmp1black and white palette (#000000,#FFFFFF)
g01wb.bmp1white and black palette (#FFFFFF,#000000). Should look the same as g01bw, not inverted.
g01bg.bmp1blue and green palette (#4040FF,#40FF40)
g01p1.bmp11-color (blue) palette (#4040FF)
g04.bmp4basic 4bpp (16 color) image
g04rle.bmp4RLE compressed.
g04p4.bmp44-color grayscale palette
g08.bmp8basic 8bpp (256 color) image
g08p256.bmp8biClrUsed=256, biClrImportant=0 [=256]
g08pi256.bmp8biClrUsed=256, biClrImportant=256
g08pi64.bmp8biClrUsed=256, biClrImportant=64. It's barely possible that some sophisticated viewers may display this image in grayscale, if there are a limited number of colors available.
g08rle.bmp8RLE compressed.
g08os2.bmp8OS/2-style bitmap. This is an obsolete variety of BMP that is still encountered sometimes. It has 3-byte palette entries (instead of 4), and 16-bit width/height fields (instead of 32).
g08res22.bmp8resolution 7874x7874 pixels/meter (200x200 dpi)
g08res11.bmp8resolution 3937x3937 pixels/meter (100x100 dpi)
g08res21.bmp8resolution 7874x3937 pixels/meter (200x100 dpi). Some programs (e.g. Imaging for Windows) may display this image stretched vertically, which is the optimal thing to do if the program is primarily a viewer, rather than an editor.
g08s0.bmp8bits size not given (set to 0). This is legal for uncompressed bitmaps.
g08offs.bmp8bfOffBits in header not set to the usual value. There are 100 extra unused bytes between palette and bits.
g08w126.bmp8size 126x63 (right and bottom slightly clipped)
g08w125.bmp8size 125x62
g08w124.bmp8size 124x61
g08p64.bmp864-color grayscale palette
g16def555.bmp1615-bit color (1 bit wasted), biCompression=BI_RGB (no bitfields, defaults to 5-5-5)
g16bf555.bmp1615-bit color, biCompression=BI_BITFIELDS (bitfields indicate 5-5-5)
g16bf565.bmp1616-bit color, biCompression=BI_BITFIELDS (bitfields indicate 5-6-5)
g24.bmp2424-bit color (BGR)
g32def.bmp3224-bit color (8 bits wasted), biCompression=BI_RGB (no bitfields, defaults to BGRx)
g32bf.bmp3224-bit color (8 bits wasted), biCompression=BI_BITFIELDS (bitfields indicate BGRx)
- -
-

By Jason Summers, -4/2001

- - - diff --git a/examples/bmpsuite/readme.txt b/examples/bmpsuite/readme.txt deleted file mode 100644 index 347aded..0000000 --- a/examples/bmpsuite/readme.txt +++ /dev/null @@ -1,38 +0,0 @@ -BMP Suite - sample BMP image files -By Jason Summers - -Version: 2001.04.27 - -For more information: http://pobox.com/~jason1/bmpsuite/ - -Contents --------- - -g01bw.bmp -g01wb.bmp -g01bg.bmp -g01p1.bmp -g04.bmp -g04p4.bmp -g08.bmp -g08offs.bmp -g08os2.bmp -g08w126.bmp -g08w125.bmp -g08w124.bmp -g08p256.bmp -g08pi256.bmp -g08pi64.bmp -g08res22.bmp -g08res21.bmp -g08res11.bmp -g08p64.bmp -g08s0.bmp -g16def555.bmp -g16bf555.bmp -g16bf565.bmp -g024.bmp -g32def.bmp -g32bf.bmp - --- end -- diff --git a/examples/bmpsuite/test.html b/examples/bmpsuite/test.html deleted file mode 100644 index 8abb614..0000000 --- a/examples/bmpsuite/test.html +++ /dev/null @@ -1,54 +0,0 @@ - - - -BMP Suite Images - - - -

BMP Suite Images

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FilebppCommentsImage
g01bw.bmp1black and white palette (#000000,#FFFFFF)
g01wb.bmp1white and black palette (#FFFFFF,#000000). Should look the same as g01bw, not inverted.
g01bg.bmp1blue and green palette (#4040FF,#40FF40)
g01p1.bmp11-color (blue) palette (#4040FF)
g04.bmp4basic 4bpp (16 color) image
g04rle.bmp4RLE compressed.
g04p4.bmp44-color grayscale palette
g08.bmp8basic 8bpp (256 color) image
g08p256.bmp8biClrUsed=256, biClrImportant=0 [=256]
g08pi256.bmp8biClrUsed=256, biClrImportant=256
g08pi64.bmp8biClrUsed=256, biClrImportant=64. It's barely possible that some sophisticated viewers may display this image in grayscale, if there are a limited number of colors available.
g08rle.bmp8RLE compressed.
g08os2.bmp8OS/2-style bitmap. This is an obsolete variety of BMP that is still encountered sometimes. It has 3-byte palette entries (instead of 4), and 16-bit width/height fields (instead of 32).
g08res22.bmp8resolution 7874x7874 pixels/meter (200x200 dpi)
g08res11.bmp8resolution 3937x3937 pixels/meter (100x100 dpi)
g08res21.bmp8resolution 7874x3937 pixels/meter (200x100 dpi). Some programs (e.g. Imaging for Windows) may display this image stretched vertically, which is the optimal thing to do if the program is primarily a viewer, rather than an editor.
g08s0.bmp8bits size not given (set to 0). This is legal for uncompressed bitmaps.
g08offs.bmp8bfOffBits in header not set to the usual value. There are 100 extra unused bytes between palette and bits.
g08w126.bmp8size 126x63 (right and bottom slightly clipped)
g08w125.bmp8size 125x62
g08w124.bmp8size 124x61
g08p64.bmp864-color grayscale palette
g16def555.bmp1615-bit color (1 bit wasted), biCompression=BI_RGB (no bitfields, defaults to 5-5-5)
g16bf555.bmp1615-bit color, biCompression=BI_BITFIELDS (bitfields indicate 5-5-5)
g16bf565.bmp1616-bit color, biCompression=BI_BITFIELDS (bitfields indicate 5-6-5)
g24.bmp2424-bit color (BGR)
g32def.bmp3224-bit color (8 bits wasted), biCompression=BI_RGB (no bitfields, defaults to BGRx)
g32bf.bmp3224-bit color (8 bits wasted), biCompression=BI_BITFIELDS (bitfields indicate BGRx)
- -
-

By Jason Summers, -4/2001

- - - diff --git a/examples/decode_bmp.c b/examples/decode_bmp.c deleted file mode 100644 index e5dc572..0000000 --- a/examples/decode_bmp.c +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright 2008 Sean Fox - * Copyright 2008 James Bursa - * - * This file is part of NetSurf's libnsbmp, http://www.netsurf-browser.org/ - * Licenced under the MIT License, - * http://www.opensource.org/licenses/mit-license.php - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "../include/libnsbmp.h" - -#define BYTES_PER_PIXEL 4 -#define TRANSPARENT_COLOR 0xffffffff - -unsigned char *load_file(const char *path, size_t *data_size); -void warning(const char *context, bmp_result code); -void *bitmap_create(int width, int height, unsigned int state); -unsigned char *bitmap_get_buffer(void *bitmap); -size_t bitmap_get_bpp(void *bitmap); -void bitmap_destroy(void *bitmap); - - -int main(int argc, char *argv[]) -{ - bmp_bitmap_callback_vt bitmap_callbacks = { - bitmap_create, - bitmap_destroy, - bitmap_get_buffer, - bitmap_get_bpp - }; - bmp_result code; - bmp_image bmp; - size_t size; - unsigned short res = 0; - - if (argc != 2) { - fprintf(stderr, "Usage: %s image.bmp\n", argv[0]); - return 1; - } - - /* create our bmp image */ - bmp_create(&bmp, &bitmap_callbacks); - - /* load file into memory */ - unsigned char *data = load_file(argv[1], &size); - - /* analyse the BMP */ - code = bmp_analyse(&bmp, size, data); - if (code != BMP_OK) { - warning("bmp_analyse", code); - res = 1; - goto cleanup; - } - - /* decode the image */ - code = bmp_decode(&bmp); - /* code = bmp_decode_trans(&bmp, TRANSPARENT_COLOR); */ - if (code != BMP_OK) { - warning("bmp_decode", code); - /* allow partially decoded images */ - if (code != BMP_INSUFFICIENT_DATA) { - res = 1; - goto cleanup; - } - } - - printf("P3\n"); - printf("# %s\n", argv[1]); - printf("# width %u \n", bmp.width); - printf("# height %u \n", bmp.height); - printf("%u %u 256\n", bmp.width, bmp.height); - - { - uint16_t row, col; - uint8_t *image; - image = (uint8_t *) bmp.bitmap; - for (row = 0; row != bmp.height; row++) { - for (col = 0; col != bmp.width; col++) { - size_t z = (row * bmp.width + col) * BYTES_PER_PIXEL; - printf("%u %u %u ", image[z], - image[z + 1], - image[z + 2]); - } - printf("\n"); - } - } - -cleanup: - /* clean up */ - bmp_finalise(&bmp); - free(data); - - return res; -} - - -unsigned char *load_file(const char *path, size_t *data_size) -{ - FILE *fd; - struct stat sb; - unsigned char *buffer; - size_t size; - size_t n; - - fd = fopen(path, "rb"); - if (!fd) { - perror(path); - exit(EXIT_FAILURE); - } - - if (stat(path, &sb)) { - perror(path); - exit(EXIT_FAILURE); - } - size = sb.st_size; - - buffer = malloc(size); - if (!buffer) { - fprintf(stderr, "Unable to allocate %lld bytes\n", - (long long) size); - exit(EXIT_FAILURE); - } - - n = fread(buffer, 1, size, fd); - if (n != size) { - perror(path); - exit(EXIT_FAILURE); - } - - fclose(fd); - - *data_size = size; - return buffer; -} - - -void warning(const char *context, bmp_result code) -{ - fprintf(stderr, "%s failed: ", context); - switch (code) { - case BMP_INSUFFICIENT_MEMORY: - fprintf(stderr, "BMP_INSUFFICIENT_MEMORY"); - break; - case BMP_INSUFFICIENT_DATA: - fprintf(stderr, "BMP_INSUFFICIENT_DATA"); - break; - case BMP_DATA_ERROR: - fprintf(stderr, "BMP_DATA_ERROR"); - break; - default: - fprintf(stderr, "unknown code %i", code); - break; - } - fprintf(stderr, "\n"); -} - - -void *bitmap_create(int width, int height, unsigned int state) -{ - (void) state; /* unused */ - return calloc(width * height, BYTES_PER_PIXEL); -} - - -unsigned char *bitmap_get_buffer(void *bitmap) -{ - assert(bitmap); - return bitmap; -} - - -size_t bitmap_get_bpp(void *bitmap) -{ - (void) bitmap; /* unused */ - return BYTES_PER_PIXEL; -} - - -void bitmap_destroy(void *bitmap) -{ - assert(bitmap); - free(bitmap); -} - diff --git a/examples/decode_ico.c b/examples/decode_ico.c deleted file mode 100644 index 935001c..0000000 --- a/examples/decode_ico.c +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright 2008 Sean Fox - * Copyright 2008 James Bursa - * - * This file is part of NetSurf's libnsbmp, http://www.netsurf-browser.org/ - * Licenced under the MIT License, - * http://www.opensource.org/licenses/mit-license.php - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "../include/libnsbmp.h" - -/* Currently the library returns the data in RGBA format, - * so there are 4 bytes per pixel */ -#define BYTES_PER_PIXEL 4 - -/* White with alpha masking. */ -#define TRANSPARENT_COLOR 0xffffffff - -unsigned char *load_file(const char *path, size_t *data_size); -void warning(const char *context, bmp_result code); -void *bitmap_create(int width, int height, unsigned int state); -unsigned char *bitmap_get_buffer(void *bitmap); -size_t bitmap_get_bpp(void *bitmap); -void bitmap_destroy(void *bitmap); - - -int main(int argc, char *argv[]) -{ - bmp_bitmap_callback_vt bitmap_callbacks = { - bitmap_create, - bitmap_destroy, - bitmap_get_buffer, - bitmap_get_bpp - }; - uint16_t width, height; - ico_collection ico; - bmp_result code; - struct bmp_image *bmp; - size_t size; - unsigned short res = 0; - - if ((argc < 2) || (argc > 4)) { - fprintf(stderr, "Usage: %s collection.ico [width=255] [height=255]\n", argv[0]); - return 1; - } - width = (argc >= 3) ? atoi(argv[2]) : 255; - height = (argc == 4) ? atoi(argv[3]) : 255; - - /* create our bmp image */ - ico_collection_create(&ico, &bitmap_callbacks); - - /* load file into memory */ - unsigned char *data = load_file(argv[1], &size); - - /* analyse the BMP */ - code = ico_analyse(&ico, size, data); - if (code != BMP_OK) { - warning("ico_analyse", code); - res = 1; - goto cleanup; - } - - /* decode the image */ - bmp = ico_find(&ico, width, height); - assert(bmp); - - code = bmp_decode(bmp); - /* code = bmp_decode_trans(bmp, TRANSPARENT_COLOR); */ - if (code != BMP_OK) { - warning("bmp_decode", code); - /* allow partially decoded images */ - if (code != BMP_INSUFFICIENT_DATA) { - res = 1; - goto cleanup; - } - } - - printf("P3\n"); - printf("# %s\n", argv[1]); - printf("# width %u \n", bmp->width); - printf("# height %u \n", bmp->height); - printf("%u %u 256\n", bmp->width, bmp->height); - - { - uint16_t row, col; - uint8_t *image; - image = (uint8_t *) bmp->bitmap; - for (row = 0; row != bmp->height; row++) { - for (col = 0; col != bmp->width; col++) { - size_t z = (row * bmp->width + col) * BYTES_PER_PIXEL; - printf("%u %u %u ", image[z], - image[z + 1], - image[z + 2]); - } - printf("\n"); - } - } - -cleanup: - /* clean up */ - ico_finalise(&ico); - free(data); - - return res; -} - - -unsigned char *load_file(const char *path, size_t *data_size) -{ - FILE *fd; - struct stat sb; - unsigned char *buffer; - size_t size; - size_t n; - - fd = fopen(path, "rb"); - if (!fd) { - perror(path); - exit(EXIT_FAILURE); - } - - if (stat(path, &sb)) { - perror(path); - exit(EXIT_FAILURE); - } - size = sb.st_size; - - buffer = malloc(size); - if (!buffer) { - fprintf(stderr, "Unable to allocate %lld bytes\n", - (long long) size); - exit(EXIT_FAILURE); - } - - n = fread(buffer, 1, size, fd); - if (n != size) { - perror(path); - exit(EXIT_FAILURE); - } - - fclose(fd); - - *data_size = size; - return buffer; -} - - -void warning(const char *context, bmp_result code) -{ - fprintf(stderr, "%s failed: ", context); - switch (code) { - case BMP_INSUFFICIENT_MEMORY: - fprintf(stderr, "BMP_INSUFFICIENT_MEMORY"); - break; - case BMP_INSUFFICIENT_DATA: - fprintf(stderr, "BMP_INSUFFICIENT_DATA"); - break; - case BMP_DATA_ERROR: - fprintf(stderr, "BMP_DATA_ERROR"); - break; - default: - fprintf(stderr, "unknown code %i", code); - break; - } - fprintf(stderr, "\n"); -} - - -void *bitmap_create(int width, int height, unsigned int state) -{ - (void) state; /* unused */ - return calloc(width * height, BYTES_PER_PIXEL); -} - - -unsigned char *bitmap_get_buffer(void *bitmap) -{ - assert(bitmap); - return bitmap; -} - - -size_t bitmap_get_bpp(void *bitmap) -{ - (void) bitmap; /* unused */ - return BYTES_PER_PIXEL; -} - - -void bitmap_destroy(void *bitmap) -{ - assert(bitmap); - free(bitmap); -} - diff --git a/examples/ico_display b/examples/ico_display new file mode 100755 index 0000000..ff5cd3c --- /dev/null +++ b/examples/ico_display @@ -0,0 +1,3 @@ +set -e +make +bin/decode_ico $1 | display diff --git a/examples/monitor.ico b/examples/monitor.ico deleted file mode 100644 index 2997dc3..0000000 Binary files a/examples/monitor.ico and /dev/null differ -- cgit v1.2.3