数码相框——8、3、2 程序编写_图片显示之缩放与合并
作者:互联网
1、图像缩放算法
参考文件夹里: 图像缩放算法.htm
void PicZoom3_Table(const TPicRegion& Dst,const TPicRegion& Src)
{
if ( (0==Dst.width)||(0==Dst.height)
||(0==Src.width)||(0==Src.height)) return;
unsigned long dst_width=Dst.width;
unsigned long* SrcX_Table = new unsigned long[dst_width];
for (unsigned long x=0;x<dst_width;++x)//生成表 SrcX_Table
{
SrcX_Table[x]=(x*Src.width/Dst.width);
}
TARGB32* pDstLine=Dst.pdata;
for (unsigned long y=0;y<Dst.height;++y)
{
unsigned long srcy=(y*Src.height/Dst.height);
TARGB32* pSrcLine=((TARGB32*)((TUInt8*)Src.pdata+Src.byte_width*srcy));
for (unsigned long x=0;x<dst_width;++x)
pDstLine[x]=pSrcLine[SrcX_Table[x]];
((TUInt8*&)pDstLine)+=Dst.byte_width;
}
delete [] SrcX_Table;
}
解释下就是:
2、编写代码
在render目录下新建operation
在operation里建立
1)zoom.c
#include <pic_operation.h>
#include <stdlib.h>
#include <string.h>
int PicZoom(PT_PixelDatas ptOriginPic, PT_PixelDatas ptZoomPic)
{
unsigned long dwDstWidth = ptZoomPic->iWidth;
unsigned long* pdwSrcXTable = malloc(sizeof(unsigned long) * dwDstWidth);
unsigned long x;
unsigned long y;
unsigned long dwSrcY;
unsigned char *pucDest;
unsigned char *pucSrc;
unsigned long dwPixelBytes = ptOriginPic->iBpp/8;
if (ptOriginPic->iBpp != ptZoomPic->iBpp)
{
return -1;
}
for (x = 0; x < dwDstWidth; x++)//生成表 pdwSrcXTable Sx
{
pdwSrcXTable[x]=(x*ptOriginPic->iWidth/ptZoomPic->iWidth);
}
for (y = 0; y < ptZoomPic->iHeight; y++)
{
dwSrcY = (y * ptOriginPic->iHeight / ptZoomPic->iHeight); //Sy
pucDest = ptZoomPic->aucPixelDatas + y*ptZoomPic->iLineBytes;
pucSrc = ptOriginPic->aucPixelDatas + dwSrcY*ptOriginPic->iLineBytes;
for (x = 0; x <dwDstWidth; x++)
{
/* 原图座标: pdwSrcXTable[x],srcy
* 缩放座标: x, y
*/
memcpy(pucDest+x*dwPixelBytes, pucSrc+pdwSrcXTable[x]*dwPixelBytes, dwPixelBytes);
}
}
free(pdwSrcXTable);
return 0;
}
2)merge.c
#include <pic_operation.h>
#include <string.h>
int PicMerge(int iX, int iY, PT_PixelDatas ptSmallPic, PT_PixelDatas ptBigPic)
{
int i;
unsigned char *pucSrc;
unsigned char *pucDst;
if ((ptSmallPic->iWidth > ptBigPic->iWidth) ||
(ptSmallPic->iHeight > ptBigPic->iHeight) ||
(ptSmallPic->iBpp != ptBigPic->iBpp))
{
return -1;
}
pucSrc = ptSmallPic->aucPixelDatas;
pucDst = ptBigPic->aucPixelDatas + iY * ptBigPic->iLineBytes + iX * ptBigPic->iBpp / 8;
for (i = 0; i < ptSmallPic->iHeight; i++)
{
memcpy(pucDst, pucSrc, ptSmallPic->iLineBytes);
pucSrc += ptSmallPic->iLineBytes;
pucDst += ptBigPic->iLineBytes;
}
return 0;
}
标签:ptZoomPic,缩放,ptSmallPic,相框,unsigned,long,数码,ptOriginPic,ptBigPic 来源: https://blog.csdn.net/qq_40674996/article/details/100578644