Created
October 24, 2012 14:07
-
-
Save nikolaykasyanov/3946238 to your computer and use it in GitHub Desktop.
Memory source for libjpeg-turbo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "jpeg_memory_src.h" | |
/// JPEG source manager | |
struct jpeg_source_t | |
{ | |
struct jpeg_source_mgr _pub; | |
const char *_begin; | |
const char *_end; | |
}; | |
/// Initialize JPEG source | |
METHODDEF(void) init_source(j_decompress_ptr cinfo) | |
{ | |
} | |
/// Fill image buffer | |
METHODDEF(boolean) fill_input_buffer(j_decompress_ptr cinfo) | |
{ | |
struct jpeg_source_t *src=(struct jpeg_source_t *)cinfo->src; | |
src->_pub.next_input_byte=(const JOCTET *)src->_begin; | |
src->_pub.bytes_in_buffer=src->_end-src->_begin; | |
return TRUE; | |
} | |
/// Skip data in buffer | |
METHODDEF(void)skip_input_data(j_decompress_ptr cinfo, long num_bytes) | |
{ | |
struct jpeg_source_t *src=(struct jpeg_source_t *)cinfo->src; | |
src->_pub.next_input_byte+=(size_t)num_bytes; | |
src->_pub.bytes_in_buffer-=(size_t)num_bytes; | |
} | |
/// Close buffer | |
METHODDEF(void)term_source(j_decompress_ptr cinfo) | |
{ | |
} | |
/// Initialize memory source | |
void jpeg_memory_src(j_decompress_ptr cinfo, const char *begin, const char *end) | |
{ | |
cinfo->src=(struct jpeg_source_mgr *)(*cinfo->mem->alloc_small)((j_common_ptr)cinfo, JPOOL_PERMANENT, sizeof(struct jpeg_source_t)); | |
struct jpeg_source_t *src=(struct jpeg_source_t *)cinfo->src; | |
src->_pub.init_source=init_source; | |
src->_pub.fill_input_buffer=fill_input_buffer; | |
src->_pub.skip_input_data=skip_input_data; | |
src->_pub.resync_to_restart=jpeg_resync_to_restart; | |
src->_pub.term_source=term_source; | |
src->_pub.bytes_in_buffer=0; | |
src->_pub.next_input_byte=NULL; | |
src->_begin=begin; | |
src->_end=end; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef jpegtest_jpeg_memory_src_h | |
#define jpegtest_jpeg_memory_src_h | |
#include <stdio.h> | |
#include <jpeglib.h> | |
extern void jpeg_memory_src(j_decompress_ptr cinfo, const char *begin, const char *end); | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment