当前位置:网站首页>Gif image analysis drawing RGB to YUV table lookup method to reduce CPU occupancy
Gif image analysis drawing RGB to YUV table lookup method to reduce CPU occupancy
2022-07-03 09:57:00 【Wukong is so timid】
/*
----------------------------------------------------------------------
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 (Graphic Control Extension)
This part is optional ( need 89a edition ), It can be placed in an image block ( Include image identifiers 、 Local color list and image data ) Or in front of a text extension , Used to control the first image following it ( Or the text ) Rendering of (Render) form , The composition is as follows :
BYTE 7 6 5 4 3 2 1 0 BIT
Extension block ID Extension Introducer - Identify that this is an extension block , Fixed value 0x21
Graphics control extension label Graphic Control Label - Identify that this is a graphics control extension , Fixed value 0xF9
Block size Block Size - Block terminators are not included , Fixed value 4
Retain How to deal with it i
t
i - User input flag ;t - Transparent color logo .
Delay time Delay Time - Company 1/100 second , If the value is not 1, It means to suspend the specified time before continuing to process the data stream
Transparent color index Transparent Color Index - Transparent color index value
Block Terminator Block Terminator - Identifies the end of the block , Fixed value 0
How to deal with it (Disposal Method): Indicate how to dispose of graphics , The duty of :
0 - Do not use disposal method
1 - Do not dispose of drawings , Move the graph from its current position
2 - Revert to background color
3 - Return to the previous state
4-7 - Customize
User input flag (Use Input Flag): Indicate whether to expect the user to enter before continuing , Set... To indicate expectation , A value of no indicates that... Is not expected . User input can be by pressing enter 、 Mouse click, etc , Can be used with delay time , If the user has input within the set delay time, it will continue immediately , Or continue without input until the delay time arrives
Transparent color logo (Transparent Color Flag): Set indicates the use of transparent colors
*/
//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();// Draw a frame immediately for the first time , Lest there be a green flower screen
while(err != TERMINATE_RECORD_ERROR && err != IMAGE_DESC_RECORD_TYPE)
//while(err != IMAGE_DESC_RECORD_TYPE)
{
err = gif_time_callback_osd();// Draw a frame immediately for the first time , Lest there be a green flower screen , Until the interface of drawing the first frame is called
//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();// Draw a frame immediately for the first time , Lest there be a green flower screen
while(err != TERMINATE_RECORD_ERROR && err != IMAGE_DESC_RECORD_TYPE)
//while(err != IMAGE_DESC_RECORD_TYPE)
{
err = gif_time_callback_osd();// Draw a frame immediately for the first time , Lest there be a green flower screen , Until the interface of drawing the first frame is called
//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);
}
// Logically, we should ensure GifData.time_id Certainly more than 0, Before GifData.time_id Request timer
//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(" No GIF Format picture \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();// Draw a frame immediately for the first time , Lest there be a green flower screen
//while(err != TERMINATE_RECORD_ERROR && err != IMAGE_DESC_RECORD_TYPE)
while(err != IMAGE_DESC_RECORD_TYPE)
{
err = gif_time_callback_osd();// Draw a frame immediately for the first time , Lest there be a green flower screen , Until the interface of drawing the first frame is called
}
// 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;
}
边栏推荐
- Which language should I choose to program for single chip microcomputer
- Learn the contents of 5g toolbox supporting NR through the NR resources provided by MATLAB
- Application of 51 single chip microcomputer timer
- [CSDN] C1 training problem analysis_ Part II_ Web Foundation
- STM32 general timer 1s delay to realize LED flashing
- 03 FastJson 解决循环引用
- 2020-08-23
- MySQL 数据库基础知识(系统化一篇入门)
- [combinatorics] Introduction to Combinatorics (combinatorial thought 2: mathematical induction | mathematical induction promotion | multiple induction thought)
- Hal library sets STM32 clock
猜你喜欢
单片机职业发展:能做下去的都成牛人了,熬不动就辞职或者改行了
SCM career development: those who can continue to do it have become great people. If they can't endure it, they will resign or change their careers
STM32 external interrupt experiment
UCI and data multiplexing are transmitted on Pusch - Part I
Basic knowledge of communication interface
Idea remote breakpoint debugging jar package project
Notes on C language learning of migrant workers majoring in electronic information engineering
In third tier cities and counties, it is difficult to get 10K after graduation
I didn't think so much when I was in the field of single chip microcomputer. I just wanted to earn money to support myself first
嵌入式本来就很坑,相对于互联网来说那个坑多得简直是难走
随机推荐
[22 graduation season] I'm a graduate yo~
el-table X轴方向(横向)滚动条默认滑到右边
2021-01-03
Do you understand automatic packing and unpacking? What is the principle?
Fundamentals of Electronic Technology (III)_ Integrated operational amplifier and its application__ Basic arithmetic circuit
[untitled] proteus simulation of traffic lights based on 89C51 Single Chip Microcomputer
There is no shortcut to learning and development, and there is almost no situation that you can learn faster by leading the way
MySQL 数据库基础知识(系统化一篇入门)
Project cost management__ Cost management technology__ Article 6 prediction
I think all friends should know that the basic law of learning is: from easy to difficult
Install local sources using yum
Runtime.getRuntime().gc() 和 Runtime.getRuntime().runFinalization() 的区别
Uniapp realizes global sharing of wechat applet and custom sharing button style
You need to use MySQL in the opening experiment. How can you forget the basic select statement? Remedy is coming~
在三线城市、在县城,很难毕业就拿到10K
【力扣刷题笔记(二)】特别技巧,模块突破,45道经典题目分类总结,在不断巩固中精进
学历是一张通行证,门票,你有了它,可以踏入更高层次的环境里
Electronic product design
UCI and data multiplexing are transmitted on Pusch - placement of data and UCI positions (Part III)
Project cost management__ Cost management technology__ Article 7 completion performance index (tcpi)