2011-08-10 49 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函數(或其調用者)以保存在那裏解碼的數據。