Re: [PATCH libv4l tree, RFC] libv4l: skip false Pixart markers with buffer copy
Hi, On 02/04/2010 09:22 AM, Németh Márton wrote: Hi, This is a proof-of-concept patch to try to decode the JPEG with PixArt markers. Please check whether it is working at your side. My experience is that the number of frames with glitch are reduced. Hi, Good job! I never noticed the ff ff ff xx markers where spaced a certain numbers of bytes apart. Based on that I've written a different filtering function, which at least for me completely removes all glitches!! See: http://linuxtv.org/hg/~hgoede/libv4l/rev/1fa67e17b77c Thanks !!! Regards, Hans Regards, Márton Németh --- From: Márton Némethnm...@freemail.hu Before trying to decode the image data filter the PixArt markers out. Signed-off-by: Márton Némethnm...@freemail.hu --- diff -r 966f60c672e9 v4l2-apps/libv4l/libv4lconvert/tinyjpeg-internal.h --- a/v4l2-apps/libv4l/libv4lconvert/tinyjpeg-internal.hTue Feb 02 11:34:06 2010 +0100 +++ b/v4l2-apps/libv4l/libv4lconvert/tinyjpeg-internal.hThu Feb 04 09:13:24 2010 +0100 @@ -91,8 +91,11 @@ /* Private variables */ const unsigned char *stream_begin, *stream_end; unsigned int stream_length; + unsigned char *stream_begin_filtered, *stream_end_filtered; + unsigned int stream_length_filtered; const unsigned char *stream;/* Pointer to the current stream */ + unsigned char *stream_filtered; unsigned int reservoir, nbits_in_reservoir; struct component component_infos[COMPONENTS]; diff -r 966f60c672e9 v4l2-apps/libv4l/libv4lconvert/tinyjpeg.c --- a/v4l2-apps/libv4l/libv4lconvert/tinyjpeg.c Tue Feb 02 11:34:06 2010 +0100 +++ b/v4l2-apps/libv4l/libv4lconvert/tinyjpeg.c Thu Feb 04 09:13:24 2010 +0100 @@ -312,19 +312,18 @@ /* Special Pixart versions of the *_nbits functions, these remove the special ff ff ff xx sequences pixart cams insert from the bitstream */ -#define pixart_fill_nbits(reservoir,nbits_in_reservoir,stream,nbits_wanted) \ +#define pixart_fill_nbits(reservoir,nbits_in_reservoir,stream,stream_end,nbits_wanted) \ do { \ while (nbits_in_reservoirnbits_wanted) \ { \ unsigned char c; \ - if (stream= priv-stream_end) { \ + if (stream= stream_end) { \ snprintf(priv-error_string, sizeof(priv-error_string), \ fill_nbits error: need %u more bits\n, \ nbits_wanted - nbits_in_reservoir); \ longjmp(priv-jump_state, -EIO); \ } \ c = *stream++; \ - reservoir= 8; \ if (c == 0xff) { \ switch (stream[0]) { \ case 0x00: \ @@ -332,7 +331,7 @@ break; \ case 0xd9: /* EOF marker */ \ stream++; \ - if (stream != priv-stream_end) { \ + if (stream != stream_end) { \ snprintf(priv-error_string, sizeof(priv-error_string), \ Pixart JPEG error: premature EOF\n); \ longjmp(priv-jump_state, -EIO); \ @@ -340,14 +339,22 @@ break; \ case 0xff: \ if (stream[1] == 0xff) { \ - if (stream[2] 7) { \ + if (stream[2] == 0) { \ + stream += 3; \ + c = *stream++; \ + break; \ + } else if (stream[2] == 1) { \ + stream += 3; \ + c = *stream++; \ + break; \ + } else if (stream[2] == 2) { \ stream += 3; \ c = *stream++; \ break; \ } else if (stream[2] == 0xff) { \ - /* four 0xff in a row: the first belongs to the image data */ \ + /* four 0xff in a row: the first belongs to the image */ \ break; \ - }\ + } \ } \ /* Error fall through */ \ default: \ @@ -358,15 +365,16 @@ longjmp(priv-jump_state, -EIO); \ } \ } \ + reservoir= 8; \ reservoir |= c; \ nbits_in_reservoir+=8; \ } \ } while(0); /* Signed version */ -#define pixart_get_nbits(reservoir,nbits_in_reservoir,stream,nbits_wanted,result) \ +#define pixart_get_nbits(reservoir,nbits_in_reservoir,stream,stream_end,nbits_wanted,result) \ do { \ - pixart_fill_nbits(reservoir,nbits_in_reservoir,stream,(nbits_wanted)); \ + pixart_fill_nbits(reservoir,nbits_in_reservoir,stream,stream_end,(nbits_wanted)); \ result = ((reservoir)(nbits_in_reservoir-(nbits_wanted))); \ nbits_in_reservoir -= (nbits_wanted); \ reservoir= ((1Unbits_in_reservoir)-1); \ @@ -374,9 +382,9 @@ result += (0xUL(nbits_wanted))+1; \ } while(0); -#define pixart_look_nbits(reservoir,nbits_in_reservoir,stream,nbits_wanted,result) \ +#define pixart_look_nbits(reservoir,nbits_in_reservoir,stream,stream_end,nbits_wanted,result) \ do { \ - pixart_fill_nbits(reservoir,nbits_in_reservoir,stream,(nbits_wanted)); \ +
Re: [PATCH libv4l tree, RFC] libv4l: skip false Pixart markers with buffer copy
On 02/05/2010 02:42 PM, Hans de Goede wrote: Good job! I never noticed the ff ff ff xx markers where spaced a certain numbers You can find this info here http://www.kaiser-linux.li/index.php?title=PAC7311 go down the page to 2006-11-12 Thomas -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH libv4l tree, RFC] libv4l: skip false Pixart markers with buffer copy
Hi, This is a proof-of-concept patch to try to decode the JPEG with PixArt markers. Please check whether it is working at your side. My experience is that the number of frames with glitch are reduced. Regards, Márton Németh --- From: Márton Németh nm...@freemail.hu Before trying to decode the image data filter the PixArt markers out. Signed-off-by: Márton Németh nm...@freemail.hu --- diff -r 966f60c672e9 v4l2-apps/libv4l/libv4lconvert/tinyjpeg-internal.h --- a/v4l2-apps/libv4l/libv4lconvert/tinyjpeg-internal.hTue Feb 02 11:34:06 2010 +0100 +++ b/v4l2-apps/libv4l/libv4lconvert/tinyjpeg-internal.hThu Feb 04 09:13:24 2010 +0100 @@ -91,8 +91,11 @@ /* Private variables */ const unsigned char *stream_begin, *stream_end; unsigned int stream_length; + unsigned char *stream_begin_filtered, *stream_end_filtered; + unsigned int stream_length_filtered; const unsigned char *stream; /* Pointer to the current stream */ + unsigned char *stream_filtered; unsigned int reservoir, nbits_in_reservoir; struct component component_infos[COMPONENTS]; diff -r 966f60c672e9 v4l2-apps/libv4l/libv4lconvert/tinyjpeg.c --- a/v4l2-apps/libv4l/libv4lconvert/tinyjpeg.c Tue Feb 02 11:34:06 2010 +0100 +++ b/v4l2-apps/libv4l/libv4lconvert/tinyjpeg.c Thu Feb 04 09:13:24 2010 +0100 @@ -312,19 +312,18 @@ /* Special Pixart versions of the *_nbits functions, these remove the special ff ff ff xx sequences pixart cams insert from the bitstream */ -#define pixart_fill_nbits(reservoir,nbits_in_reservoir,stream,nbits_wanted) \ +#define pixart_fill_nbits(reservoir,nbits_in_reservoir,stream,stream_end,nbits_wanted) \ do { \ while (nbits_in_reservoirnbits_wanted) \ { \ unsigned char c; \ - if (stream = priv-stream_end) { \ + if (stream = stream_end) { \ snprintf(priv-error_string, sizeof(priv-error_string), \ fill_nbits error: need %u more bits\n, \ nbits_wanted - nbits_in_reservoir); \ longjmp(priv-jump_state, -EIO); \ } \ c = *stream++; \ - reservoir = 8; \ if (c == 0xff) { \ switch (stream[0]) { \ case 0x00: \ @@ -332,7 +331,7 @@ break; \ case 0xd9: /* EOF marker */ \ stream++; \ - if (stream != priv-stream_end) { \ + if (stream != stream_end) { \ snprintf(priv-error_string, sizeof(priv-error_string), \ Pixart JPEG error: premature EOF\n); \ longjmp(priv-jump_state, -EIO); \ @@ -340,14 +339,22 @@ break; \ case 0xff: \ if (stream[1] == 0xff) { \ - if (stream[2] 7) { \ + if (stream[2] == 0) { \ + stream += 3; \ + c = *stream++; \ + break; \ + } else if (stream[2] == 1) { \ + stream += 3; \ + c = *stream++; \ + break; \ + } else if (stream[2] == 2) { \ stream += 3; \ c = *stream++; \ break; \ } else if (stream[2] == 0xff) { \ - /* four 0xff in a row: the first belongs to the image data */ \ + /* four 0xff in a row: the first belongs to the image */ \ break; \ - }\ + } \ } \ /* Error fall through */ \ default: \ @@ -358,15 +365,16 @@ longjmp(priv-jump_state, -EIO); \ } \ } \ + reservoir = 8; \ reservoir |= c; \ nbits_in_reservoir+=8; \ } \ } while(0); /* Signed version */ -#define pixart_get_nbits(reservoir,nbits_in_reservoir,stream,nbits_wanted,result) \ +#define pixart_get_nbits(reservoir,nbits_in_reservoir,stream,stream_end,nbits_wanted,result) \ do { \ - pixart_fill_nbits(reservoir,nbits_in_reservoir,stream,(nbits_wanted)); \ + pixart_fill_nbits(reservoir,nbits_in_reservoir,stream,stream_end,(nbits_wanted)); \ result = ((reservoir)(nbits_in_reservoir-(nbits_wanted))); \ nbits_in_reservoir -= (nbits_wanted); \ reservoir = ((1Unbits_in_reservoir)-1); \ @@ -374,9 +382,9 @@ result += (0xUL(nbits_wanted))+1; \ } while(0); -#define pixart_look_nbits(reservoir,nbits_in_reservoir,stream,nbits_wanted,result) \ +#define pixart_look_nbits(reservoir,nbits_in_reservoir,stream,stream_end,nbits_wanted,result) \ do { \ - pixart_fill_nbits(reservoir,nbits_in_reservoir,stream,(nbits_wanted)); \ + pixart_fill_nbits(reservoir,nbits_in_reservoir,stream,stream_end,(nbits_wanted)); \ result = ((reservoir)(nbits_in_reservoir-(nbits_wanted))); \ } while(0); @@ -443,7 +451,8 @@ unsigned int extra_nbits, nbits; uint16_t *slowtable; - pixart_look_nbits(priv-reservoir, priv-nbits_in_reservoir, priv-stream, HUFFMAN_HASH_NBITS, hcode); + pixart_look_nbits(priv-reservoir, priv-nbits_in_reservoir,