📄 myprogram.txt
字号:
/**********************************************************
* Copyright (C), 2003-2004, Dahua Tech Co. Ltd
* FileName: mainstream.c
* Version: 1.0 Date: 2004-11-24 Author: George
* Description: 主函数入口,实现主要接口
* History:
**********************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tmMainStreaming.h>
#include <psos.h>
#include <mmio.h>
#include <math.h>
#include "./dhdvp1500/include/type.h"
#include "./dhdvp1500/avsetup/inc/videosetup.h"
//#include "./dhdvp1500/record/inc/AVRecord.h"
//#include "./dhdvp1500/fat32/inc/DHMAPI.h"
//#include "./dhdvp1500/fat32/inc/AVIAPI.h"
#include <tmml.h>
#include <tmhwDraw.h>
//#include "./System/SysIniti.h"
//#include "./System/AVBuf.h"
//#include "./NetSvr/TcpSvr.h"
#include "./dhdvp1500/api/inc/GUIDriver.h"
//#include "./GUISvr/uimain.h"
//#include "./dhdvp1500/avplay/inc/mediaplay.h"
//#include "./System/Play.h"
//#include "./System/HardMsg.h"
//#include "./System/Play.h"
//#include "./System/USBDev.h"
//extern PREVIEW g_Preview;
#include "graphics.h"
int g_VideoInstance;
int g_RecordInstance;
int g_iState = 0;
extern void UpdateDT(void *p);
//------------------------------------------------------------------------------
#define PRNT_ERRINFO //输出信息控制 */
#define PRNT_DEBUGINFO
#define TESTDELAY //测试时加入延时控制
#define WholeBMP //动画显示数据转换函数输入控制位:定义WholeBMP表示输入的为完整的BMP图像地址
//若未定义WholeBMP则表示输入的参数为索引颜色表地址和位图数据地址
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600
#define SCREEN_VTF vtfRGB // dataType
#define SCREEN_VCF vcfXRGB8888 //subdataType
#define SCREEN_VDF 0 //description
#define SCREEN_BITS_PER_PIXEL 32
#define SCREEN_BYTES_PER_PIXEL 4
#define SCREEN_VTFINDEX vtfCLUT
#define SCREEN_VCFINDEX vdfRGBCLUT8bpp
#define SCREEN_VDFINDEX 0
#define SCREEN_BITS_PER_PIXEL_INDEX 8
#define SCREEN_BYTES_PER_PIXEL 1
#define ERR_RETURN 0 //函数出错返回值
#define SUCCESS_RETURN 1 //成功调用返回
#define MAX(x,y) (((x) > (y)) ? (x) : (y))
#define MIN(x,y) (((x) < (y)) ? (x) : (y))
#define RtlZeroMemory(Destination,Length) memset((Destination),0,(Length))
#define ZeroMemory RtlZeroMemory
int InitFlg = 0; //初始化标志
//tmErrorCode_t errcode;
tmhwDrawable_t *pScreen;
tmhwUnkColor_t clr;
UINT8 *pVideoBuffer;
UInt8 *Index_color;
UInt32 *pIndex1;
UInt32 *pIndex2;
//========================================================================//
typedef struct
{ BOOL active;
UINT disposalMethod;
BOOL userInputFlag;
BOOL trsFlag;
WORD delayTime;
UINT trsColorIndex;
}GCTRLEXT;
typedef struct
{ WORD imageLPos;
WORD imageTPos;
WORD imageWidth;
WORD imageHeight;
BOOL lFlag;
BOOL interlaceFlag;
BOOL sortFlag;
UINT lSize;
BYTE *pColorTable;
BYTE *dataBuf;
GCTRLEXT ctrlExt;
}FRAME;
typedef FRAME *LPFRAME;
typedef const FRAME *LPCFRAME;
typedef struct
{ UINT frames;
WORD scrWidth,scrHeight;
BOOL gFlag;
UINT colorRes;
BOOL gSort;
UINT gSize;
UINT BKColorIdx;
UINT pixelAspectRatio;
BYTE *gColorTable;
}GLOBAL_INFO;
typedef GLOBAL_INFO *LPGLOBAL_INFO;
typedef const GLOBAL_INFO *LPCGLOBAL_INFO;
typedef struct
{ UINT len;
unsigned char* p;
}STRING_TABLE_ENTRY;
char version[4];
BOOL error;
BOOL opened = FALSE;
BOOL inMem;
BYTE gColorTable[256*3];
BYTE lColorTable[256*3];
UInt8 *dataStart;
FRAME *allFrames;
UINT curIndex;
GLOBAL_INFO gInfo;
FRAME curFrame;
GCTRLEXT ctrlExt;
//------------------------------------------------------------------------//
tmRect_t fillarea=
{
{0,0},
{600,600}
//{20,20},
//{400,400}
};
tmRect_t fillarea2=
{
{150,150},
{500,500}
//{20,20},
//{400,400}
};
tmRect_t clrarea=
{
{0,0},
{320,320}
};
static const tmXY_t centre =
{
200,200
};
static tmRect_t screen =
{
{0, 0},
{SCREEN_WIDTH, SCREEN_HEIGHT}
};
static const tmXY_t start =
{
0,10
};
static const tmXY_t end =
{
100,10
};
static const tmXY_t start1 =
{
0,300
};
static const tmXY_t end1 =
{
750,300
};
static const tmXY_t start2 =
{
50,100
};
static const tmXY_t end2 =
{
750,500
};
static const tmXY_t start3 =
{
50,500
};
static const tmXY_t end3 =
{
750,100
};
static const tmXY_t dot[]=
{
{550,550},
{580,580},
{600,550},
{650,550},
{700,550},
{750,550}
};
static tmXY_t dotfill[800][600]=
{
{0,0}
};
tmXY_t dstXY =
{
200,200
};
#define PCOLOR(r, g, b) ( \
0xff000000 \
| (((r) << 16) & 0x00ff0000u) \
| (((g) << 8) & 0x0000ff00u) \
| (((b) ) & 0x000000ffu) \
)
static tmhwDrawBitsRef_t hPixel;
UInt8 *VideoGetOsdBuf(void);
//-----------------------------------------------------------------------------------------------------
//函数名: Index_DataConvert
//输 入: ChanDirect , pixel_width , pixel_height,pCol,pImageData
//输 出: 指向经过处理后的数据缓存区的首地址
//完成人: nxf
//完成日期: 2005-6-2
//描 述: 完成对图像数据格式的排列,转换成4字节对齐的方式并返回。当输入指针指向的BMP图像为完整图像数据
//时,若定义了WholeBMP,则只接收该指针值,否则,若没有定义WholeBMP,调用本函数时须同时指定索引颜色表的首
//地址和位图数据起始指针。
//参数说明:
// 1.ChanDirect - 颜色通道顺序选择. 0:通道顺序为R->G->B. 1:通道顺序为B->G->R.
// 2.pixel_width - 图像的像素宽度.
// 3.pixel_height - 图像的像素高度.
// 4.pImageData - 指向原始图像数据的指针.
//------------------------------------------------------------------------------------------------------
#ifdef WholeBMP
UINT32 *Index_DataConvert(UInt8 ChanDirect,int pixel_width,int pixel_height,UInt8 *pBMP)
#else
UINT32 *Index_DataConvert(UInt8 ChanDirect,int pixel_width,int pixel_height,UInt8 *pCol,UInt8 *pImgData)
#endif
{
int i=0,j=0;
UInt8 *imagealpha=NULL;
UInt32 *pDbWordData=NULL;
UInt8 appbits;
#ifdef WholeBMP //输入参数为完整BMP图像的首指针(包括BMP头信息)
UInt8 *pCol;
UInt8 *pImgData;
UInt32 offs; //BMP图像首地址到位图数据的偏移
pCol = 54 + pBMP; //索引颜色表的首址
offs = ((*(pBMP + 13))<<24) + ((*(pBMP + 12))<<16) + \
((*(pBMP + 11))<<8) + ((*(pBMP + 10)));
pImgData = pBMP + offs;
#endif
if((pixel_width)%4) //图象宽度不是4字节对齐
appbits = 4 - ((pixel_width)%4); //补齐的字节数
if(!(imagealpha = (UInt8 *)malloc(pixel_width * pixel_height *4)))
return NULL;
if(!(pDbWordData = (UInt32 *)malloc(pixel_width * pixel_height*4)))
return NULL;
for(i =0; i < pixel_width*pixel_height; i++)
{
Index_color = pCol + 4*(*(pImgData + i)); //4字节索引颜色的首地址
if(appbits!=4)
{
if((i+1)%pixel_width)
{
if(!ChanDirect)//输入R->G->B转化为4字节对齐(alpha + R + G + B)
pDbWordData[i] = (0xff<<24) + ((*(Index_color++))<<16) +((*(Index_color++))<<8) +((*(Index_color++)));
else //输入B->G->R转化为4字节对齐(alpha + R + G + B)
pDbWordData[i] = (0xff<<24) + ((*(Index_color++))) +((*(Index_color++))<<8) +((*(Index_color++))<<16);
}
else
{
if(!ChanDirect)
pDbWordData[i] = (0xff<<24) + ((*(Index_color++))<<16) +((*(Index_color++))<<8) +((*(Index_color++)));
else
pDbWordData[i] = (0xff<<24) + ((*(Index_color++))) +((*(Index_color++))<<8) +((*(Index_color++))<<16);
pImgData = pImgData + appbits;
}
}
else
{
for(i=0; i < pixel_height*pixel_width; i++)
{
if(!ChanDirect)
pDbWordData[i] = (0xff<<24) + ((*(Index_color++))<<16) +((*(Index_color++))<<8) +((*(Index_color++)));
else
pDbWordData[i] = (0xff<<24) + ((*(Index_color++))) +((*(Index_color++))<<8) +((*(Index_color++))<<16);
}
}
}
free(imagealpha);
return pDbWordData;
}
//-----------------------------------------------------------------------------------------------------
//函数名: DataConvert
//输 入: ChanDirect , pixel_width , pixel_height
//输 出: 指向经过处理后的数据缓存区的首地址
//完成人: nxf
//完成日期: 2005-6-1
//描 述: 完成对图像数据格式的排列,转换成4字节对齐的方式并返回。
//参数说明:
// 1.ChanDirect - 颜色通道顺序选择. 0:输入通道顺序为R->G->B. 1:输入通道顺序为B->G->R.
// 2.pixel_width - 图像的像素宽度.
// 3.pixel_height - 图像的像素高度.
// 4.pImageData - 指向原始图像数据的指针.
//------------------------------------------------------------------------------------------------------
#ifdef WholeBMP
UINT32 *DataConvert(UInt8 ChanDirect,int pixel_width,int pixel_height,UInt8 *pBMP)
#else
UINT32 *DataConvert(UInt8 ChanDirect,int pixel_width,int pixel_height,UInt8 *pImgData)
#endif
{
int i=0,j=0;
UInt8 *imagealpha=NULL;
UInt32 *pDbWordData=NULL;
UInt8 *pData;
UInt8 appbits;
#ifdef WholeBMP
pData = pBMP + 54;
#else
pData = pImgData;
#endif
if((pixel_width*3)%4) //图象宽度不是4字节对齐
appbits = 4 - ((pixel_width*3)%4); //补齐的字节数
if(!(imagealpha = (UInt8 *)malloc(pixel_width * pixel_height *4)))
return NULL;
if(!(pDbWordData = (UInt32 *)malloc(pixel_width * pixel_height*4)))
return NULL;
if(appbits!=4) //宽度字节4字节不对齐
{
for(i=0; i < pixel_height*pixel_width; i++)
{
if((i+1)%pixel_width)
{
if(!ChanDirect)//输入R->G->B转化为4字节对齐(alpha + R + G + B)
pDbWordData[i] = (0xff<<24) + ((*(pData++))<<16) +((*(pData++))<<8) +((*(pData++)));
else //输入B->G->R转化为4字节对齐(alpha + R + G + B)
pDbWordData[i] = (0xff<<24) + ((*(pData++))) +((*(pData++))<<8) +((*(pData++))<<16);
}
else
{
if(!ChanDirect)
pDbWordData[i] = (0xff<<24) + ((*(pData++))<<16) +((*(pData++))<<8) +((*(pData++)));
else
pDbWordData[i] = (0xff<<24) + ((*(pData++))) +((*(pData++))<<8) +((*(pData++))<<16);
pData = pData +appbits;
}
}
}
else
{
for(i=0; i < pixel_height*pixel_width; i++)
{
if(!ChanDirect)
pDbWordData[i] = (0xff<<24) + ((*(pData++))<<16) +((*(pData++))<<8) +((*(pData++)));
else
pDbWordData[i] = (0xff<<24) + ((*(pData++))) +((*(pData++))<<8) +((*(pData++))<<16);
}
}
free(imagealpha);
return pDbWordData;
}
//----------------------------------------------------------------------------------------------------
//函数名:DrawableCreate
//输 入: 无
//输 出: TM_OK 或错误号
//完成人: nxf
//完成日期: 2005-5-25
//描 述: 创建一个绘画对象
//-----------------------------------------------------------------------------------------------------
tmErrorCode_t DrawableCreate(void)
{
tmErrorCode_t tmError = TM_OK;
tmhwDrawBitsRef_t hPixel; // handle to screen
UINT8 *p;
int i;
tmDrawFormat_t vidFormat =
{
sizeof(tmDrawFormat_t), // 大小
(0-0),
(0-0),
avdcDraw,
vtfRGB, // 数据类型
vcfXRGB8888, // 数据子类型
0,
gdtVideo, // drawable类型
{
800,
600
},
{
800 * 32
}
};
if (TM_OK!=(tmError = tmhwDrawInit()))
return tmError;
InitFlg = 1;
hPixel.pBits = VideoGetOsdBuf();
if (tmError = tmhwDrawCreate(&pScreen, &vidFormat,&hPixel))
{
myprintf("tmdraw not ok \n");
return tmError;
}
return tmError;
}
//----------------------------------------------------------------------------------------------------
//函数名:GetDrawableInfo
//输 入:pVersion,pState
//输 出: TM_OK 或错误号
//完成人: nxf
//完成日期: 2005-5-25
//描 述: 返回当前绘画设备的状态
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -