libjpeg ver。 6b jpeg_stdio_src vs jpeg_mem_src [英] libjpeg ver. 6b jpeg_stdio_src vs jpeg_mem_src

查看:196
本文介绍了libjpeg ver。 6b jpeg_stdio_src vs jpeg_mem_src的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Libjpeg版本6b。在版本8,他们有一个很好的功能,从内存中读出数据 jpeg_mem_src(...),不幸的是。 6b没有这个功能。

I am using Libjpeg version 6b. In version 8 they have a nice function to read data out of the memory called jpeg_mem_src(...), unfortunately ver. 6b does not have this function.

我可以使用什么来直接从内存读取压缩数据?我看到的是从硬盘驱动器读取的 jpeg_stdio_src

What can I use to read compressed data directly from memory? All I see is jpeg_stdio_src which reads from the hard drive.

推荐答案

写自己的...

/* Read JPEG image from a memory segment */
static void init_source (j_decompress_ptr cinfo) {}
static boolean fill_input_buffer (j_decompress_ptr cinfo)
{
    ERREXIT(cinfo, JERR_INPUT_EMPTY);
return TRUE;
}
static void skip_input_data (j_decompress_ptr cinfo, long num_bytes)
{
    struct jpeg_source_mgr* src = (struct jpeg_source_mgr*) cinfo->src;

    if (num_bytes > 0) {
        src->next_input_byte += (size_t) num_bytes;
        src->bytes_in_buffer -= (size_t) num_bytes;
    }
}
static void term_source (j_decompress_ptr cinfo) {}
static void jpeg_mem_src (j_decompress_ptr cinfo, void* buffer, long nbytes)
{
    struct jpeg_source_mgr* src;

    if (cinfo->src == NULL) {   /* first time for this JPEG object? */
        cinfo->src = (struct jpeg_source_mgr *)
            (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
            SIZEOF(struct jpeg_source_mgr));
    }

    src = (struct jpeg_source_mgr*) cinfo->src;
    src->init_source = init_source;
    src->fill_input_buffer = fill_input_buffer;
    src->skip_input_data = skip_input_data;
    src->resync_to_restart = jpeg_resync_to_restart; /* use default method */
    src->term_source = term_source;
    src->bytes_in_buffer = nbytes;
    src->next_input_byte = (JOCTET*)buffer;
}

,然后使用它:

...
    /* Step 2: specify data source (eg, a file) */
    jpeg_mem_src(&dinfo, buffer, nbytes);
...

其中buffer是指向包含压缩jpeg图像的内存块的指针,而nbytes是该缓冲区的长度。

where buffer is a pointer to the memory chunk containing the compressed jpeg image, and nbytes is the length of that buffer.

这篇关于libjpeg ver。 6b jpeg_stdio_src vs jpeg_mem_src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆