Make samples work when compiled with support for large images.

This commit is contained in:
Joachim Bauch 2013-01-09 16:29:51 +01:00
parent 8c66a4437e
commit 5c43051d6d
6 changed files with 39 additions and 15 deletions

View file

@ -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++) {

View file

@ -19,6 +19,8 @@
#include <stdint.h>
#include <quirc.h>
/* 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

View file

@ -15,6 +15,7 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <setjmp.h>
#include <jpeglib.h>
@ -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;

View file

@ -22,6 +22,8 @@
#include <jpeglib.h>
#include <setjmp.h>
#include <quirc.h>
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

View file

@ -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;

View file

@ -16,6 +16,7 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>
#include <jpeglib.h>
#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);