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

📄 cmjpghdr.c

📁 Abstract—Wireless networks in combination with image sensors open up a multitude of previously unth
💻 C
字号:
/* * Module:  cmJpgHdr * * Description:  Attach a jpeg header to jpeg data. * */#include <stdio.h>#include <stdlib.h>#include <windows.h>		/* data type type defs */#include "cmJpgHdr.h"#include "qtables.h"#include "jpgHeader.h"#include "cmApi.h"extern Image_t g_defaultVideo;extern Image_t g_defaultStill;/* * global data   all of the following must be fixed up later */long int m_qtd = 0;     /* offset in qtable to get ctable *///long int m_width = 0;        /* width in pixels *///long int m_height = 0;       /* height in pixels *///long int m_width_still = 0;  /* width in pixels *///long int m_height_still = 0; /* height in pixels *//* W A R N I N G ---- The jpeg mode is set here but it really depends upon the   settings in the VIDEO and STILL configuration registers.  In a future    revision, this information will be passed in as a parameter */int jpeg_mode = 1;                      /* jpeg compression 0 = grey, 1 = 444, 2=422 *//* * Function: cmJpgHdrBuild * * Inputs: *      jpeg_data       The buffer containing the 1670 jpeg data *      length          Number of bytes of data *      whole_jpg       The final destination buffer pointer *      whole_jpg_len   The pointer to the final length *      type            The API Image type (jpeg 444, 422 or GRAY) *      width           The width (X in pixels) *      height          The height (Y in pixels) * * Outputs: *      whole_jpg       Updated with the header plus the jpg data *      whole_jpg_len   Updated with the length of the jpg data with header * * Returns:  void (there is no way for it  to fail in this routine. Any failure is  *           catastrophic.) * */void cmJpgHdrBuild(unsigned char *jpeg_data, int length, unsigned char *whole_jpg, int *whole_jpg_len, ImageType_t type, int width, int height){    unsigned char Yqtable = jpeg_data[4];    unsigned char Cqtable = Yqtable + (unsigned char)m_qtd;  // add qtable delta to Yqtable to get Cqtable    unsigned char *Yqtable_ptr  = qtable_list[Yqtable];    unsigned char *Cqtable_ptr  = qtable_list[Cqtable];    int header_length;    BYTE *header;    if (type == CM_TYPE_JPEGGREY) {        // grayscale        // copy table to header        memcpy(header_gray.QTABLE0 + 5, Yqtable_ptr, 64);        // set image size in header        //        header_gray.SOF0[5] = (height >> 8) & 0xff;        header_gray.SOF0[6] = (height) & 0xff;        header_gray.SOF0[7] = (width >> 8) & 0xff;        header_gray.SOF0[8] = (width) & 0xff;        header = (UCHAR *) &header_gray;        header_length = sizeof(header_gray);    }    else if (type == CM_TYPE_JPEG444) {        // 444        // copy tables to header        memcpy(header_4xx.QTABLE0 + 5, Yqtable_ptr, 64);        memcpy(header_4xx.QTABLE1 + 5, Cqtable_ptr, 64);        memcpy(header_4xx.QTABLE2 + 5, Cqtable_ptr, 64);        // set image size in header        //        header_4xx.SOF0[5] = (height >> 8) & 0xff;        header_4xx.SOF0[6] = (height) & 0xff;        header_4xx.SOF0[7] = (width >> 8) & 0xff;        header_4xx.SOF0[8] = (width) & 0xff;        header_4xx.SOF0[11] = 0x11;   // 444        header = (UCHAR *) &header_4xx;        header_length = sizeof(header_4xx);    } else if (type == CM_TYPE_JPEG422) {        // 422        // copy tables to header        memcpy(header_4xx.QTABLE0 + 5, Yqtable_ptr, 64);        memcpy(header_4xx.QTABLE1 + 5, Cqtable_ptr, 64);        memcpy(header_4xx.QTABLE2 + 5, Cqtable_ptr, 64);        // set image size in header        //        header_4xx.SOF0[5] = (height >> 8) & 0xff;        header_4xx.SOF0[6] = (height) & 0xff;        header_4xx.SOF0[7] = (width >> 8) & 0xff;        header_4xx.SOF0[8] = (width) & 0xff;        header_4xx.SOF0[11] = 0x21;   // 422        header = (UCHAR *) &header_4xx;        header_length = sizeof(header_4xx);    }    else {        return;    }    //length = length - 7;  // subtract leading 5 bytes & trailing status byte    length = length - 5;  // subtract leading 5 bytes & trailing status byte    // build image    //    memcpy(whole_jpg,header,header_length);    memcpy(whole_jpg+header_length,jpeg_data+5,length);	*whole_jpg_len = header_length + length;	/* global variable write */}

⌨️ 快捷键说明

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