# huffman compression

## Recommended Posts

Hi, i'm wanting to integrate my webcams into an application. I'm using my drivers' test program 'testquickcam' to provide the frame data. This gives me a headerless jpeg, as explained here from the help docs:
                                  Compression
The Logitech Quickcam Web can deliver their images in compressed
format. The image format is a kind of JPEG, but without headers
describing the encoding. Instead the encoding is fixed. Every block
starts with a bit selecting the quantizer scale and 10 bits
representing the zeroth element of the DCT matrix. After this the
huffman codes follow. Here is the [8]huffman table. The last element
is marked by the huffman code 0110. Before every fourth block (i.e.
also before the first) there is a four bit number that has to do with
the quantizer scale, but it is always 7 in my experiments. The file
[9]decode-lvc.c contains the code interpreting the huffman blocks and
sending the result through an Inverse DCT, do a YUV transformation and
return the RGB pixels.

The 'testquickcam' code provides two methods for retrieving the data, which then is sent to hexdump. Instead of hexdumping I want to be able to save the data as an image. My first attempts will be trying to use the 'gd' libary. 'testquickcam' provides, img_w, img_h, img_depth, and obviously the image buffer which is the huffman table (lossless jpeg). The driver being used is: http://qce-ga.sourceforge.net/ If anyone has a simple suggestion of how to save the buffer, it'll be much appreciated. Just for reference here's code for one method and it's output (slightly formatted by the hexdump()):
void mmap_test(int quiet)
{
struct video_mbuf vidbuf;
struct video_mmap vm;
int numframe = 0;
unsigned char *buffer;
ioctl(device_fd, VIDIOCGMBUF, &vidbuf);
buffer = mmap(NULL, vidbuf.size, PROT_READ, MAP_SHARED, device_fd, 0);

vm.format = VIDEO_PALETTE_RGB24;
vm.frame  = 0;
vm.width  = 352;
vm.height = 288;
ioctl(device_fd, VIDIOCMCAPTURE, &vm);

ioctl(device_fd, VIDIOCSYNC, &numframe);

if(!quiet)
{
printf(" *** mmap() test ***\n");
printf("Raw data: \n\n");
hexdump_data(buffer, vidbuf.size);
}
}

and here's the output:
    *** Camera Info ***
Name:           Labtec Webcam
Type:           1
Minimum Width:  160
Maximum Width:  352
Minimum Height: 120
Maximum Height: 288
X:              0
Y:              0
Width:          176
Height:         144
Depth:          24
Color           true
Version:        $Id: testquickcam.c,v 1.3 2004/07/28 10:13:12 tuukkat Exp$
*** mmap() test ***
Raw data:

[0000]: 11 24 5d 11 27 5d 11 27 5d 11 29 5d 11 26 5f 11 29 5f 11 27 5f 11 2a 5f 12 28 5f 12 29 5f 12 28
[0020]: 61 12 2a 61 12 29 63 12 2b 63 13 29 64 13 2c 64 11 2a 63 11 2c 63 11 29 66 11 2c 66 13 2b 67 13
[0040]: 2d 67 12 2b 66 12 2e 66 14 2a 67 14 2d 67 13 2b 68 13 2d 68 13 2b 6a 13 2d 6a 13 2c 69 13 2e 69
[0060]: 14 2e 6c 14 2f 6c 14 2b 6e 14 2e 6e 13 2d 6b 13 30 6b 14 2d 6c 14 30 6c 13 2d 71 13 30 71 14 2f
[0080]: 70 14 31 70 14 2e 6f 14 31 6f 13 2e 6d 13 2f 6d 10 28 62 10 28 62 11 29 65 11 2b 65 11 2c 69 11
[00a0]: 2e 69 13 2d 6d 13 30 6d 11 2b 69 11 2d 69 14 2f 70 14 32 70 15 30 77 15 34 77 17 32 79 17 35 79
[00c0]:
...
...
...
[257fa0]: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[257fc0]: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[257fe0]: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[258000]: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00


##### Share on other sites
Does anybody know an easy way of writing a jpeg header for the above so I can impliment it into the following code:

// -lgd -lpng -lz -ljpeg -lfreetype -lm#include "gd.h"#include <stdio.h>void save_img(int size, void *data){	gdImagePtr im;	FILE *jpegout;		im = gdImageCreateFromJpegPtr(size, data);		jpegout = fopen("test.jpg", "wb");	gdImageJpeg(im, jpegout, -1);	fclose(jpegout);	gdImageDestroy(im);}

At current it errors like this:
gd-jpeg: JPEG library reports unrecoverable error: Not a JPEG file: starts with 0x05 0x04Segmentation fault

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627708
• Total Posts
2978730

• 21
• 14
• 12
• 22
• 35