From 5c43051d6deb43ae764013ecaa933588bf3fac34 Mon Sep 17 00:00:00 2001 From: Joachim Bauch Date: Wed, 9 Jan 2013 16:29:51 +0100 Subject: [PATCH] Make samples work when compiled with support for large images. --- demo/convert.c | 8 ++++---- demo/convert.h | 6 ++++-- demo/mjpeg.c | 19 +++++++++++++++---- demo/mjpeg.h | 4 +++- demo/scanner.c | 2 +- tests/dbgutil.c | 15 ++++++++++++--- 6 files changed, 39 insertions(+), 15 deletions(-) diff --git a/demo/convert.c b/demo/convert.c index 9e6f458..4d480a2 100644 --- a/demo/convert.c +++ b/demo/convert.c @@ -61,14 +61,14 @@ void yuyv_to_rgb32(const uint8_t *src, int src_pitch, void yuyv_to_luma(const uint8_t *src, int src_pitch, int w, int h, - uint8_t *dst, int dst_pitch) + quirc_pixel_t *dst, int dst_pitch) { int y; for (y = 0; y < h; y++) { int x; const uint8_t *srow = src + y * src_pitch; - uint8_t *drow = dst + y * dst_pitch; + quirc_pixel_t *drow = dst + y * dst_pitch; for (x = 0; x < w; x += 2) { *(drow++) = srow[0]; @@ -80,13 +80,13 @@ void yuyv_to_luma(const uint8_t *src, int src_pitch, void rgb32_to_luma(const uint8_t *src, int src_pitch, int w, int h, - uint8_t *dst, int dst_pitch) + quirc_pixel_t *dst, int dst_pitch) { int y; for (y = 0; y < h; y++) { const uint8_t *rgb32 = src + src_pitch * y; - uint8_t *gray = dst + y * dst_pitch; + quirc_pixel_t *gray = dst + y * dst_pitch; int i; for (i = 0; i < w; i++) { diff --git a/demo/convert.h b/demo/convert.h index ec2a14e..5693a75 100644 --- a/demo/convert.h +++ b/demo/convert.h @@ -19,6 +19,8 @@ #include +#include + /* Convert 4:2:2 YUYV format to RGB32 format. The source and destination * frames are expected to be the same size. */ @@ -29,11 +31,11 @@ void yuyv_to_rgb32(const uint8_t *src, int src_pitch, /* Extract the luma channel from a 4:2:2 YUYV image. */ void yuyv_to_luma(const uint8_t *src, int src_pitch, int w, int h, - uint8_t *dst, int dst_pitch); + quirc_pixel_t *dst, int dst_pitch); /* Extract the luma channel from an RGB32 image. */ void rgb32_to_luma(const uint8_t *src, int src_pitch, int w, int h, - uint8_t *dst, int dst_pitch); + quirc_pixel_t *dst, int dst_pitch); #endif diff --git a/demo/mjpeg.c b/demo/mjpeg.c index a6aa8be..2429fce 100644 --- a/demo/mjpeg.c +++ b/demo/mjpeg.c @@ -15,6 +15,7 @@ */ #include +#include #include #include #include @@ -247,8 +248,10 @@ int mjpeg_decode_rgb32(struct mjpeg_decoder *mj, int mjpeg_decode_gray(struct mjpeg_decoder *mj, const uint8_t *data, int datalen, - uint8_t *out, int pitch, int max_w, int max_h) + quirc_pixel_t *out, int pitch, int max_w, int max_h) { + int x; + JSAMPROW row_pointer; if (setjmp(mj->env)) return -1; @@ -266,12 +269,20 @@ int mjpeg_decode_gray(struct mjpeg_decoder *mj, return -1; } - while (mj->dinfo.output_scanline < mj->dinfo.image_height) { - uint8_t *scr = out + pitch * mj->dinfo.output_scanline; + row_pointer = malloc(mj->dinfo.output_width); + if (!row_pointer) + return -1; - jpeg_read_scanlines(&mj->dinfo, &scr, 1); + while (mj->dinfo.output_scanline < mj->dinfo.image_height) { + quirc_pixel_t *scr = out + pitch * mj->dinfo.output_scanline; + + jpeg_read_scanlines(&mj->dinfo, &row_pointer, 1); + for (x=0; x < mj->dinfo.output_width; x++, scr++) { + *scr = *(row_pointer + x); + } } + free(row_pointer); jpeg_finish_decompress(&mj->dinfo); return 0; diff --git a/demo/mjpeg.h b/demo/mjpeg.h index caac855..c360f7d 100644 --- a/demo/mjpeg.h +++ b/demo/mjpeg.h @@ -22,6 +22,8 @@ #include #include +#include + struct mjpeg_decoder { /* The error manager must be the first item in this struct */ struct jpeg_error_mgr err; @@ -49,6 +51,6 @@ int mjpeg_decode_rgb32(struct mjpeg_decoder *mj, */ int mjpeg_decode_gray(struct mjpeg_decoder *mj, const uint8_t *data, int datalen, - uint8_t *out, int pitch, int max_w, int max_h); + quirc_pixel_t *out, int pitch, int max_w, int max_h); #endif diff --git a/demo/scanner.c b/demo/scanner.c index 5d7877f..59b572b 100644 --- a/demo/scanner.c +++ b/demo/scanner.c @@ -45,7 +45,7 @@ static int main_loop(struct camera *cam, for (;;) { int w, h; int i, count; - uint8_t *buf = quirc_begin(q, &w, &h); + quirc_pixel_t *buf = quirc_begin(q, &w, &h); if (camera_update(cam) < 0) return -1; diff --git a/tests/dbgutil.c b/tests/dbgutil.c index 17473b2..851f3dc 100644 --- a/tests/dbgutil.c +++ b/tests/dbgutil.c @@ -16,6 +16,7 @@ #include #include +#include #include #include #include "dbgutil.h" @@ -91,7 +92,9 @@ int load_jpeg(struct quirc *q, const char *filename) FILE *infile = fopen(filename, "rb"); struct jpeg_decompress_struct dinfo; struct my_jpeg_error err; - uint8_t *image; + quirc_pixel_t *image; + JSAMPROW row_pointer; + int x; int y; if (!infile) { @@ -124,12 +127,18 @@ int load_jpeg(struct quirc *q, const char *filename) image = quirc_begin(q, NULL, NULL); - for (y = 0; y < dinfo.output_height; y++) { - JSAMPROW row_pointer = image + y * dinfo.output_width; + row_pointer = malloc(dinfo.output_width); + if (!row_pointer) + goto fail; + for (y = 0; y < dinfo.output_height; y++) { jpeg_read_scanlines(&dinfo, &row_pointer, 1); + for (x=0; x < dinfo.output_width; x++, image++) { + *image = *(row_pointer + x); + } } + free(row_pointer); fclose(infile); jpeg_finish_decompress(&dinfo); jpeg_destroy_decompress(&dinfo);