[英]Libjpeg error - improper call in state 205
我正在使用 libjpeg(Windows Mobile 6.5 上的 C/C++ 編程),以便在將它們推入 DirectShow 圖形之前解碼來自 IP 相機(以 MJPEG 流發送)的圖像。
到目前為止,我一直在使用一個 function 來:接收 stream,手動解析它(為了找到 JPEG 數據的起點和終點),解碼數據(即初始化 libjpeg 結構,讀取 JPEG header,進行實際的解碼......)並最終將其推入圖中。 這工作正常,但為了使事情更順暢和整潔,我想使用 function 進行接收,調用另一個 function(后來,一個線程)進行解碼/推送。
因此,作為第一步,我沒有在 stream 中找到數據后立即執行所有 JPEG 工作,而是簡單地調用另一個 function,它負責 JPEG 結構 init / header 讀取/解碼/推送。
這就是我遇到無法破譯的錯誤的地方: "improper call to jpeg library in state 205" 。
// 編輯清晰
現在,我的代碼如下所示:
void receive1() { while(1) { if(recvfrom(/* ... */) > 0) { /* parse the received data for JPEG start and end */ /* decode the JPEG */ //Declarations struct jpeg_decompress_struct cinfo; struct my_error_mgr jerr; // Step 1: allocation / initialization cinfo.err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = my_error_exit; if(setjmp(jerr.setjmp_buffer)) { printf("--ERROR LIBJPEG\n"); /* quit with error code */ } // Next steps : proceed with the decoding and displaying... jpeg_create_decompress(&cinfo); /* ... */ } } }
我想讓我的代碼看起來像:
void receive2() { while(1) { if(recvfrom(/* ... */) > 0) { /* parse the received data for JPEG start and end */ decode(data); } } } int decode(char* data) { /* decode the JPEG */ //Declarations struct jpeg_decompress_struct cinfo; struct my_error_mgr jerr; // Step 1: allocation / initialization cinfo.err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = my_error_exit; if(setjmp(jerr.setjmp_buffer)) // This is where the "state 205" error occurs { printf("--ERROR LIBJPEG\n"); /* quit with error code */ } // Next steps : proceed with the decoding and displaying... jpeg_create_decompress(&cinfo); /* ... */ return 0; }
任何幫助將不勝感激。 非常感謝 !
// 編輯
我意識到我在原來的帖子中省略了很多信息。 這里有一些(可能)有用的細節:
typedef struct my_error_mgr * my_error_ptr; struct my_error_mgr { struct jpeg_error_mgr pub; jmp_buf setjmp_buffer; }; METHODDEF(void) my_error_exit (j_common_ptr cinfo) { my_error_ptr myerr = (my_error_ptr) cinfo->err; /* Always display the message. */ (*cinfo->err->output_message) (cinfo); /* Return control to the setjmp point */ longjmp(myerr->setjmp_buffer, 1); }
205是0xCD,這是VS在調試模式下將VS放入標准內存中的標准值,因此我認為在調用解碼器時,您的cinfo
沒有正確初始化。 使用時發布代碼。
另外,您正在使用的setjump()
讓我認為它是IJG庫。 請小心,因為它不是標准功能。 它會在您進行調用時記住線程和堆棧的確切狀態,並且能夠從任何地方返回該位置,除非該狀態不再有效,例如:
int init_fn(){
if (setjump(my_state)){
// ERROR!
};
return 0;
};
int decode(){
init_fn();
do_work();
};
在這里,保存的狀態在您調用實際的解碼器時無效。 對於MT情況,您必須從與longjmp()
相同的線程中調用setjump()
longjmp()
。
我遇到了完全相同的錯誤。 我正在開發 NVidia Jetson 開發工具包,想在屏幕上繪制 JPEG。
首先,我的圖像寬度不是 16 的倍數。一旦我修復了該部分,它就會加載,然后渲染會失敗並出現奇怪的錯誤消息:
state 205 中JPEG庫調用不當
我知道 Jetsons 只支持可能的 JPEG 格式的一個子集。 我重新生成了我的 JPEG 圖像以確保它是 4:2:0 而不是灰度(盡管該圖像有顏色,但 NVidia 硬件也不支持灰度圖像)然后再次嘗試。 錯誤消失了。
對於那些感興趣的人,這是我用來修復那些 JPEG 的命令行 function:
convert \
-sampling-factor 4:2:0 \
-type truecolor -define colorspace:auto-grayscale=off \
input.png output.jpg
然后output.jpg
圖像有效(只要寬度是 16 的倍數)。
找到了我問題的答案,部分歸功於ruslik。 事實證明,我確實在兩個函數之間嚴重初始化了cinfo和jerr。
但是當我糾正這一點時,我仍然遇到“狀態205”錯誤,並認為它在同一位置。 在我的日志中,我發現錯誤消息將在以后的代碼執行中發布,並且是由於函數指針問題引起的。 我自己的丑陋錯誤
還是非常感謝!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.