2 #include "fitz-stream.h"
7 * We use the Jasper JPEG2000 coder for now.
10 #include <jasper/jasper.h>
12 static char *colorspacename(jas_clrspc_t clrspc
)
14 switch (jas_clrspc_fam(clrspc
))
16 case JAS_CLRSPC_FAM_UNKNOWN
: return "Unknown";
17 case JAS_CLRSPC_FAM_XYZ
: return "XYZ";
18 case JAS_CLRSPC_FAM_LAB
: return "Lab";
19 case JAS_CLRSPC_FAM_GRAY
: return "Gray";
20 case JAS_CLRSPC_FAM_RGB
: return "RGB";
21 case JAS_CLRSPC_FAM_YCBCR
: return "YCbCr";
26 typedef struct fz_jpxd_s fz_jpxd
;
38 fz_newjpxd(fz_filter
**fp
, fz_obj
*params
)
42 FZ_NEWFILTER(fz_jpxd
, d
, jpxd
);
47 return fz_throw("ioerror in jpxd: jas_init()");
50 d
->stream
= jas_stream_memopen(nil
, 0);
53 return fz_throw("ioerror in jpxd: jas_stream_memopen()");
64 fz_dropjpxd(fz_filter
*filter
)
66 fz_jpxd
*d
= (fz_jpxd
*)filter
;
67 if (d
->stream
) jas_stream_close(d
->stream
);
68 if (d
->image
) jas_image_destroy(d
->image
);
72 fz_processjpxd(fz_filter
*filter
, fz_buffer
*in
, fz_buffer
*out
)
74 fz_jpxd
*d
= (fz_jpxd
*)filter
;
86 while (in
->rp
< in
->wp
) {
87 n
= jas_stream_write(d
->stream
, in
->rp
, in
->wp
- in
->rp
);
97 jas_stream_seek(d
->stream
, 0, 0);
99 d
->image
= jas_image_decode(d
->stream
, -1, 0);
101 return fz_throw("ioerror in jpxd: unable to decode image data");
103 fprintf(stderr
, "P%c\n# JPX %d x %d n=%d bpc=%d colorspace=%04x %s\n%d %d\n%d\n",
104 jas_image_numcmpts(d
->image
) == 1 ? '5' : '6',
106 jas_image_width(d
->image
),
107 jas_image_height(d
->image
),
108 jas_image_numcmpts(d
->image
),
109 jas_image_cmptprec(d
->image
, 0),
110 jas_image_clrspc(d
->image
),
111 colorspacename(jas_image_clrspc(d
->image
)),
113 jas_image_width(d
->image
),
114 jas_image_height(d
->image
),
115 (1 << jas_image_cmptprec(d
->image
, 0)) - 1);
120 w
= jas_image_width(d
->image
);
121 h
= jas_image_height(d
->image
);
122 n
= jas_image_numcmpts(d
->image
);
123 bpc
= jas_image_cmptprec(d
->image
, 0); /* use precision of first component for all... */
125 while (d
->offset
< w
* h
)
128 x
= d
->offset
- y
* w
;
132 if (out
->wp
+ n
>= out
->ep
)
135 for (i
= 0; i
< n
; i
++)
136 *out
->wp
++ = jas_image_readcmptsample(d
->image
, i
, x
, y
);