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

📄 file_handling.c

📁 motion Jpeg 在SPI DSP平台优化好的代码
💻 C
字号:
////////////////////////////////////////////////////////////////////////////////////////////////////////                      file_handling.c ////      Notice:         COPYRIGHT (C) STREAM PROCESSORS, INC. 2005-2007//                      THIS PROGRAM IS PROVIDED UNDER THE TERMS OF THE SPI//                      END-USER LICENSE AGREEMENT (EULA). THE PROGRAM MAY ONLY//                      BE USED IN A MANNER EXPLICITLY SPECIFIED IN THE EULA,//                      WHICH INCLUDES LIMITATIONS ON COPYING, MODIFYING,//                      REDISTRIBUTION AND WARANTIES. UNAUTHORIZED USE OF THIS//                      PROGRAM IS STRICTLY PROHIBITED. YOU MAY OBTAIN A COPY OF//                      THE EULA FROM WWW.STREAMPROCESSORS.COM. //    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////          #includes ////////////////////////////////////////////////////////////////////////////////#include <stdio.h>#include <string.h>#include <stdlib.h>#include "spi_macros.h"#include "task_context.h"#include "jpeg_to_avi.h"//////////////////////////////////////////////////////////////////////////////////          Constants////////////////////////////////////////////////////////////////////////////////#define MAX_AVI_SIZE    (1000 * 1024 * 1024)//    Functions for writing input and output.int read_yuv(CHANNEL_CONTEXT_T *p_channel_context, unsigned char *p_data){    int     frame_size;    if (p_channel_context->format == SPI_VISUAL_FMT_YUV420)    {        frame_size = (p_channel_context->width * p_channel_context->height * 3) >> 1;    }    else     {        printf ("Error: Input format not supported\n");        return ERROR;    }    if (fread((char *)p_data, 1, frame_size, p_channel_context->f_yuv_file) != frame_size)    {        printf ("Reached end of file in %dth frames.\n", p_channel_context->frame_number);        if (p_channel_context->total_frames == -1)        {            rewind (p_channel_context->f_yuv_file);            if (fread((char *)p_data, 1, frame_size, p_channel_context->f_yuv_file) != frame_size)            {                printf(" Error: Not even single frame available for loopback in file - %s \n",p_channel_context->yuv_filename);                return ERROR;            }        }        else        {            p_channel_context->status = E_STOP;        }    }    return SUCCESS;}int write_jpeg(CHANNEL_CONTEXT_T *p_channel_context, unsigned char *p_data, int bs_size){    char    jpeg_filename[100];    FILE    *f_jpeg_file;	sprintf(jpeg_filename, "%s_%03d%s",p_channel_context->jpeg_filename, ((p_channel_context->frame_number-1) + p_channel_context->skip_count), ".jpg");    f_jpeg_file = fopen(jpeg_filename, "wb");    if (f_jpeg_file == NULL)     {        printf(" Error: Cannot open %s \n",jpeg_filename);        return ERROR;    }    if (fwrite((char *)p_data, 1, bs_size, f_jpeg_file) != bs_size)    {        printf ("Error: JPEG write failed\n");        return ERROR;    }    fclose(f_jpeg_file);    printf("JPEG file - %s of size = %d created.\n", jpeg_filename, bs_size);    return SUCCESS;}int open_avi_handle(CHANNEL_CONTEXT_T *p_channel_context){    AVI_SETTINGS_T      avi_settings;    if (spi_jpeg_to_avi_open(&p_channel_context->avi_handle) == ERROR)    {        printf ("AVI open failed\n\n\n");        return ERROR;    }    avi_settings.avi_filename   = p_channel_context->avi_filename;    avi_settings.width          = p_channel_context->width;    avi_settings.height         = p_channel_context->height;    avi_settings.fps            = p_channel_context->avi_fps;    if (spi_jpeg_to_avi_init(p_channel_context->avi_handle, &avi_settings) == ERROR)    {        printf ("AVI init failed\n");        return ERROR;    }    return SUCCESS;}int write_avi(CHANNEL_CONTEXT_T *p_channel_context, unsigned char *p_data, int bs_size){    AVI_INPUT_T         avi_input;    unsigned int        avi_size;    AVI_SETTINGS_T      avi_settings;    avi_input.input_data    = (char *)p_data;    avi_input.size          = bs_size;    ERR_HANDLE(spi_jpeg_to_avi_add(p_channel_context->avi_handle, &avi_input));    spi_jpeg_to_avi_get_avi_size(p_channel_context->avi_handle, &avi_size);    if (avi_size > MAX_AVI_SIZE)    {        printf(" Opening the AVI file again since the size exceeded 1GB limit.");        ERR_HANDLE (spi_jpeg_to_avi_close(p_channel_context->avi_handle));        if (spi_jpeg_to_avi_open(&p_channel_context->avi_handle) == ERROR)        {            printf ("AVI open failed\n\n\n");            return ERROR;        }        avi_settings.avi_filename   = p_channel_context->avi_filename;        avi_settings.width          = p_channel_context->width;        avi_settings.height         = p_channel_context->height;        avi_settings.fps            = p_channel_context->avi_fps;        if (spi_jpeg_to_avi_init(p_channel_context->avi_handle, &avi_settings) == ERROR)        {            printf ("AVI init failed\n");            return ERROR;        }        avi_input.input_data    = (char *)p_data;        avi_input.size          = bs_size;        ERR_HANDLE(spi_jpeg_to_avi_add(p_channel_context->avi_handle, &avi_input));    }    return SUCCESS;}

⌨️ 快捷键说明

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