* v4l library - decoding of Pixart JPEG frames
@ 2008-08-14 17:14 Jean-Francois Moine
2008-08-14 18:51 ` Thomas Kaiser
2008-08-17 11:47 ` Hans de Goede
0 siblings, 2 replies; 4+ messages in thread
From: Jean-Francois Moine @ 2008-08-14 17:14 UTC (permalink / raw)
To: Hans de Goede; +Cc: Video 4 Linux
Hello Hans,
I found that the webcams containing a Pixart JPEG chip (PAC 73xx)
generate strange JPEG frames: they contains 'ff ff ff xx' markers every
1024 or 512 bytes and there are eight unused bits at the end of each
JPEG block (I saw also a 90 degrees rotation with the PAC 7302).
So, I added a new pixel format V4L2_PIX_FMT_PJPG for this encoding. It
is generated by the pac7311 subdriver of gspca. May you add the code for
decoding this format in the V4L library?
I could have done a patch by myself, but the tiny jpeg decoder is rather
complex, and I could not find the right place to do the job. If it may
help, I wrote a simple image viewer (http://moinejf.free.fr/siv.c) which
takes a raw webcam image and displays it via gtk+. It contains the
Pixart JPEG decoder and the two differences from normal JPEG are
identified by 'pac7311'.
Cheers.
--
Ken ar c'hentañ | ** Breizh ha Linux atav! **
Jef | http://moinejf.free.fr/
--
video4linux-list mailing list
Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: v4l library - decoding of Pixart JPEG frames
2008-08-14 17:14 v4l library - decoding of Pixart JPEG frames Jean-Francois Moine
@ 2008-08-14 18:51 ` Thomas Kaiser
2008-08-17 11:47 ` Hans de Goede
1 sibling, 0 replies; 4+ messages in thread
From: Thomas Kaiser @ 2008-08-14 18:51 UTC (permalink / raw)
To: Jean-Francois Moine; +Cc: Video 4 Linux
Hello Jean-Francois, Hans
I am the original developer who started the PAC7311 support for gspca V1.
Jean-Francois Moine wrote:
> Hello Hans,
>
> I found that the webcams containing a Pixart JPEG chip (PAC 73xx)
> generate strange JPEG frames: they contains 'ff ff ff xx' markers every
> 1024 or 512 bytes
xx = 01 -> 1024 Bytes
xx = 02 -> 512 Bytes
xx = 00 -> size of the following block is not defined
I don't know for what this markers should be good for.
So, I suggest to just remove them in the driver.
> and there are eight unused bits at the end of each
> JPEG block
End or Start? Depends where the end of the frame marker is defined! The
Last Byte in the frame marker has the same bit pattern which you will
find after each MCU. I call it MCU markers.
So, throw the first MCU marker (last Byte in the frame header) away in
the driver. While decoding the JPEG in the V4L library one have to throw
away 8 Bit after each MCU.
> (I saw also a 90 degrees rotation with the PAC 7302).
Same thing I saw by analyzing usbsnoops from a PAC7302.
>
> So, I added a new pixel format V4L2_PIX_FMT_PJPG for this encoding. It
> is generated by the pac7311 subdriver of gspca. May you add the code for
> decoding this format in the V4L library?
You should call it _SPJPG -> Special Pixart JPEG, just kidding :-)
>
> I could have done a patch by myself, but the tiny jpeg decoder is rather
> complex, and I could not find the right place to do the job.
Hans: Do you use tiny jpeg decoder in the v4l library?
I should have a version of tiny jpeg somewhere, where this special
Pixart jpeg decoding is already implemented. But anyway it's simple,
just skip 8 Bits after each MCU.
> If it may
> help, I wrote a simple image viewer (http://moinejf.free.fr/siv.c) which
> takes a raw webcam image and displays it via gtk+. It contains the
> Pixart JPEG decoder and the two differences from normal JPEG are
> identified by 'pac7311'.
I really don't understand why Pixart added this stuff. Once I asked
about more information about the stream, they just told me that they had
develop their own JPEG coding and decoding and it is company confidential.
Hope this information helps.
Thomas
--
video4linux-list mailing list
Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: v4l library - decoding of Pixart JPEG frames
2008-08-14 17:14 v4l library - decoding of Pixart JPEG frames Jean-Francois Moine
2008-08-14 18:51 ` Thomas Kaiser
@ 2008-08-17 11:47 ` Hans de Goede
2008-08-18 7:34 ` Jean-Francois Moine
1 sibling, 1 reply; 4+ messages in thread
From: Hans de Goede @ 2008-08-17 11:47 UTC (permalink / raw)
To: Jean-Francois Moine; +Cc: Video 4 Linux
[-- Attachment #1: Type: text/plain, Size: 1318 bytes --]
Hi Jean, Thomas,
Jean, good to see that you are working on the pixart 73xx support, I
have a cam over here as well which didn't work at all, now with your
fixes, it atleast generates proper frames (they used too be much too
small). Unfortunately my cam still does not work, your siv.c does show
something which seems to be decoded video data, but not as it should
look like, from the looks of it we are close though.
I've made a single raw frame from my cam available here:
http://people.atrpms.net/~hdegoede/image.dat
If anyone can write code which can convert that to an image (might be
unsharp) that would be great!
I've done a first attempt at making v4lconvert handle these pixart jpeg
frames, patch attached. Warning this is a crude hack breaking regular
jpeg support. This seems to work less well with my cam then the siv.c
code, so we might need to make more changes either to v4lconvert, or
maybe to the jpeg_put_header call in pac7311.c, talking about this call,
since we are defining a custom format anyways, shouldn't we just omit
the header and send the jpeg-ish pixart frame data to userspace as is?
Thomas, I would be very much interested in your tinyjpeg version with
pixart support!
Jean, perhaps you can make some raw images from your cam available
somewhere too?
Regards,
Hans
[-- Attachment #2: diff --]
[-- Type: text/plain, Size: 3038 bytes --]
diff -r 566aac58b414 v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert-priv.h
--- a/v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert-priv.h Thu Aug 07 19:34:10 2008 +0200
+++ b/v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert-priv.h Sun Aug 17 14:06:29 2008 +0200
@@ -43,6 +43,10 @@
#define V4L2_PIX_FMT_PAC207 v4l2_fourcc('P','2','0','7')
#endif
+#ifndef V4L2_PIX_FMT_PJPG
+#define V4L2_PIX_FMT_PJPG v4l2_fourcc('P', 'J', 'P', 'G')
+#endif
+
#ifndef V4L2_PIX_FMT_SGBRG8
#define V4L2_PIX_FMT_SGBRG8 v4l2_fourcc('G','B','R','G')
#endif
diff -r 566aac58b414 v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert.c
--- a/v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert.c Thu Aug 07 19:34:10 2008 +0200
+++ b/v4l2-apps/lib/libv4l/libv4lconvert/libv4lconvert.c Sun Aug 17 14:06:29 2008 +0200
@@ -48,6 +48,7 @@
V4L2_PIX_FMT_SPCA561,
V4L2_PIX_FMT_SN9C10X,
V4L2_PIX_FMT_PAC207,
+ V4L2_PIX_FMT_PJPG,
};
static const unsigned int supported_dst_pixfmts[] = {
@@ -297,6 +298,51 @@
}
switch (src_fmt->fmt.pix.pixelformat) {
+ case V4L2_PIX_FMT_PJPG:
+ {
+ unsigned char *in;
+ unsigned char *out, out_buf[src_size];
+ int in_size = src_size, out_size, header_size = 0x646;
+
+ if (src_size < header_size)
+ return needed;
+
+ memcpy(out_buf, src, header_size);
+
+ in = src + header_size;
+ out = out_buf + header_size;
+ in_size -= header_size;
+ out_size = header_size;
+
+ while(in_size > 0) {
+ int chunk_size;
+
+ if (in[0] != 0xff || in[1] != 0xff || in[2] != 0xff) {
+ fprintf(stderr, "Pixart JPEG format error, header: %02x %02x %02x\n",
+ (int)in[0], (int)in[1], (int)in[2]);
+ return needed;
+ }
+ if (in[3] == 0u)
+ chunk_size = in_size - 4;
+ else if (in[3] < 6u)
+ chunk_size = 1024 >> (in[3] - 1);
+ else {
+ fprintf(stderr, "Pixart JPEG format error: chunk_size = %d\n",
+ (int)in[3]);
+ return needed;
+ }
+
+ memcpy(out, in + 4, chunk_size);
+ in += chunk_size + 4;
+ out += chunk_size;
+ in_size -= chunk_size + 4;
+ out_size += chunk_size;
+ }
+
+ src = out_buf;
+ src_size = out_size;
+ /* fall through! */
+ }
case V4L2_PIX_FMT_MJPEG:
case V4L2_PIX_FMT_JPEG:
if (!data->jdec) {
diff -r 566aac58b414 v4l2-apps/lib/libv4l/libv4lconvert/tinyjpeg.c
--- a/v4l2-apps/lib/libv4l/libv4lconvert/tinyjpeg.c Thu Aug 07 19:34:10 2008 +0200
+++ b/v4l2-apps/lib/libv4l/libv4lconvert/tinyjpeg.c Sun Aug 17 14:06:29 2008 +0200
@@ -60,6 +60,9 @@
#define BLACK_Y 0
#define BLACK_U 127
#define BLACK_V 127
+
+#define DEBUG 1
+#define LOG2FILE 1
#if DEBUG
#if LOG2FILE
@@ -2112,6 +2115,7 @@
for (x=0; x < priv->width; x+=xstride_by_mcu)
{
decode_MCU(priv);
+ skip_nbits(priv->reservoir, priv->nbits_in_reservoir, priv->stream, 8);
convert_to_pixfmt(priv);
priv->plane[0] += bytes_per_mcu[0];
priv->plane[1] += bytes_per_mcu[1];
[-- Attachment #3: Type: text/plain, Size: 164 bytes --]
--
video4linux-list mailing list
Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: v4l library - decoding of Pixart JPEG frames
2008-08-17 11:47 ` Hans de Goede
@ 2008-08-18 7:34 ` Jean-Francois Moine
0 siblings, 0 replies; 4+ messages in thread
From: Jean-Francois Moine @ 2008-08-18 7:34 UTC (permalink / raw)
To: Hans de Goede; +Cc: Magic Banana, Video 4 Linux
On Sun, 2008-08-17 at 13:47 +0200, Hans de Goede wrote:
> Hi Jean, Thomas,
Hi Hans,
> Jean, good to see that you are working on the pixart 73xx support, I
> have a cam over here as well which didn't work at all, now with your
> fixes, it atleast generates proper frames (they used too be much too
> small). Unfortunately my cam still does not work, your siv.c does show
> something which seems to be decoded video data, but not as it should
> look like, from the looks of it we are close though.
>
> I've made a single raw frame from my cam available here:
> http://people.atrpms.net/~hdegoede/image.dat
I forgot to give you the command:
siv -p PJPG -f 480x640 -d image.dat
('-p PJPG' gives the encoding and '-f 480x640' because the image is
turned to the left).
It is almost black and white with high contrast.
> If anyone can write code which can convert that to an image (might be
> unsharp) that would be great!
>
> I've done a first attempt at making v4lconvert handle these pixart jpeg
> frames, patch attached. Warning this is a crude hack breaking regular
> jpeg support. This seems to work less well with my cam then the siv.c
> code, so we might need to make more changes either to v4lconvert, or
> maybe to the jpeg_put_header call in pac7311.c, talking about this call,
> since we are defining a custom format anyways, shouldn't we just omit
> the header and send the jpeg-ish pixart frame data to userspace as is?
About the header, it seems that neither the previous (in pac7311.c), nor
the standard jpeg header (in jpeg.h) give good results.
> Thomas, I would be very much interested in your tinyjpeg version with
> pixart support!
>
> Jean, perhaps you can make some raw images from your cam available
> somewhere too?
I am working with a french guy (Magic Banana, in Cc) who has a webcam
with a 7302 sensor. I put an image extracted from a MS-win trace in my
site:
http://moinejf.free.fr/pac7302.dat
(I added a jpeg header).
Cheers
--
Ken ar c'hentañ | ** Breizh ha Linux atav! **
Jef | http://moinejf.free.fr/
--
video4linux-list mailing list
Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-08-18 7:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-14 17:14 v4l library - decoding of Pixart JPEG frames Jean-Francois Moine
2008-08-14 18:51 ` Thomas Kaiser
2008-08-17 11:47 ` Hans de Goede
2008-08-18 7:34 ` Jean-Francois Moine
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox