WEB开发网
开发学院手机开发Android 开发 Android jpeglib库在内存中实现解码 阅读

Android jpeglib库在内存中实现解码

 2010-09-10 00:39:00 来源:WEB开发网   
核心提示:/** This function will read the jpeg memery block to fill the library buffer.*/METHODDEF(boolean)jpg_fill_input_buffer (j_decompress_ptr cinfo){my_src_ptr src =

/*

* This function will read the jpeg memery block to fill the library buffer.

*/

METHODDEF(boolean)

jpg_fill_input_buffer (j_decompress_ptr cinfo)

{

my_src_ptr src = (my_src_ptr) cinfo->src;

size_t nbytes;

if(src->jpg.img_buffer == NULL || src->jpg.pos >= src->jpg.buffer_size){

nbytes = -1;

}

else {

nbytes = (src->jpg.pos + INPUT_BUF_SIZE > src->jpg.buffer_size ?

src->jpg.buffer_size - src->jpg.pos : INPUT_BUF_SIZE);

MEMCPY(src->buffer, src->jpg.img_buffer + src->jpg.pos, nbytes);

src->jpg.pos += nbytes;

}

if (nbytes <= 0) {

if (src->start_of_file) /* Treat empty input file as fatal error */

ERREXIT(cinfo, JERR_INPUT_EMPTY);

WARNMS(cinfo, JWRN_JPEG_EOF);

/* Insert a fake EOI marker */

src->buffer[0] = (JOCTET) 0xFF;

src->buffer[1] = (JOCTET) JPEG_EOI;

nbytes = 2;

}

src->pub.next_input_byte = src->buffer;

src->pub.bytes_in_buffer = nbytes;

src->start_of_file = FALSE;

return TRUE;

}

可以看出我们读取数据都是从内存缓存中读取,如果到达缓存末尾就返回-1。

经过调试分析还发现jdatasrc.c文件中skip_input_data函数有一个不严谨的地方。原来代码中如下:

METHODDEF(void)

skip_input_data (j_decompress_ptr cinfo, long num_bytes)

{

my_src_ptr src = (my_src_ptr) cinfo->src;

/* Just a dumb implementation for now. Could use fseek() except

* it doesn't work on pipes. Not clear that being smart is worth

* any trouble anyway --- large skips are infrequent.

*/

if (num_bytes > 0) {

while (num_bytes > (long) src->pub.bytes_in_buffer) {

上一页  1 2 3 4 5  下一页

Tags:Android jpeglib 内存

编辑录入:coldstar [复制链接] [打 印]
赞助商链接