首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用jpg库从jpg中获取DC系数?

如何使用jpg库从jpg中获取DC系数?
EN

Stack Overflow用户
提问于 2011-08-10 19:23:30
回答 1查看 351关注 0票数 2

我是新手,但我需要使用jpeg库从jpeg中获取dc系数?我被告知相应的函数在jdhuff.c中,但我找不到它。我试图找到一篇关于jpg库的好文章,在那里我可以得到这篇文章,但到目前为止还没有成功。

所以我希望你们能帮我一点忙,或者给我一些文档或者给我一些提示。所以,这是我所知道的:

jpg图片由8×8的块组成。这是64个像素。其中63个命名为AC,1个命名为DC。这就是系数。位置在数组中。

但是我该如何使用jpg库来准确地读取它呢?我正在使用C++。

编辑:这是我到目前为止所知道的:

代码语言:javascript
复制
read_jpeg::read_jpeg( const std::string& filename )
{
    FILE* fp = NULL;                // File-Pointer
    jpeg_decompress_struct cinfo;   // jpeg decompression parameters
    JSAMPARRAY buffer;              // Output row-buffer
    int row_stride = 0;             // physical row width
    my_error_mgr jerr;              // Custom Error Manager


    // Set Error Manager
    cinfo.err = jpeg_std_error(&jerr.pub);
    jerr.pub.error_exit = my_error_exit;

    // Handle longjump
    if (setjmp(jerr.setjmp_buffer)) {

        // JPEG has signaled an error. Clean up and throw an exception.
        jpeg_destroy_decompress(&cinfo);
        fclose(fp);
        throw std::runtime_error("Error: jpeg has reported an error.");
    }   

    // Open the file
    if ( (fp = fopen(filename.c_str(), "rb")) == NULL )
    {
        std::stringstream ss;
        ss << "Error: Cannot read '" <<  filename.c_str() << "' from the specified location!";
        throw std::runtime_error(ss.str());
    }

    // Initialize jpeg decompression
    jpeg_create_decompress(&cinfo);

    // Show jpeg where to read the data
    jpeg_stdio_src(&cinfo, fp);

    // Read the header
    jpeg_read_header(&cinfo, TRUE);

    // Decompress the file
    jpeg_start_decompress(&cinfo);

    // JSAMPLEs per row in output buffer
    row_stride = cinfo.output_width * cinfo.output_components;

    // Make a one-row-high sample array 
    buffer = (*cinfo.mem->alloc_sarray)((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);

    // Read image using jpgs counter
    while (cinfo.output_scanline < cinfo.output_height) 
    {

         // Read the image
         jpeg_read_scanlines(&cinfo, buffer, 1);
    }

    // Finish the decompress 
    jpeg_finish_decompress(&cinfo);

    // Release memory
    jpeg_destroy_decompress(&cinfo);

    // Close the file 
    fclose(fp);
}
EN

回答 1

Stack Overflow用户

发布于 2018-01-22 05:53:54

使用标准API是不可能的。使用libjpeg API,您可以获得的最接近的是Y/Cb/Cr通道的原始像素数据。

要获得系数的数据,您需要破解decode_mcu函数(或其调用者)以保存解码后的数据。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7009973

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档