⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gspcadecoder.c

📁 Linux下面摄像头最新源代码:支持200多中摄像头
💻 C
📖 第 1 页 / 共 5 页
字号:
	    /* store pixel */	    *outp++ = CLIP(val);	    col++;	}    }}void init_pixart_decoder(struct usb_spca50x *spca50x){    int i;    int is_abs, val, len;    struct code_table_t *table = spca50x->maindecode.table;    for (i = 0; i < 256; i++) {	is_abs = 0;	val = 0;	len = 0;	if ((i & 0xC0) == 0) {	    /* code 00 */	    val = 0;	    len = 2;	} else if ((i & 0xC0) == 0x40) {	    /* code 01 */	    val = -5;	    len = 2;	} else if ((i & 0xC0) == 0x80) {	    /* code 10 */	    val = +5;	    len = 2;	} else if ((i & 0xF0) == 0xC0) {	    /* code 1100 */	    val = -10;	    len = 4;	} else if ((i & 0xF0) == 0xD0) {	    /* code 1101 */	    val = +10;	    len = 4;	} else if ((i & 0xF8) == 0xE0) {	    /* code 11100 */	    val = -15;	    len = 5;	} else if ((i & 0xF8) == 0xE8) {	    /* code 11101 */	    val = +15;	    len = 5;	} else if ((i & 0xFC) == 0xF0) {	    /* code 111100 */	    val = -20;	    len = 6;	} else if ((i & 0xFC) == 0xF4) {	    /* code 111101 */	    val = +20;	    len = 6;	} else if ((i & 0xF8) == 0xF8) {	    /* code 11111xxxxxx */	    is_abs = 1;	    val = 0;	    len = 5;	}	table[i].is_abs = is_abs;	table[i].val = val;	table[i].len = len;    }}static intpac_decompress_row(struct code_table_t *table, unsigned char *inp,		   unsigned char *outp, int width){    int col;    int val;    int bitpos;    unsigned char code;    /* first two pixels are stored as raw 8-bit */    *outp++ = inp[2];    *outp++ = inp[3];    bitpos = 32;    /* main decoding loop */    for (col = 2; col < width; col++) {	/* get bitcode */	code = getByte(inp, bitpos);	bitpos += table[code].len;	/* calculate pixel value */	if (table[code].is_abs) {	    /* absolute value: get 6 more bits */	    code = getByte(inp, bitpos);	    bitpos += 6;	    *outp++ = code & 0xFC;	} else {	    /* relative to left pixel */	    val = outp[-2] + table[code].val;	    *outp++ = CLIP(val);	}    }    /* return line length, rounded up to next 16-bit word */    return 2 * ((bitpos + 15) / 16);}static void tv8532_preprocess(struct spca50x_frame *myframe){/* we should received a whole frame with header and EOL markerin myframe->data and return a GBRG pattern in frame->tmpbuffer sequence 2bytes header the Alternate pixels bayer GB 4 bytes Alternate pixels bayer RG 4 bytes EOL */    int width = myframe->hdrwidth;    int height = myframe->hdrheight;    int src = 0;    unsigned char *dst = myframe->tmpbuffer;    unsigned char *data = myframe->data;    int i;    int seq1, seq2;    /* precompute where is the good bayer line */    if ((((data[src + 3] + data[src + width + 7]) >> 1) +	 (data[src + 4] >> 2) + (data[src + width + 6] >> 1)) >=	(((data[src + 2] + data[src + width + 6]) >> 1) +	 (data[src + 3] >> 2) + (data[src + width + 5] >> 1))) {	seq1 = 3;	seq2 = 4;    } else {	seq1 = 2;	seq2 = 5;    }    for (i = 0; i < height / 2; i++) {	src += seq1;	memcpy(dst, &myframe->data[src], width);	src += (width + 3);	dst += width;	memcpy(dst, &myframe->data[src], width);	src += (width + seq2);	dst += width;    }}static inline unsigned short getShort(unsigned char *pt){    return ((pt[0] << 8) | pt[1]);}static int pixart_decompress(struct spca50x_frame *myframe){/* we should received a whole frame with header and EOL markerin myframe->data and return a GBRG pattern in frame->tmpbufferremove the header then copy line by line EOL is set with 0x0f 0xf0 markeror 0x1e 0xe1 for compressed line*/    int width = myframe->hdrwidth;    int height = myframe->hdrheight;    unsigned char *outp = myframe->tmpbuffer;    unsigned char *inp = myframe->data;    struct code_table_t *table = myframe->decoder->table;    unsigned short word;    int row;    /* skip header */    inp += 16;    /* and ask to go at pixel +1 ?? */    outp++;    /* iterate over all rows */    for (row = 0; row < height; row++) {	word = getShort(inp);	switch (word) {	case 0x0FF0:	    memcpy(outp, inp + 2, width);	    inp += (2 + width);	    break;	case 0x1EE1:	    inp += pac_decompress_row(table, inp, outp, width);	    break;	default:	    return -1;	}	outp += width;    }    return 0;}#define PAC7311_JPEG_HEADER_SIZE 594#define PAC7311_JPEG_HEADER_GEO_START 12const unsigned char pac7311_jpeg_header[PAC7311_JPEG_HEADER_SIZE] = {  0xff, 0xd8, 0xff, 0xe0, 0x00, 0x03, 0x20, 0xff, 0xc0, 0x00,   0x11, 0x08, 0x01, 0xe0, 0x02, 0x80, 0x03, 0x01, 0x21, 0x00,   0x02, 0x11, 0x01, 0x03, 0x11, 0x01, 0xff, 0xdb, 0x00, 0x84,   0x00, 0x10, 0x0b, 0x0c, 0x0e, 0x0c, 0x0a, 0x10, 0x0e, 0x0d,   0x0e, 0x12, 0x11, 0x10, 0x13, 0x18, 0x28, 0x1a, 0x18, 0x16,   0x16, 0x18, 0x31, 0x23, 0x25, 0x1d, 0x28, 0x3a, 0x33, 0x3d,   0x3c, 0x39, 0x33, 0x38, 0x37, 0x40, 0x48, 0x5c, 0x4e, 0x40,   0x44, 0x57, 0x45, 0x37, 0x38, 0x50, 0x6d, 0x51, 0x57, 0x5f,   0x62, 0x67, 0x68, 0x67, 0x3e, 0x4d, 0x71, 0x79, 0x70, 0x64,   0x78, 0x5c, 0x65, 0x67, 0x63, 0x01, 0x11, 0x12, 0x12, 0x18,   0x15, 0x18, 0x2f, 0x1a, 0x1a, 0x2f, 0x63, 0x42, 0x38, 0x42,   0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,   0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,   0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,   0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,   0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,   0xff, 0xc4, 0x01, 0xa2, 0x00, 0x00, 0x01, 0x05, 0x01, 0x01,   0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,   0x09, 0x0a, 0x0b, 0x10, 0x00, 0x02, 0x01, 0x03, 0x03, 0x02,   0x04, 0x03, 0x05, 0x05, 0x04, 0x04, 0x00, 0x00, 0x01, 0x7d,   0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31,   0x41, 0x06, 0x13, 0x51, 0x61, 0x07, 0x22, 0x71, 0x14, 0x32,   0x81, 0x91, 0xa1, 0x08, 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52,   0xd1, 0xf0, 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,   0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a,   0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45,   0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57,   0x58, 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,   0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x83,   0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94,   0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,   0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,   0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,   0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8,   0xd9, 0xda, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8,   0xe9, 0xea, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,   0xf9, 0xfa, 0x01, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01,   0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,   0x0b, 0x11, 0x00, 0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04,   0x07, 0x05, 0x04, 0x04, 0x00, 0x01, 0x02, 0x77, 0x00, 0x01,   0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41,   0x51, 0x07, 0x61, 0x71, 0x13, 0x22, 0x32, 0x81, 0x08, 0x14,   0x42, 0x91, 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,   0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34, 0xe1, 0x25,   0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26, 0x27, 0x28, 0x29, 0x2a,   0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46,   0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,   0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a,   0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x82, 0x83,   0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94,   0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,   0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,   0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,   0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8,   0xd9, 0xda, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,   0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa,   0xff, 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03,   0x11, 0x00, 0x3f, 0x00};static int pac7311_make_jpg(struct spca50x_frame *myframe){/* we should received a whole frame with header and EOF markerin myframe->data and return a clean JPEG in frame->tmpbufferremove the header, the stream markers and the MCU markers andadd a correct JPEG header*/    int i;    int decrease_scanlenght;    char *pdatasave;    char *ptempsave;    pdatasave = myframe->data;    ptempsave = myframe->tmpbuffer;    if (*(myframe->data) != 0xFF && *(myframe->data+1) != 0xFF && *(myframe->data+2) != 0x00 && *(myframe->data+3) != 0xFF && *(myframe->data+4) != 0x96) {        myframe->scanlength = 0;        return -1;    }        memcpy(myframe->tmpbuffer, pac7311_jpeg_header, PAC7311_JPEG_HEADER_SIZE);    myframe->tmpbuffer += PAC7311_JPEG_HEADER_SIZE;    myframe->data += 7;    myframe->scanlength -= 7;    decrease_scanlenght = 7;    for (i=0;i<myframe->scanlength;++i) {        if (i < myframe->scanlength+4) {            if (*(myframe->data) == 0xff && *(myframe->data+1) == 0xff && *(myframe->data+2) == 0xff) {                myframe->data += 4;                decrease_scanlenght -= 4;            }        }        *myframe->tmpbuffer = *myframe->data;        myframe->tmpbuffer++;        myframe->data++;    }        myframe->data = pdatasave;    myframe->tmpbuffer = ptempsave;    myframe->scanlength += (PAC7311_JPEG_HEADER_SIZE + decrease_scanlenght);    memcpy(myframe->data, myframe->tmpbuffer, myframe->scanlength);    return 1;}static int jpeg_decode422_PAC7311(struct spca50x_frame *myframe, int force_rgb);static int pac7311_decode(struct spca50x_frame *myframe, int force_rgb){/* we should received a whole frame with header and EOF markerin myframe->data and return a decoded frame in frame->tmpbuffer*/    int i;    int done;    char *pdatasave;    char *ptempsave;    pdatasave = myframe->data;    ptempsave = myframe->tmpbuffer;    if (*(myframe->data) != 0xFF && *(myframe->data+1) != 0xFF && *(myframe->data+2) != 0x00 && *(myframe->data+3) != 0xFF && *(myframe->data+4) != 0x96) {        myframe->scanlength = 0;        return -1;    }        myframe->data += 7;    myframe->scanlength -= 7;    for (i=0;i<myframe->scanlength;++i) {        if (i < myframe->scanlength+4) {            if (*(myframe->data) == 0xff && *(myframe->data+1) == 0xff && *(myframe->data+2) == 0xff) {				if (*(myframe->data+3) == 0x00 || *(myframe->data+3) == 0x01 || *(myframe->data+3) == 0x02 ) {	                myframe->data += 4;				    myframe->scanlength -= 4;				} else {					PDEBUG(1, "Unknown FFFFFF marker value: 0x%2X", *(myframe->data+3));				}            }        }        *myframe->tmpbuffer = *myframe->data;        myframe->tmpbuffer++;        myframe->data++;    }        myframe->data = pdatasave;    myframe->tmpbuffer = ptempsave;    done = jpeg_decode422_PAC7311(myframe, force_rgb);    return done;}/*#	Decoder for compressed spca561 images			    		##	It was developed for "Labtec WebCam Elch 2(SPCA561A)" (046d:0929)	##	but it might work with other spca561 cameras				#*/static unsigned int bit_bucket;static unsigned char *input_ptr;static inline void refill(int *bitfill){    if (*bitfill < 8) {	bit_bucket = (bit_bucket << 8) | *(input_ptr++);	*bitfill += 8;    }}static inline int nbits(int *bitfill, int n){    bit_bucket = (bit_bucket << 8) | *(input_ptr++);    *bitfill -= n;    return (bit_bucket >> (*bitfill & 0xff)) & ((1 << n) - 1);}static inline int _nbits(int *bitfill, int n){    *bitfill -= n;    return (bit_bucket >> (*bitfill & 0xff)) & ((1 << n) - 1);}static int fun_A(int *bitfill){    int ret;    static int tab[] =	{ 12, 13, 14, 15, 16, 17, 18, 19, -12, -13, -14, -15, -16, -17,	-18, -19, -19    };    ret = tab[nbits(bitfill, 4)];    refill(bitfill);    return ret;}static int fun_B(int *bitfill){    static int tab1[] =	{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 31, 31,	31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 16, 17,	18,	19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30    };    static int tab[] =	{ 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, -5,	-6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17, -18, -19    };    unsigned int tmp;    tmp = nbits(bitfill, 7) - 68;    refill(bitfill);    if (tmp > 47)	return 0xff;    return tab[tab1[tmp]];}static int fun_C(int *bitfill, int gkw){    static int tab1[] =	{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 23, 23, 23, 23, 23, 23,	23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 12, 13,	14,	15, 16, 17, 18, 19, 20, 21, 22    };    static int tab[] =	{ 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, -9, -10, -11,	-12, -13, -14, -15, -16, -17, -18, -19    };    unsigned int tmp;    if (gkw == 0xfe) {	if (nbits(bitfill, 1) == 0)	    return 7;	else	    return -8;    }    if (gkw != 0xff)	return 0xff;    tmp = nbits(bitfill, 7) - 72;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -