Mercurial > hg > minimon
diff jpg.c @ 3:e8957085fe8a
working
author | Peter Meerwald <pmeerw@pmeerw.net> |
---|---|
date | Sun, 08 May 2011 23:08:45 +0200 |
parents | bac8ed8d6eb9 |
children | 3819ecaf0f14 |
line wrap: on
line diff
--- a/jpg.c Sun May 08 18:22:22 2011 +0200 +++ b/jpg.c Sun May 08 23:08:45 2011 +0200 @@ -1,9 +1,12 @@ #include <stdlib.h> #include <stdio.h> +#include <unistd.h> #include <string.h> #include "jpeglib.h" #include "jerror.h" +#include "common.h" + typedef struct { struct jpeg_destination_mgr pub; /* public fields */ @@ -16,10 +19,10 @@ typedef mem_dest_mgr * mem_dest_mgr_ptr; -void init_mem_destination (j_compress_ptr cinfo) { +static void init_mem_destination (j_compress_ptr cinfo) { } -boolean empty_mem_output_buffer(j_compress_ptr cinfo) { +static boolean empty_mem_output_buffer(j_compress_ptr cinfo) { size_t nextsize; JOCTET * nextbuffer; mem_dest_mgr_ptr dest = (mem_dest_mgr_ptr) cinfo->dest; @@ -47,14 +50,14 @@ return TRUE; } -void term_mem_destination(j_compress_ptr cinfo) { +static void term_mem_destination(j_compress_ptr cinfo) { mem_dest_mgr_ptr dest = (mem_dest_mgr_ptr) cinfo->dest; *dest->outbuffer = dest->buffer; *dest->outsize = dest->bufsize - dest->pub.free_in_buffer; } -void jpeg_mem_dest(j_compress_ptr cinfo, unsigned char ** outbuffer, unsigned long * outsize) { +static void jpeg_mem_dest(j_compress_ptr cinfo, unsigned char ** outbuffer, unsigned long * outsize) { mem_dest_mgr_ptr dest; if (outbuffer == NULL || outsize == NULL) /* sanity check */ @@ -90,7 +93,8 @@ } -int build_jpg(JSAMPLE *image_buf, int width, int height) { + +jpg_buf_t build_jpg_from_fb(int fb, int width, int height) { int scanline; struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; @@ -98,9 +102,11 @@ cinfo.err = jpeg_std_error(&jerr); jpeg_create_compress(&cinfo); - unsigned long out_size = 1<<20; - unsigned char *out_buf = NULL; - jpeg_mem_dest(&cinfo, &out_buf, &out_size); + jpg_buf_t jpg_buf; + jpg_buf.size = 1 << 20; + jpg_buf.ptr = NULL; + + jpeg_mem_dest(&cinfo, &jpg_buf.ptr, &jpg_buf.size); cinfo.image_width = width; cinfo.image_height = height; @@ -110,15 +116,18 @@ jpeg_start_compress(&cinfo, TRUE); + JSAMPLE *buf = malloc(width * 4); + JSAMPROW row_ptr[1]; + row_ptr[0] = buf; for (scanline = 0; scanline < height; scanline++) { - JSAMPROW *row_ptr; - row_ptr = &image_buf[scanline * width]; + read(fb, buf, width*4); jpeg_write_scanlines(&cinfo, row_ptr, 1); } + free(buf); jpeg_finish_compress(&cinfo); jpeg_destroy_compress(&cinfo); - return 0; + return jpg_buf; }