Stretchblitting 32->32 bpp implemented

svn path=/trunk/; revision=7120
This commit is contained in:
Aleksey Bragin 2003-12-18 18:09:48 +00:00
parent 8bef76d86b
commit 10d1fb4bda
2 changed files with 199 additions and 49 deletions

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: dib16bpp.c,v 1.13 2003/12/15 23:33:45 fireball Exp $ */ /* $Id: dib16bpp.c,v 1.14 2003/12/18 18:09:48 fireball Exp $ */
#undef WIN32_LEAN_AND_MEAN #undef WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
#include <stdlib.h> #include <stdlib.h>
@ -351,13 +351,10 @@ DIB_16BPP_BitBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
typedef unsigned short PIXEL; typedef unsigned short PIXEL;
// DON'T FIX BUGS IN THIS FUNCTION YET
// BUT EMAIL INFO ABOUT IT TO aleksey at studiocerebral.com
// THIS IS WORK IN PROGRESS !!
/* 16-bit HiColor (565 format) */ /* 16-bit HiColor (565 format) */
inline unsigned short average(unsigned short a, unsigned short b) inline PIXEL average(PIXEL a, PIXEL b)
{ {
// This one doesn't work
/* /*
if (a == b) { if (a == b) {
return a; return a;
@ -365,13 +362,33 @@ inline unsigned short average(unsigned short a, unsigned short b)
unsigned short mask = ~ (((a | b) & 0x0410) << 1); unsigned short mask = ~ (((a | b) & 0x0410) << 1);
return ((a & mask) + (b & mask)) >> 1; return ((a & mask) + (b & mask)) >> 1;
}*/ /* if */ }*/ /* if */
return a; // FIXME: Temp hack to remove "PCB-effect" from the image
// This one should be correct, but it's too long
/*
unsigned char r1, g1, b1, r2, g2, b2, rr, gr, br;
unsigned short res;
r1 = (a & 0xF800) >> 11;
g1 = (a & 0x7E0) >> 5;
b1 = (a & 0x1F);
r2 = (b & 0xF800) >> 11;
g2 = (b & 0x7E0) >> 5;
b2 = (b & 0x1F);
rr = (r1+r2) / 2;
gr = (g1+g2) / 2;
br = (b1+b2) / 2;
res = (rr << 11) + (gr << 5) + br;
return res;
*/
return a; // FIXME: Depend on SetStretchMode
} }
// DON'T FIX BUGS IN THIS FUNCTION YET //NOTE: If you change something here, please do the same in other dibXXbpp.c files!
// BUT EMAIL INFO ABOUT IT TO aleksey at studiocerebral.com void ScaleLineAvg16(PIXEL *Target, PIXEL *Source, int SrcWidth, int TgtWidth)
// THIS IS WORK IN PROGRESS !!
void ScaleLineAvg16(unsigned short *Target, unsigned short *Source, int SrcWidth, int TgtWidth)
{ {
int NumPixels = TgtWidth; int NumPixels = TgtWidth;
int IntPart = SrcWidth / TgtWidth; int IntPart = SrcWidth / TgtWidth;
@ -379,7 +396,7 @@ void ScaleLineAvg16(unsigned short *Target, unsigned short *Source, int SrcWidth
int Mid = TgtWidth / 2; int Mid = TgtWidth / 2;
int E = 0; int E = 0;
int skip; int skip;
WORD p; PIXEL p;
skip = (TgtWidth < SrcWidth) ? 0 : (TgtWidth / (2*SrcWidth) + 1); skip = (TgtWidth < SrcWidth) ? 0 : (TgtWidth / (2*SrcWidth) + 1);
NumPixels -= skip; NumPixels -= skip;
@ -400,15 +417,12 @@ void ScaleLineAvg16(unsigned short *Target, unsigned short *Source, int SrcWidth
*Target++ = *Source; *Target++ = *Source;
} }
// DON'T FIX BUGS IN THIS FUNCTION YET //NOTE: If you change something here, please do the same in other dibXXbpp.c files!
// BUT EMAIL INFO ABOUT IT TO aleksey at studiocerebral.com
// THIS IS WORK IN PROGRESS !!
void ScaleRectAvg(PIXEL *Target, PIXEL *Source, int SrcWidth, int SrcHeight, void ScaleRectAvg(PIXEL *Target, PIXEL *Source, int SrcWidth, int SrcHeight,
int TgtWidth, int TgtHeight, int srcPitch, int dstPitch) int TgtWidth, int TgtHeight, int srcPitch, int dstPitch)
{ {
int NumPixels = TgtHeight; int NumPixels = TgtHeight;
int IntPart = (SrcHeight / TgtHeight) * (SrcWidth+1); int IntPart = (SrcHeight / TgtHeight) * (SrcWidth+1);
//int IntPart = (SrcHeight / TgtHeight) * SrcWidth;
int FractPart = SrcHeight % TgtHeight; int FractPart = SrcHeight % TgtHeight;
int Mid = TgtHeight / 2; int Mid = TgtHeight / 2;
int E = 0; int E = 0;
@ -449,7 +463,7 @@ void ScaleRectAvg(PIXEL *Target, PIXEL *Source, int SrcWidth, int SrcHeight,
memcpy(Target, ScanLine, TgtWidth*sizeof(PIXEL)); memcpy(Target, ScanLine, TgtWidth*sizeof(PIXEL));
Target = (PIXEL *)((BYTE *)Target + dstPitch); Target = (PIXEL *)((BYTE *)Target + dstPitch);
Source += IntPart; // <----- Source += IntPart;
E += FractPart; E += FractPart;
if (E >= TgtHeight) { if (E >= TgtHeight) {
E -= TgtHeight; E -= TgtHeight;
@ -468,9 +482,7 @@ void ScaleRectAvg(PIXEL *Target, PIXEL *Source, int SrcWidth, int SrcHeight,
ExFreePool(ScanLineAhead); ExFreePool(ScanLineAhead);
} }
// DON'T FIX BUGS IN THIS FUNCTION YET //NOTE: If you change something here, please do the same in other dibXXbpp.c files!
// BUT EMAIL INFO ABOUT IT TO aleksey at studiocerebral.com
// THIS IS WORK IN PROGRESS !!
BOOLEAN DIB_16BPP_StretchBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf, BOOLEAN DIB_16BPP_StretchBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
SURFGDI *DestGDI, SURFGDI *SourceGDI, SURFGDI *DestGDI, SURFGDI *SourceGDI,
RECTL* DestRect, RECTL *SourceRect, RECTL* DestRect, RECTL *SourceRect,
@ -500,32 +512,7 @@ BOOLEAN DIB_16BPP_StretchBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
case 16: case 16:
SourceLine = SourceSurf->pvScan0 + (SourceRect->top * SourceSurf->lDelta) + 2 * SourceRect->left; SourceLine = SourceSurf->pvScan0 + (SourceRect->top * SourceSurf->lDelta) + 2 * SourceRect->left;
DestLine = DestSurf->pvScan0 + (DestRect->top * DestSurf->lDelta) + 2 * DestRect->left; DestLine = DestSurf->pvScan0 + (DestRect->top * DestSurf->lDelta) + 2 * DestRect->left;
/*
y=0;
for (j = SourceRect->top; j < SourceRect->bottom; j++)
{
dday = -1000;
while (dday < 0)
{
dday += izoom;
x=0;
DestBits = DestLine;
SourceBits = SourceLine;
for (i = SourceRect->left; i < SourceRect->right; i++)
{
*((WORD *)DestBits) = (WORD)XLATEOBJ_iXlate(ColorTranslation, *((WORD *)SourceBits));
SourceBits += 2;
DestBits += 2;
x++;
}
//SourceLine += SourceSurf->lDelta;
DestLine += DestSurf->lDelta;
lines++;
}
SourceLine += SourceSurf->lDelta;
}*/
ScaleRectAvg((PIXEL *)DestLine, (PIXEL *)SourceLine, ScaleRectAvg((PIXEL *)DestLine, (PIXEL *)SourceLine,
SourceRect->right-SourceRect->left, SourceRect->bottom-SourceRect->top, SourceRect->right-SourceRect->left, SourceRect->bottom-SourceRect->top,
DestRect->right-DestRect->left, DestRect->bottom-DestRect->top, SourceSurf->lDelta, DestSurf->lDelta); DestRect->right-DestRect->left, DestRect->bottom-DestRect->top, SourceSurf->lDelta, DestSurf->lDelta);
@ -540,7 +527,7 @@ BOOLEAN DIB_16BPP_StretchBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
break; break;
default: default:
//DbgPrint("DIB_16BPP_StretchBlt: Unhandled Source BPP: %u\n", SourceGDI->BitsPerPixel); DbgPrint("DIB_16BPP_StretchBlt: Unhandled Source BPP: %u\n", SourceGDI->BitsPerPixel);
return FALSE; return FALSE;
} }

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: dib32bpp.c,v 1.7 2003/12/08 18:05:30 fireball Exp $ */ /* $Id: dib32bpp.c,v 1.8 2003/12/18 18:09:48 fireball Exp $ */
#undef WIN32_LEAN_AND_MEAN #undef WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
#include <stdlib.h> #include <stdlib.h>
@ -285,14 +285,177 @@ DIB_32BPP_BitBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
return TRUE; return TRUE;
} }
/*
=======================================
Stretching functions goes below
Some parts of code are based on an
article "Bresenhame image scaling"
Dr. Dobb Journal, May 2002
=======================================
*/
typedef unsigned long PIXEL;
//NOTE: If you change something here, please do the same in other dibXXbpp.c files!
/* 32-bit Color (___ format) */
inline PIXEL average32(PIXEL a, PIXEL b)
{
/*
if (a == b) {
return a;
} else {
unsigned short mask = ~ (((a | b) & 0x0410) << 1);
return ((a & mask) + (b & mask)) >> 1;
}*/ /* if */
return a; // FIXME: Temp hack to remove "PCB-effect" from the image
}
void ScaleLineAvg32(PIXEL *Target, PIXEL *Source, int SrcWidth, int TgtWidth)
{
int NumPixels = TgtWidth;
int IntPart = SrcWidth / TgtWidth;
int FractPart = SrcWidth % TgtWidth;
int Mid = TgtWidth / 2;
int E = 0;
int skip;
PIXEL p;
skip = (TgtWidth < SrcWidth) ? 0 : (TgtWidth / (2*SrcWidth) + 1);
NumPixels -= skip;
while (NumPixels-- > 0) {
p = *Source;
if (E >= Mid)
p = average32(p, *(Source+1));
*Target++ = p;
Source += IntPart;
E += FractPart;
if (E >= TgtWidth) {
E -= TgtWidth;
Source++;
} /* if */
} /* while */
while (skip-- > 0)
*Target++ = *Source;
}
//NOTE: If you change something here, please do the same in other dibXXbpp.c files!
void ScaleRectAvg32(PIXEL *Target, PIXEL *Source, int SrcWidth, int SrcHeight,
int TgtWidth, int TgtHeight, int srcPitch, int dstPitch)
{
int NumPixels = TgtHeight;
int IntPart = (SrcHeight / TgtHeight) * SrcWidth;
int FractPart = SrcHeight % TgtHeight;
int Mid = TgtHeight / 2;
int E = 0;
int skip;
PIXEL *ScanLine, *ScanLineAhead;
PIXEL *PrevSource = NULL;
PIXEL *PrevSourceAhead = NULL;
skip = (TgtHeight < SrcHeight) ? 0 : (TgtHeight / (2*SrcHeight) + 1);
NumPixels -= skip;
ScanLine = (PIXEL*)ExAllocatePool(NonPagedPool, TgtWidth*sizeof(PIXEL)); // FIXME: Should we use PagedPool here?
ScanLineAhead = (PIXEL *)ExAllocatePool(NonPagedPool, TgtWidth*sizeof(PIXEL));
while (NumPixels-- > 0) {
if (Source != PrevSource) {
if (Source == PrevSourceAhead) {
/* the next scan line has already been scaled and stored in
* ScanLineAhead; swap the buffers that ScanLine and ScanLineAhead
* point to
*/
PIXEL *tmp = ScanLine;
ScanLine = ScanLineAhead;
ScanLineAhead = tmp;
} else {
ScaleLineAvg32(ScanLine, Source, SrcWidth, TgtWidth);
} /* if */
PrevSource = Source;
} /* if */
if (E >= Mid && PrevSourceAhead != (PIXEL *)((BYTE *)Source + srcPitch)) {
int x;
ScaleLineAvg32(ScanLineAhead, (PIXEL *)((BYTE *)Source + srcPitch), SrcWidth, TgtWidth);
for (x = 0; x < TgtWidth; x++)
ScanLine[x] = average32(ScanLine[x], ScanLineAhead[x]);
PrevSourceAhead = (PIXEL *)((BYTE *)Source + srcPitch);
} /* if */
memcpy(Target, ScanLine, TgtWidth*sizeof(PIXEL));
Target = (PIXEL *)((BYTE *)Target + dstPitch);
Source += IntPart;
E += FractPart;
if (E >= TgtHeight) {
E -= TgtHeight;
Source = (PIXEL *)((BYTE *)Source + srcPitch);
} /* if */
} /* while */
if (skip > 0 && Source != PrevSource)
ScaleLineAvg32(ScanLine, Source, SrcWidth, TgtWidth);
while (skip-- > 0) {
memcpy(Target, ScanLine, TgtWidth*sizeof(PIXEL));
Target = (PIXEL *)((BYTE *)Target + dstPitch);
} /* while */
ExFreePool(ScanLine);
ExFreePool(ScanLineAhead);
}
//NOTE: If you change something here, please do the same in other dibXXbpp.c files!
BOOLEAN DIB_32BPP_StretchBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf, BOOLEAN DIB_32BPP_StretchBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
SURFGDI *DestGDI, SURFGDI *SourceGDI, SURFGDI *DestGDI, SURFGDI *SourceGDI,
RECTL* DestRect, RECTL *SourceRect, RECTL* DestRect, RECTL *SourceRect,
POINTL* MaskOrigin, POINTL* BrushOrigin, POINTL* MaskOrigin, POINTL* BrushOrigin,
XLATEOBJ *ColorTranslation, ULONG Mode) XLATEOBJ *ColorTranslation, ULONG Mode)
{ {
DbgPrint("DIB_32BPP_StretchBlt: Source BPP: %u\n", SourceGDI->BitsPerPixel); BYTE *SourceLine, *DestLine;
return FALSE;
DbgPrint("DIB_32BPP_StretchBlt: Source BPP: %u, srcRect: (%d,%d)-(%d,%d), dstRect: (%d,%d)-(%d,%d)\n",
SourceGDI->BitsPerPixel, SourceRect->left, SourceRect->top, SourceRect->right, SourceRect->bottom,
DestRect->left, DestRect->top, DestRect->right, DestRect->bottom);
switch(SourceGDI->BitsPerPixel)
{
case 1:
return FALSE;
break;
case 4:
return FALSE;
break;
case 8:
return FALSE;
break;
case 16:
return FALSE;
break;
case 24:
return FALSE;
break;
case 32:
SourceLine = SourceSurf->pvScan0 + (SourceRect->top * SourceSurf->lDelta) + 4 * SourceRect->left;
DestLine = DestSurf->pvScan0 + (DestRect->top * DestSurf->lDelta) + 4 * DestRect->left;
ScaleRectAvg32((PIXEL *)DestLine, (PIXEL *)SourceLine,
SourceRect->right-SourceRect->left, SourceRect->bottom-SourceRect->top,
DestRect->right-DestRect->left, DestRect->bottom-DestRect->top, SourceSurf->lDelta, DestSurf->lDelta);
break;
default:
//DbgPrint("DIB_32BPP_StretchBlt: Unhandled Source BPP: %u\n", SourceGDI->BitsPerPixel);
return FALSE;
}
return TRUE;
} }
/* EOF */ /* EOF */