22 static const char scan_type_str[][6] = {
34 static unsigned char *jpeg_data_ptr;
35 static int flg_reduce = 0;
36 static void *image_ptr;
37 static int flg_draw = 0;
39 static unsigned char pjpeg_data_need_bytes_callback(
unsigned char *pBuf,
unsigned char buf_size,
40 unsigned char *pBytes_actually_read,
void *pCallback_data)
44 DTPRINTF(0x02,
"pBuf %p, buf_size %d\n", pBuf, buf_size);
46 (void)
memorycopy(pBuf, jpeg_data_ptr, buf_size);
48 jpeg_data_ptr += buf_size;
50 XDUMP(0x02, pBuf, rsize);
52 *pBytes_actually_read = rsize;
57 static pjpeg_image_info_t *image_info;
59 static short jpx, jpy;
61 static void draw_pict(
short px,
short py,
void *gbuf)
65 if((px + 8) > image_info->m_width) {
66 gw = (image_info->m_width % 8);
67 DTPRINTF(0x02,
"X=%d, Y=%d, W=%d\n", px, py, gw);
69 if((py + 8) > image_info->m_height) {
70 gh = (image_info->m_height % 8);
71 DTPRINTF(0x02,
"X=%d, Y=%d, H=%d\n", px, py, gh);
79 draw_image(jpx + px, jpy + py, gw, gh, gbuf, 8);
100 static void draw_block(
short px,
short py)
103 int dlen = image_info->m_MCUWidth * image_info->m_MCUHeight;
104 unsigned char *pr = image_info->m_pMCUBufR;
105 unsigned char *pg = image_info->m_pMCUBufG;
106 unsigned char *pb = image_info->m_pMCUBufB;
108 DTPRINTF(0x02,
"X = %d, Y = %d mcu = %d\n", px, py, dlen);
109 DTPRINTF(0x02,
"R = %p, B = %p, G = %p\n", pr, pg, pb);
110 DTPRINTF(0x02,
"W = %d, H = %d\n", image_info->m_MCUWidth, image_info->m_MCUHeight);
112 for(i=0; i<dlen; i++) {
113 gbuf[i] = RGB(*pr, *pg, *pb);
119 XDUMP(0x04, (
unsigned char *)gbuf, dlen *
sizeof(gbuf[0]));
121 switch(image_info->m_scanType) {
127 draw_pict(px, py, gbuf);
131 draw_pict(px, py, gbuf);
132 draw_pict(px, py+8, &gbuf[64]);
136 draw_pict(px, py, gbuf);
137 draw_pict(px+8, py, &gbuf[64]);
141 draw_pict(px, py, gbuf);
142 draw_pict(px+8, py, &gbuf[64]);
143 draw_pict(px, py+8, &gbuf[128]);
144 draw_pict(px+8, py+8, &gbuf[192]);
152 int get_jpeg_data_info(
unsigned char *jpeg_data, pjpeg_image_info_t *jpeginfo,
int reduce)
154 unsigned char status;
156 jpeg_data_ptr = jpeg_data;
157 image_info = jpeginfo;
160 status = pjpeg_decode_init(image_info, pjpeg_data_need_bytes_callback, 0, reduce);
162 DTPRINTF(0x01,
"status = %d\n", status);
164 DTPRINTF(0x01,
"pjpeg_decode_init() failed with status %u\n", status);
165 if(status == PJPG_UNSUPPORTED_MODE) {
166 DTPRINTF(0x01,
"Progressive JPEG files are not supported.\n");
171 DTPRINTF(0x01,
"IMAGE WIDTH = %d, HEIGHT = %d, COMPS = %d\n", image_info->m_width, image_info->m_height, image_info->m_comps);
172 DTPRINTF(0x01,
"MCU WIDTH = %d, HEIGHT = %d\n", image_info->m_MCUWidth, image_info->m_MCUHeight);
173 DTPRINTF(0x01,
"SCANTYPE = %s\n", scan_type_str[image_info->m_scanType]);
181 static int jpeg_fd = 0;
183 static unsigned char pjpeg_file_need_bytes_callback(
unsigned char *pBuf,
unsigned char buf_size,
184 unsigned char *pBytes_actually_read,
void *pCallback_data)
188 DTPRINTF(0x02,
"pBuf %p, buf_size %d\n", pBuf, buf_size);
190 rsize =
read_file(jpeg_fd, pBuf, buf_size);
191 XDUMP(0x02, pBuf, rsize);
193 *pBytes_actually_read = rsize;
198 int get_jpeg_file_info(
int fd, pjpeg_image_info_t *jpeginfo,
int reduce)
200 unsigned char status;
203 image_info = jpeginfo;
206 status = pjpeg_decode_init(image_info, pjpeg_file_need_bytes_callback, 0, reduce);
208 DTPRINTF(0x01,
"status = %d\n", status);
210 DTPRINTF(0x01,
"pjpeg_decode_init() failed with status %u\n", status);
211 if(status == PJPG_UNSUPPORTED_MODE) {
212 DTPRINTF(0x01,
"Progressive JPEG files are not supported.\n");
217 DTPRINTF(0x01,
"IMAGE WIDTH = %d, HEIGHT = %d, COMPS = %d\n", image_info->m_width, image_info->m_height, image_info->m_comps);
218 DTPRINTF(0x01,
"MCU WIDTH = %d, HEIGHT = %d\n", image_info->m_MCUWidth, image_info->m_MCUHeight);
219 DTPRINTF(0x01,
"SCANTYPE = %s\n", scan_type_str[image_info->m_scanType]);
225 static int decode_proc_jpeg(
void)
227 short gy = 0, gx = 0;
230 unsigned char status;
232 status = pjpeg_decode_mcu();
235 if(status != PJPG_NO_MORE_BLOCKS) {
236 DTPRINTF(0x01,
"pjpeg_decode_mcu() failed with status %u\n", status);
242 XDUMP(0x04, image_info->m_pMCUBufR, 256);
243 XDUMP(0x04, image_info->m_pMCUBufG, 256);
244 XDUMP(0x04, image_info->m_pMCUBufB, 256);
248 gx += image_info->m_MCUWidth;
249 if(gx >= image_info->m_width) {
251 gy += image_info->m_MCUHeight;
252 if(gy >= image_info->m_height) {
264 int draw_jpeg(
short px,
short py)
270 return decode_proc_jpeg();
276 int decode_jpeg(
void *image)
281 return decode_proc_jpeg();
void draw_point(short x, short y)
点を描画する
void draw_image(short px, short py, short width, short height, void *image, short dw)
イメージデータを描画する
void set_forecolor(unsigned int color)
描画の色を設定する
void * memorycopy(void *dest, const void *src, unsigned int count)
メモリコピー
t_ssize read_file(int fd, void *buf, t_size count)
ファイルからデータを読み出す
unsigned short PIXEL_DATA
$gsc グラフィックデバイスは24ビットカラー