gif 图片解析绘图 RGB 转YUV 查表法 ,降低CPU占有率
【摘要】
/*----------------------------------------------------------------------File : GIFPICTURE.cPurpose : Implementation of picture widget-------------------------...
-
/*
-
----------------------------------------------------------------------
-
File : GIFPICTURE.c
-
Purpose : Implementation of picture widget
-
---------------------------END-OF-HEADER------------------------------
-
*/
-
-
#include <stdlib.h>
-
#include <string.h>
-
#include "gif_lib.h"
-
#include "pf_layer.h"
-
#include "mod_date_time.h"
-
#include "mod_time_list.h"
-
#include "gxdemux.h"
-
#include "gxvideo.h"
-
#include "gxaudio.h"
-
#include "sys_assert.h"
-
#include "gxdisp.h"
-
#include "stb_app.h"
-
#include "media_type.h"
-
#include "gxdenc.h"
-
#include "gxvmix.h"
-
#include "av.h"
-
typedef struct GifColorPalette
-
{
-
ByteType Red, Green, Blue;
-
} GifColorPalette;
-
-
typedef struct {
-
U16 time_id;
-
GifFileType *GifFile;
-
const U8* pGifData;
-
//unsigned int palette[256];
-
GifColorPalette palette[256];
-
U32 nTransColor;
-
U32 CurrentImage;
-
} GifData_t;
-
#include "GUIType.h"
-
extern unsigned char ad_pic_osd_buffer[178*100];
-
extern GUI_CONST_STORAGE GUI_BITMAP ad_pic_osd_struct ;
-
-
static GifData_t GifData;
-
//extern unsigned short g_SppBuffer[700 * 576 ];
-
-
static int InterlacedOffset[] = { 0, 4, 2, 1 }, InterlacedJumps[] = { 8, 8, 4, 2 };
-
//extern BOOL bAdShowFlag;
-
//extern U32 nCapturePpNum;
-
static unsigned short int gif_period_time=0;
-
//unsigned short disposal_mothod=0;
-
-
-
#if 0
-
static unsigned char y_r[256];
-
static unsigned char y_g[256];
-
static unsigned char y_b[256];
-
static unsigned char u_r[256];
-
static unsigned char u_g[256];
-
static unsigned char u_b[256];
-
static unsigned char v_r[256];
-
static unsigned char v_g[256];
-
static unsigned char v_b[256];
-
static void gif_init_Palette(void)
-
{
-
int i=0;
-
for(i=0;i<256;i++)
-
{
-
#if 0
-
y_r[i]=66 * i/ 256;
-
u_r[i]=38* i/ 256;
-
v_r[i]=112 * i/ 256;
-
y_g[i]=129* i/ 256;
-
u_g[i]=74 * i/ 256;
-
v_g[i]=94 * i/ 256;
-
y_b[i]=25* i/ 256;
-
u_b[i]=112 * i/ 256;
-
v_b[i]=18 * i/ 256;
-
#else
-
y_r[i]=(66 * i)>>8;
-
u_r[i]=(38* i)>>8;
-
v_r[i]=(112 * i)>>8;
-
y_g[i]=(129* i)>>8;
-
u_g[i]=(74 * i)>>8;
-
v_g[i]=(94 * i)>>8;
-
y_b[i]=(25* i)>>8;
-
u_b[i]=(112 * i)>>8;
-
v_b[i]=(18 * i)>>8;
-
#endif
-
}
-
}
-
#endif
-
static int gif_time_callback_osd(void)
-
{
-
//*(volatile int*)0x40005028 |= (1<<1);
-
GifFileType *GifFile=GifData.GifFile;
-
int i, j,ExtCode=0,Len,Row, Col, Width, Height,Count, RealWidth;
-
GifRecordType RecordType;
-
ByteType *Extension;
-
unsigned char r,g,b ;
-
//unsigned short y2,u,v;//add for trans
-
//unsigned int y = 0,cb0=0,cr0 = 0;
-
//unsigned short cby = 0,cry = 0;
-
//unsigned short *pPicUse = (unsigned short*)g_SppBuffer;
-
PixelType *Line;
-
#if 0
-
int color;
-
unsigned int CurrentImagePalette[256];
-
#else
-
GifColorPalette Current_GifColorPalette[256]={{0,},};
-
GifColorPalette color={0,};
-
#endif
-
-
// unsigned char nDelayTime=0;
-
//SYS_PRINTF("case gif_time_callback\n");
-
-
-
if (DGifGetRecordType(GifFile, &RecordType) == ERROR) {
-
return TERMINATE_RECORD_ERROR;
-
}
-
GifFile->SWidth= ((GifFile->SWidth % 2) ? (GifFile->SWidth - 1) : (GifFile->SWidth));
-
switch (RecordType) {
-
case IMAGE_DESC_RECORD_TYPE:
-
-
//SYS_PRINTF("case IMAGE_DESC_RECORD_TYPE\n");
-
-
if (DGifGetImageDesc(GifFile) == ERROR) {
-
-
// SYS_PRINTF("DGifGetImageDesc(GifFile) == ERROR \n");
-
-
return TERMINATE_RECORD_ERROR;
-
}
-
SYS_PRINTF("pic CurrentImage = %d ITop=%d ILeft=%d IWidth=%d IHeight=%d \n", GifData.CurrentImage, GifFile->ITop, GifFile->ILeft, GifFile->IWidth, GifFile->IHeight );
-
-
if ( GifFile->IColorMap)
-
{
-
SYS_PRINTF("pic use IColorMap \n");
-
Len = 1 << GifFile->SBitsPerPixel;
-
for (i = 0; i < Len; i++)
-
{
-
Current_GifColorPalette[i].Blue=GifFile->IColorMap[i].Blue;
-
Current_GifColorPalette[i].Green=GifFile->IColorMap[i].Green;
-
Current_GifColorPalette[i].Red=GifFile->IColorMap[i].Red;
-
}
-
}
-
else
-
{
-
SYS_PRINTF("pic use SColorMap \n");
-
memcpy(Current_GifColorPalette, GifData.palette, 256*sizeof(GifColorPalette));
-
}
-
Line = (PixelType *) malloc(GifFile->IWidth *sizeof(PixelType));
-
-
Row = GifFile->ITop; /* Image Position relative to Screen */
-
Col = GifFile->ILeft;
-
Width = GifFile->IWidth;
-
Height = GifFile->IHeight;
-
{
-
RealWidth = (GifFile->IWidth % 2)?(GifFile->IWidth - 1):GifFile->IWidth;
-
-
for (i=0; i< GifFile->IHeight; i++)
-
{
-
if (DGifGetLine(GifFile, Line, GifFile->IWidth) == ERROR)
-
{
-
//SYS_PRINTF("pic DGifGetLine ERROR\n");
-
return TERMINATE_RECORD_ERROR;
-
}
-
-
//SYS_PRINTF("%d %d %d \n", GifData.palette[Line[10]], GifData.palette[Line[13]], GifData.palette[Line[45]]);
-
-
for(j = 0; j < RealWidth; j++)
-
{
-
-
if(GifData.CurrentImage == 0)
-
{
-
//if(Line[j] != GifData.nTransColor)
-
ad_pic_osd_buffer[(GifFile->ITop+i)*GifFile->SWidth + GifFile->ILeft + j ]=Line[j];
-
//else
-
//ad_pic_osd_buffer[(GifFile->ITop+i)*GifFile->SWidth + GifFile->ILeft + j ]=0;
-
-
}
-
else
-
{
-
-
//if(Line[j] != GifData.nTransColor)
-
{
-
ad_pic_osd_buffer[(GifFile->ITop+i)*GifFile->SWidth + GifFile->ILeft + j ]=Line[j];
-
}
-
-
}
-
}
-
}
-
-
}
-
free(Line);
-
GifData.CurrentImage++;
-
return IMAGE_DESC_RECORD_TYPE;
-
-
break;
-
case EXTENSION_RECORD_TYPE:
-
/*图形控制扩展(Graphic Control Extension)
-
这一部分是可选的(需要89a版本),可以放在一个图象块(包括图象标识符、局部颜色列表和图象数据)或文本扩展块的前面,用来控制跟在它后面的第一个图象(或文本)的渲染(Render)形式,组成结构如下:
-
-
BYTE 7 6 5 4 3 2 1 0 BIT
-
扩展块标识 Extension Introducer - 标识这是一个扩展块,固定值0x21
-
图形控制扩展标签 Graphic Control Label - 标识这是一个图形控制扩展块,固定值0xF9
-
块大小 Block Size - 不包括块终结器,固定值4
-
保留 处置方法 i
-
t
-
i - 用户输入标志;t - 透明色标志。
-
延迟时间 Delay Time - 单位1/100秒,如果值不为1,表示暂停规定的时间后再继续往下处理数据流
-
-
透明色索引 Transparent Color Index - 透明色索引值
-
块终结器 Block Terminator - 标识块终结,固定值0
-
-
处置方法(Disposal Method):指出处置图形的方法,当值为:
-
0 - 不使用处置方法
-
1 - 不处置图形,把图形从当前位置移去
-
2 - 回复到背景色
-
3 - 回复到先前状态
-
4-7 - 自定义
-
用户输入标志(Use Input Flag):指出是否期待用户有输入之后才继续进行下去,置位表示期待,值否表示不期待。用户输入可以是按回车键、鼠标点击等,可以和延迟时间一起使用,在设置的延迟时间内用户有输入则马上继续进行,或者没有输入直到延迟时间到达而继续
-
透明颜色标志(Transparent Color Flag):置位表示使用透明颜色
-
-
*/
-
//SYS_PRINTF("case EXTENSION_RECORD_TYPE\n");
-
if (DGifGetExtension(GifFile, &ExtCode, &Extension) == ERROR) {
-
-
return TERMINATE_RECORD_ERROR;
-
}
-
if(ExtCode == 0xF9)
-
{
-
// SYS_PRINTF("Extension[1]=0x%x\n",Extension[1]);
-
//disposal_mothod=(Extension[1]&0x1c)>>2;
-
if((Extension[1] & 0x01) == 1)
-
{
-
GifData.nTransColor = Extension[4];//nClut;
-
SYS_PRINTF("GifData.nTransColor=0x%x\n",GifData.nTransColor);
-
}
-
gif_period_time = (Extension[3]<<8)|Extension[2];
-
-
}
-
while (Extension != NULL) {
-
if (DGifGetExtensionNext(GifFile, &Extension) == ERROR) {
-
-
return TERMINATE_RECORD_ERROR;
-
}
-
}
-
-
return EXTENSION_RECORD_TYPE;
-
-
break;
-
case TERMINATE_RECORD_TYPE:
-
//SYS_PRINTF("case TERMINATE_RECORD_TYPE\n");
-
GifData.CurrentImage = 0;
-
GifData.nTransColor=0;
-
DGifSetCurrentData(GifFile, GifData.pGifData);
-
return TERMINATE_RECORD_TYPE;
-
break;
-
default: /* Should be traps by DGifGetRecordType */
-
break;
-
}
-
-
return TERMINATE_RECORD_ERROR;
-
}
-
int gif_drow_one_frame_osd(void);
-
int gif_drow_other_frame_osd(void);
-
-
int gif_drow_one_frame_osd(void)
-
{
-
int err;
-
err = gif_time_callback_osd();//第一次立刻画出一帧,免得出现绿色花屏
-
while(err != TERMINATE_RECORD_ERROR && err != IMAGE_DESC_RECORD_TYPE)
-
//while(err != IMAGE_DESC_RECORD_TYPE)
-
{
-
err = gif_time_callback_osd();//第一次立刻画出一帧,免得出现绿色花屏,直到调用画第一帧图像接口
-
//if(err == TERMINATE_RECORD_ERROR )
-
//return 0;
-
}
-
-
return 1;
-
}
-
int gif_drow_other_frame_osd(void)
-
{
-
int err;
-
//*(volatile int*)0x40005028 |= (1<<1);
-
#if 0
-
if(GifData.time_id)
-
{
-
time_release(GifData.time_id);
-
GifData.time_id = 0;
-
}
-
#endif
-
err = gif_time_callback_osd();//第一次立刻画出一帧,免得出现绿色花屏
-
while(err != TERMINATE_RECORD_ERROR && err != IMAGE_DESC_RECORD_TYPE)
-
//while(err != IMAGE_DESC_RECORD_TYPE)
-
{
-
err = gif_time_callback_osd();//第一次立刻画出一帧,免得出现绿色花屏,直到调用画第一帧图像接口
-
//if(err == TERMINATE_RECORD_ERROR )
-
//return 0;
-
}
-
// SYS_PRINTF("gif_period_time= %d \n", gif_period_time);
-
if(gif_period_time==0)
-
{
-
gif_drow_one_frame_osd();
-
// err = time_register(gif_drow_one_frame_osd, 4000, 1, ONCE_TIME, TIME_RUN_MODE_ISR, &GifData.time_id);
-
}
-
else
-
{
-
//err = time_register(gif_drow_one_frame_osd, gif_period_time*10, 1, ONCE_TIME, TIME_RUN_MODE_ISR, &GifData.time_id);
-
}
-
//逻辑上要保证 GifData.time_id 肯定大于0,要有先于GifData.time_id申请定时器
-
//time_start(GifData.time_id);
-
//SYS_PRINTF("GifData.time_id = %d \n", GifData.time_id);
-
return 1;
-
}
-
GifFileType *GifFile;
-
inline int com_gif_draw_osd(unsigned char* pGifData,int x0,int y0)
-
{
-
int i, j,err,Len;
-
Window_Para_t window;
-
//U16 time_id = 0;
-
-
GifData.nTransColor=0;
-
GifData.CurrentImage = 0;
-
GifFile=GifData.GifFile = DGifOpenFileName(pGifData);
-
if(GifFile == NULL)
-
{
-
SYS_PRINTF("不是GIF格式图片\n");
-
return 0;
-
}
-
-
GifData.pGifData = DGifGetCurrentData(GifFile);
-
-
// window.PositionX=x0;
-
// window.PositionY=y0;
-
-
ad_pic_osd_struct.XSize=GifFile->SWidth;
-
ad_pic_osd_struct.YSize=GifFile->SHeight;
-
-
GifFile->SWidth=(GifFile->SWidth % 2) ? (GifFile->SWidth - 1) : (GifFile->SWidth);
-
// window.Width=GifFile->SWidth;
-
// window.Height=GifFile->SHeight;
-
-
if ( GifFile->SColorMap)
-
{
-
Len = 1 << GifFile->SBitsPerPixel;
-
for (i = 0; i < Len; i++)
-
{
-
-
GifData.palette[i].Blue=GifFile->SColorMap[i].Blue;
-
GifData.palette[i].Green=GifFile->SColorMap[i].Green;
-
GifData.palette[i].Red=GifFile->SColorMap[i].Red;
-
}
-
}
-
//5000 old
-
-
err = gif_time_callback_osd();//第一次立刻画出一帧,免得出现绿色花屏
-
//while(err != TERMINATE_RECORD_ERROR && err != IMAGE_DESC_RECORD_TYPE)
-
while(err != IMAGE_DESC_RECORD_TYPE)
-
{
-
err = gif_time_callback_osd();//第一次立刻画出一帧,免得出现绿色花屏,直到调用画第一帧图像接口
-
}
-
// SYS_PRINTF("gif_period_time= %d \n", gif_period_time);
-
-
//if(gif_period_time==0)
-
//{
-
// gif_drow_one_frame_osd();
-
//err = time_register(gif_drow_one_frame_osd, 4000, 1, ONCE_TIME, TIME_RUN_MODE_ISR, &GifData.time_id);
-
//}
-
-
return 1;
-
-
-
}
-
-
文章来源: blog.csdn.net,作者:悟空胆好小,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/xushx_bigbear/article/details/122730997
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)