ximawnd.cpp
来自「君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图」· C++ 代码 · 共 1,694 行 · 第 1/4 页
CPP
1,694 行
bool bAlpha = pAlpha != 0;
cx = MIN(xr,src_x_size) - xl;
cy = MIN(yr,src_y_size) - yl;
dx = MIN(cx,ima_x_size - x1);
dy = MIN(cy,ima_y_size - y1);
printf("dx = %d,dy = %d\n",dx,dy);
printf("ima_x_size = %d\n ima_y_size = %d\n",ima_x_size,ima_y_size);
//bitmap 4byte align
if(head.biBitCount == 8)
{
if(ima_x_size & 3)
src_width = (ima_x_size / 4 + 1) * 4;
else
src_width = ima_x_size;
}else
{
if(ima_x_size & 3)
src_width = (ima_x_size * 3 / 4 + 1) * 4;
else
src_width = ima_x_size * 3;
}
psrc += src_width * (ima_y_size - 1);
printf("src_width = %d\n",src_width);
printf("bTransparent = %d\nbAlpha = %d\ninfo.bAlphaPaletteEnabled = %d\n",
bTransparent,
bAlpha,
info.bAlphaPaletteEnabled);
if (!(bTransparent || bAlpha || info.bAlphaPaletteEnabled)){
//draw not alpha bitmap
psrc -= y1 * 3 * src_width;
ptar += yl * src_x_size;
ptar += xl;
psrc += 3 * x1;
if(head.biBitCount == 8)
{
colors = (unsigned int *)GetPalette();
for(j = 0; j < dy;j++)
{
for(i = 0;i < dx; i++)
*(ptar+i)= colors[*(psrc + i)];
ptar += src_x_size;
psrc -= src_width;
}
}else{
for(j = 0; j < dy;j++)
{
for(i = 0;i < dx; i++)
*(ptar+i)= SETBMRGB(*(psrc+ 2 + i * 3 ),*(psrc+1 + i * 3),*(psrc + i * 3));
ptar += src_x_size;
psrc -= src_width;
}
}
}else
{
//alpha blend bitmap
//pixel informations
RGBQUAD c={0,0,0,0};
RGBQUAD ct = GetTransColor();
long* pc = (long*)&c;
long* pct= (long*)&ct;
long sx,sy;
long cit = GetTransIndex();
long ci;
unsigned char a,a1,*ppbtar;
//long alphaoffset;
unsigned char *pa = pAlpha;
pa += ima_x_size * (ima_y_size - 1) + x1;
sy = y1;
ptar += yl * src_x_size;
for(j = 0; j < dy;j++)
{
psrc += 3 * x1;
unsigned int *pdst = (ptar + xl);
//printf("psrc = %x\n",psrc);
//printf("ptar = %x\n",ptar);
sx = x1;
//alphaoffset=sy * ima_x_size;
for(i = 0;i < dx; i++)
{
unsigned char *ppix = (psrc + i * 3);
if (bAlpha)
{
a=*(pa + sx);
//pAlpha[alphaoffset+sx];
}else a=255;
a =(BYTE)((a*(1+info.nAlphaMax))>>8);
if (head.biClrUsed){
ci = GetPixelIndex(sx,sy);
c = GetPaletteColor(ci);
if (info.bAlphaPaletteEnabled){
a = (BYTE)((a*(1+c.rgbReserved))>>8);
}
}else
{
ppix = psrc + sx * 3;
c.rgbBlue = *ppix++;
c.rgbGreen= *ppix++;
c.rgbRed = *ppix;
}
if ((head.biClrUsed && ci!=cit) || (!head.biClrUsed && *pc!=*pct) || !bTransparent){
if (a != 0) { // a == 0 Transparent, retain dest
if (a == 255) { // opaque, ignore dest
*pdst = SETBMRGB(c.rgbRed,c.rgbGreen,c.rgbBlue);
} else { // semi transparent
a1=(BYTE)~a;
unsigned char *pcdst = (unsigned char*)pdst;
*pcdst++=(unsigned char)(((unsigned int)*pcdst * (unsigned int)a1 + (unsigned int)a * (unsigned int)c.rgbBlue)>>8);
*pcdst++=(unsigned char)(((unsigned int)*pcdst * (unsigned int)a1 + (unsigned int)a * (unsigned int)c.rgbGreen)>>8);
*pcdst++=(unsigned char)(((unsigned int)*pcdst * (unsigned int)a1 + (unsigned int)a * (unsigned int)c.rgbRed)>>8);
}
}
}
sx++;
pdst++;
}
ptar += src_x_size;
psrc -= src_width;
pa -= ima_x_size;
sy++;
}
}
}
void CxImage::DrawImage(SCRINFO *bf,
unsigned int xl,unsigned int yl,
unsigned int xr,unsigned int yr,
unsigned int xl1,unsigned int yl1,
unsigned int xr1,unsigned int yr1,unsigned char isEqualScale)
{
int i, j;
BYTE *psrc = info.pImage;
unsigned int *ptar = bf->buffer;
int ima_x_size = head.biWidth;
int ima_y_size = head.biHeight;
int src_x_size = bf->w;
int src_y_size = bf->h;
int dx,dy,src_width,idx,idy;
float xscale,yscale;
unsigned int *colors;
int cx,cy;
bool bTransparent = info.nBkgndIndex != -1;
bool bAlpha = pAlpha != 0;
cx = MIN(xr,src_x_size) - xl;
cy = MIN(yr,src_y_size) - yl;
dx = MIN(cx,ima_x_size - xl1);
dy = MIN(cy,ima_y_size - yl1);
idx = MIN(xr1 - xl1,ima_x_size - xl1);
idy = MIN(yr1 - yl1,ima_y_size - yl1);
xscale = (float)dx / (float)idx;
yscale = (float)dy / (float)idy;
if(isEqualScale)
{
if(xscale > yscale)
{
xscale = yscale;
dx = (unsigned int)((float)idx * xscale);
}
else
{
yscale = xscale;
dy = (unsigned int)((float)idy * yscale);
}
}
//printf("\ndx = %d,dy = %d\n",dx,dy);
//printf("idx = %d,idy = %d\n",idx,idy);
//printf("xscale = %d/1000\n yscale = %d/1000\n",(unsigned int)(xscale * 1000.0),(unsigned int)(yscale * 1000.0));
//printf("ima_x_size = %d\n ima_y_size = %d\n",ima_x_size,ima_y_size);
//bitmap 4byte align
if(head.biBitCount == 8)
{
if(ima_x_size & 3)
src_width = (ima_x_size / 4 + 1) * 4;
else
src_width = ima_x_size;
}else
{
if(ima_x_size & 3)
src_width = (ima_x_size * 3 / 4 + 1) * 4;
else
src_width = ima_x_size * 3;
}
psrc += src_width * (ima_y_size - 1);
//printf("src_width = %d\n",src_width);
//printf("bTransparent = %d\nbAlpha = %d\ninfo.bAlphaPaletteEnabled = %d\n",
// bTransparent,
// bAlpha,
// info.bAlphaPaletteEnabled);
unsigned int *row = new unsigned int[dx * 4];
unsigned int ix,iy,oy,*ox;
ox = new unsigned int[dx];
if (!(bTransparent || bAlpha || info.bAlphaPaletteEnabled)){
//draw not alpha bitmap
psrc -= yl1 * src_width;
ptar += yl * src_x_size;
ptar += xl;
psrc += 3 * xl1;
if(head.biBitCount == 8)
{
colors = (unsigned int *)GetPalette();
iy = 0;
for(j = 0; j < dy;j++)
{
memset(row,0,4 * dx * 3);
oy = 0;
while((unsigned int)((float)iy * yscale) == j)
{
ix = 0;
for(i = 0;i < dx; i++)
{
ox[i] = 0;
while((unsigned int)((float)ix * xscale) == i)
{
row[i*3 + 0] += (colors[*(psrc + ix)] & 0x000000ff) >> 0;
row[i*3 + 1] += (colors[*(psrc + ix)] & 0x0000ff00) >> 8;
row[i*3 + 2] += (colors[*(psrc + ix)] & 0x00ff0000) >> 16;
ix++;
ox[i]++;
}
}
iy++;
oy++;
psrc -= src_width;
}
for(i = 0;i < dx;i++)
{
unsigned int count_x;
count_x = ox[i] * oy;
if(ox[i] > 0)
*(ptar+i)= SETBMRGB(row[i* 3 + 2] / count_x,
row[i* 3 + 1] / count_x,
row[i* 3 + 0] / count_x);
}
ptar += src_x_size;
}
}else{
iy = 0;
for(j = 0; j < dy;j++)
{
memset(row,0,4 * dx * 3);
oy = 0;
while((unsigned int)((float)iy * yscale) == j)
{
//printf("____%d == %d iy = %d dx = %d\n",(unsigned int)((float)iy * yscale),j,iy,dx);
ix = 0;
for(i = 0;i < dx; i++)
{
ox[i] = 0;
while((unsigned int)((float)ix * xscale) == i)
{
//printf("____%d == %d ix= %d\n",(unsigned int)((float)ix * xscale),i,ix);
row[i * 3 + 0] += *(psrc + ix * 3);
row[i * 3 + 1] += *(psrc + ix * 3 + 1);
row[i * 3 + 2] += *(psrc + ix * 3 + 2);
ix++;
ox[i]++;
}
}
psrc -= src_width;
oy++;
iy++;
}
for(i = 0;i < dx;i++)
{
unsigned int count_x;
count_x = ox[i] * oy;
if(ox[i] > 0)
*(ptar+i)= SETBMRGB(row[i* 3 + 2] / count_x,
row[i* 3 + 1] / count_x,
row[i* 3 + 0] / count_x);
}
ptar += src_x_size;
}
}
}else
{
//alpha blend bitmap
//pixel informations
RGBQUAD c={0,0,0,0};
RGBQUAD ct = GetTransColor();
long* pc = (long*)&c;
long* pct= (long*)&ct;
long cit = GetTransIndex();
long ci;
unsigned char a,a1;
//long alphaoffset;
unsigned char *pa = pAlpha;
pa += ima_x_size * (ima_y_size - 1);
ptar += yl * src_x_size + xl;
psrc -= yl1 * src_width;
psrc += xl1 * 3;
pa -= yl * src_width;
pa += xl1;
iy = 0;
for(j = 0; j < dy;j++)
{
oy = 0;
memset(row,0,4 * dx * 3);
while((unsigned int)((float)iy * yscale) == j)
{
//printf("psrc = %x\n",psrc);
//printf("ptar = %x\n",ptar);
ix = 0;
//alphaoffset=sy * ima_x_size;
for(i = 0;i < dx; i++)
{
ox[i] = 0;
while((unsigned int)((float)ix * xscale) == i)
{
if (bAlpha)
{
a=*(pa+ix);
}else
a=255;
a =(BYTE)((a*(1+info.nAlphaMax))>>8);
if (head.biClrUsed){
ci = GetPixelIndex(ix+xl1,yl1 + iy);
c = GetPaletteColor(ci);
if (info.bAlphaPaletteEnabled){
a = (BYTE)((a*(1+c.rgbReserved))>>8);
}
}else
{
unsigned char *ppix = psrc + ix * 3;
c.rgbBlue = *ppix++;
c.rgbGreen= *ppix++;
c.rgbRed = *ppix;
}
if ((head.biClrUsed && ci!=cit) || (!head.biClrUsed && *pc!=*pct) || !bTransparent){
if (a != 0) { // a == 0 Transparent, retain dest
if (a == 255) { // opaque, ignore dest
row[i * 3 + 0] += (unsigned int)c.rgbBlue;
row[i * 3 + 1] += (unsigned int)c.rgbGreen;
row[i * 3 + 2] += (unsigned int)c.rgbRed;
} else { // semi transparent
a1=(BYTE)~a;
unsigned char *pcdst = (unsigned char*)((unsigned int)ptar + i * 4);
row[i * 3 + 0] += (unsigned char)(((unsigned int)*pcdst++ * (unsigned int)a1 + (unsigned int)a * (unsigned int)c.rgbBlue)>>8);
row[i * 3 + 1] +=(unsigned char)(((unsigned int)*pcdst++ * (unsigned int)a1 + (unsigned int)a * (unsigned int)c.rgbGreen)>>8);
row[i * 3 + 2] +=(unsigned char)(((unsigned int)*pcdst++ * (unsigned int)a1 + (unsigned int)a * (unsigned int)c.rgbRed)>>8);
}
}else
{
unsigned char *pcdst = (unsigned char*)((unsigned int)ptar + i * 4);
row[i * 3 + 0] += (unsigned int)*pcdst++;
row[i * 3 + 1] += (unsigned int)*pcdst++;
row[i * 3 + 2] += (unsigned int)*pcdst++;
}
}else
{
unsigned char *pcdst = (unsigned char*)((unsigned int)ptar + i * 4);
row[i * 3 + 0] += (unsigned int)*pcdst++;
row[i * 3 + 1] += (unsigned int)*pcdst++;
row[i * 3 + 2] += (unsigned int)*pcdst++;
}
ix++;
ox[i]++;
}
}
iy++;
psrc -= src_width;
pa -= ima_x_size;
oy++;
}
for(i = 0; i < dx; i++)
{
/////////////
unsigned int dd = ox[i] * oy;
unsigned char *pcdst = (unsigned char*)((unsigned int)ptar + i * 4);
*pcdst++ = row[i*3 + 0] / dd;
*pcdst++ = row[i*3 + 1] / dd;
*pcdst++ = row[i*3 + 2] / dd;
///////////
}
ptar += src_x_size;
}
}
delete[] row;
delete[] ox;
}
////////////////////////////////////////////////////////////////////////////////
#endif //CXIMAGE_SUPPORT_UCOS
////////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?