Mon, 14 Dec 2009 15:51:53 +0000
Patched to add PNG and JP2 support.
Created-By: Daniel Glöckner <daniel-gl at gmx.net>
The attached patch adds PNG and JP2 support to tumble.
PNG:
As the deflated data is directly copied into the PDF, there are some
limitations to the list of supported images:
- bit depth <= 8
- no alpha channel
- no interlace
JP2:
The PDF Reference says JP2 is just a subset of the allowed JPX
format. I don't have a copy of the official standard, so I don't know
what to change to cover JPXes as well.
You'll need the Adobe Acrobat Reader 6 to display those images.
Xpdf and Ghostscript are missing the ColorSpace key in the image
dictionary, which is optional for JPXDecode and IMHO not just a matter
of a few lines of code.
One thing left to do is to change the PDF version to 1.5 if a JP2 file
has been given to tumble - maybe using the Version key in the Catalog
if seeking is not possible.
Using the resolution info in a JP2 (resc/resd boxes) is implemented but
untested. Jasper doesn't write those boxes.
I had to change the string handling to allow black in PNG palettes.
And there was a double free in tumble_input.c which happens when not
using control files.
Daniel
1 #include <stdbool.h>
2 #include <stdint.h>
3 #include <stdio.h>
4 #include <stdlib.h>
6 #include "bitblt.h"
9 #define WIDTH 44
10 #define HEIGHT 9
12 char test_data [HEIGHT][WIDTH] =
13 {
14 ".....XXXXXXXXXX.......XX............X......X",
15 ".....XX.......X.......X.X..........X......X.",
16 "XXXXXX.X......XXXXXX..X..X........X......X..",
17 ".....X..X.....X.......XX.........X......X...",
18 ".....X...X....X.......X.X.......X......X....",
19 ".....X....X...X.......X..X.....X......X.....",
20 ".....X.....X..X.......XX..... X......X......",
21 ".....XXXXXXXXXX.......X.X....X......X.......",
22 ".....X.X.X.X.X........X..X..X......X........"
23 };
25 Bitmap *setup (void)
26 {
27 Bitmap *b;
28 Point p;
29 Rect r = {{ 0, 0 }, { WIDTH, HEIGHT }};
31 b = create_bitmap (& r);
32 if (! b)
33 return (NULL);
35 for (p.y = 0; p.y < HEIGHT; p.y++)
36 for (p.x = 0; p.x < WIDTH; p.x++)
37 set_pixel (b, p, test_data [p.y][p.x] == 'X');
39 return (b);
40 }
42 void print_bitmap (FILE *o, Bitmap *b)
43 {
44 Point p;
45 printf ("row_words: %d\n", b->row_words);
46 for (p.y = b->rect.min.y; p.y < b->rect.max.y; p.y++)
47 {
48 for (p.x = b->rect.min.x; p.x < b->rect.max.x; p.x++)
49 fputc (".X" [get_pixel (b, p)], o);
50 fprintf (o, "\n");
51 }
52 }
55 int main (int argc, char *argv[])
56 {
57 Bitmap *b;
58 Bitmap *b2;
59 Rect r;
60 Point p;
62 b = setup ();
63 if (! b)
64 {
65 fprintf (stderr, "setup failed\n");
66 exit (2);
67 }
69 print_bitmap (stdout, b);
70 printf ("\n");
72 flip_v (b);
74 printf ("flipped vertically:\n");
75 print_bitmap (stdout, b);
76 printf ("\n");
78 flip_h (b);
80 printf ("flipped horizontally:\n");
81 print_bitmap (stdout, b);
82 printf ("\n");
84 #if 1
85 r.min.x = r.min.y = 0;
86 r.max.x = b->rect.max.x + 8;
87 r.max.y = b->rect.max.y + 8;
89 b2 = create_bitmap (& r);
91 r.min.x = r.min.y = 0;
92 r.max.x = b->rect.max.x;
93 r.max.y = b->rect.max.y;
95 p.x = -3;
96 p.y = -3;
98 b2 = bitblt (b, & r,
99 b2, & p,
100 TF_SRC, 0);
101 if (! b2)
102 {
103 fprintf (stderr, "bitblt failed\n");
104 exit (2);
105 }
107 printf ("after bitblt\n");
108 print_bitmap (stdout, b2);
109 #endif
111 exit (0);
112 }