2011-08-10 17 views
2

我是新来的这个东西,但我需要从jpeg使用jpeg库得到dc系数? 我被告知提示相应的函数在jdhuff.c中,但我找不到它。我试图找到一个关于jpg库的体面的文章,我可以得到它,但迄今为止没有成功。如何使用jpg库从jpg获取DC系数?

所以我希望你们能够帮助我一点,并指出我有些文件或有提示。 所以,这里是我所知道的:

jpg图片由8x8块组成。那是64像素。其中63个被命名为AC,1个被命名为DC。这就是系数。位置在数组[0] [0]处。

但我该如何阅读与JPG图书馆?我正在使用C++。

编辑: 这是我到目前为止有:

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); 
} 

回答

0

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

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