 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Jon Lennart Aasenden Guest
|
Posted: Tue Mar 29, 2005 6:09 pm Post subject: Native Stretchdraw again.. |
|
|
I have asked this one before without any answere.. so here i go again.
Does anyone have a routine for stretch-blitting using nothing but delphi?
No assembler, just pure delphi.
It needs to be very fast, preferably using integer maths and access pixel
memory directly.
or..
If anyone could help me out to get this right, that would also be welcome.
Im only a handfull of procedures away from finishing XLR8 now.
I had to rewrite everything, including large parts of freetype to get
everything working for all compilers - but its pretty darn good :)
Jon Lennart Aasenden
|
|
| Back to top |
|
 |
Jens Gruschel Guest
|
Posted: Tue Mar 29, 2005 6:37 pm Post subject: Re: Native Stretchdraw again.. |
|
|
| Quote: | I have asked this one before without any answere.. so here i go again.
|
I must have missed it.
| Quote: | Does anyone have a routine for stretch-blitting using nothing but delphi?
No assembler, just pure delphi.
It needs to be very fast, preferably using integer maths and access pixel
memory directly.
|
type
TPegtopColor = packed record
case Integer of
0: (Def: Longword);
1: (R, G, B, A: Byte);
2: (Channel: packed array[0..3] of Byte);
end;
PPegtopColor = ^TPegtopColor;
procedure PegtopStretchBitmap32(const DestOrigin: Pointer; const
DestPitch: Integer; const DestRect: TRect;
const SourceOrigin: Pointer; const SourcePitch: Integer; const
SourceRect: TRect);
var
X, Y: Integer;
DestP, DestQ: PPegtopColor;
SourceP, SourceQ: PPegtopColor;
DeltaIntX, DeltaFracX: Integer;
DeltaIntY, DeltaFracY: Integer;
SourceWidth, SourceHeight, DestWidth, DestHeight: Integer;
SourceIntX, SourceFracX: Integer;
SourceIntY, SourceFracY: Integer;
begin
// set width and height:
SourceWidth := SourceRect.Right - SourceRect.Left - 1;
SourceHeight := SourceRect.Bottom - SourceRect.Top - 1;
DestWidth := DestRect.Right - DestRect.Left - 1;
DestHeight := DestRect.Bottom - DestRect.Top - 1;
// set deltas:
DeltaIntX := SourceWidth div DestWidth;
DeltaFracX := SourceWidth mod DestWidth;
DeltaIntY := SourceHeight div DestHeight;
DeltaFracY := SourceHeight mod DestHeight;
// set source y-coodinate:
SourceIntY := (DestRect.Top * SourceHeight div DestHeight) +
SourceRect.Top;
SourceFracY := (DestRect.Top * SourceHeight) mod DestHeight;
// set destination pointer:
DestQ := Pointer(Integer(DestOrigin) + DestRect.Top * DestPitch +
DestRect.Left * 4);
for Y := DestRect.Top to DestRect.Bottom - 1 do begin
DestP := DestQ;
// set source x-coordinate:
SourceIntX := (DestRect.Left * SourceWidth div DestWidth) +
SourceRect.Left;
SourceFracX := (DestRect.Left * SourceWidth) mod DestWidth;
// set source pointer:
SourceQ := Pointer(Integer(SourceOrigin) + (SourceIntY shr *
SourcePitch);
for X := DestRect.Left to DestRect.Right - 1 do begin
// set source pointer:
SourceP := SourceQ;
Inc(SourceP, SourceIntX shr ;
// copy pixel:
DestP^ := SourceP^;
// inc dest pointer
Inc(DestP);
// simulate floating point arithmetics:
Inc(SourceIntX, DeltaIntX);
Inc(SourceFracX, DeltaFracX);
if SourceFracX > DestWidth then begin
Inc(SourceIntX);
Dec(SourceFracX, DestWidth);
end;
end;
// simulate floating point arithmetics:
Inc(SourceIntY, DeltaIntY);
Inc(SourceFracY, DeltaFracY);
if SourceFracY > DestHeight then begin
Inc(SourceIntY);
Dec(SourceFracY, DestHeight);
end;
// next destination line:
DestQ := Pointer(Integer(DestQ) + DestPitch);
end;
end;
Works for 32 bit only.
When using TBitmap, Origin := Bitmap.ScanLine[0] and Pitch :=
Integer(Bitmap.ScanLine[1]) - Integer(Origin). The good thing about it
is that it works for TBitmap, TBitmap32, DirectX surfaces...
No clipping is made, so make sure DestRect and SourceRect are valid (AV
otherwise). If you need functions for clipping tell me (it's pretty easy).
Even without asm it's very fast, because there are no divisions in the
inner loop. And it's 100% accurate (even better than using floating
point arithmetics or scaled integers and shl / shr), see "simulate
floating point arithmetics".
Instead of using PPegtopColor of course you can use ^Longint or any
other pointer to a 32 bit type.
Jens
|
|
| Back to top |
|
 |
Jens Gruschel Guest
|
Posted: Tue Mar 29, 2005 6:42 pm Post subject: Re: Native Stretchdraw again.. |
|
|
| Quote: | Works for 32 bit only.
Instead of using PPegtopColor of course you can use ^Longint or any
other pointer to a 32 bit type.
|
Well, if you change the type, the procedure should work for other pixel
formats than 32 bit as well :-)
Jens
|
|
| Back to top |
|
 |
Nils Haeck Guest
|
Posted: Wed Mar 30, 2005 9:32 am Post subject: Re: Native Stretchdraw again.. |
|
|
Hi Jon Lennart,
Do you have a link to XLR8? I would be interested in hearing from you what
you did with freetype to get it working.. Would you be willing to share your
version?
Kind regards,
Nils Haeck
"Jon Lennart Aasenden" <post_nospam_nojunk (AT) jurasoft (DOT) no> wrote
| Quote: | I have asked this one before without any answere.. so here i go again.
Does anyone have a routine for stretch-blitting using nothing but delphi?
No assembler, just pure delphi.
It needs to be very fast, preferably using integer maths and access pixel
memory directly.
or..
If anyone could help me out to get this right, that would also be welcome.
Im only a handfull of procedures away from finishing XLR8 now.
I had to rewrite everything, including large parts of freetype to get
everything working for all compilers - but its pretty darn good :)
Jon Lennart Aasenden
|
|
|
| Back to top |
|
 |
Jon Lennart Aasenden Guest
|
Posted: Wed Mar 30, 2005 5:03 pm Post subject: Re: Native Stretchdraw again.. |
|
|
Thanks!
Will try it out!
Jon Lennart Aasenden
"Jens Gruschel" <nospam (AT) thisurldoesnotexist (DOT) com> wrote
| Quote: | Works for 32 bit only.
Instead of using PPegtopColor of course you can use ^Longint or any
other pointer to a 32 bit type.
Well, if you change the type, the procedure should work for other pixel
formats than 32 bit as well :-)
Jens
|
|
|
| Back to top |
|
 |
Jon Lennart Aasenden Guest
|
Posted: Wed Mar 30, 2005 5:24 pm Post subject: Re: Native Stretchdraw again.. |
|
|
Hi Nils
Im not quite ready with XLR8 yet - but its getting there.
Just today i found a faster way of rendering pixels.. never ending story..
I had to re-write everything from the first version, so the new one is all
class based.
I will post a link here when it is finished.
| Quote: | Would you be willing to share your version?
|
Not quite yet nils, but when it is complete i will share it with this board,
be sure of it.
XLR8 will also be dedicated to this board, since it contains inspiration
from just about everyone.
Jon Lennart Aasenden
"Nils Haeck" <n.haeckno (AT) spamchello (DOT) nl> wrote
| Quote: | Hi Jon Lennart,
Do you have a link to XLR8? I would be interested in hearing from you what
you did with freetype to get it working.. Would you be willing to share
your
version?
Kind regards,
Nils Haeck
"Jon Lennart Aasenden" <post_nospam_nojunk (AT) jurasoft (DOT) no> wrote in message
news:424999cb (AT) newsgroups (DOT) borland.com...
I have asked this one before without any answere.. so here i go again.
Does anyone have a routine for stretch-blitting using nothing but
delphi?
No assembler, just pure delphi.
It needs to be very fast, preferably using integer maths and access
pixel
memory directly.
or..
If anyone could help me out to get this right, that would also be
welcome.
Im only a handfull of procedures away from finishing XLR8 now.
I had to rewrite everything, including large parts of freetype to get
everything working for all compilers - but its pretty darn good :)
Jon Lennart Aasenden
|
|
|
| Back to top |
|
 |
Steve Guest
|
Posted: Thu Mar 31, 2005 6:56 am Post subject: Re: Native Stretchdraw again.. |
|
|
Hi Jon Lennart,
Any plan to make a freepascal version of XLR8?
So the lib will be useable under Windows, Linux and MacOSX...
thanks
Steve
|
|
| Back to top |
|
 |
Mr. X Guest
|
Posted: Thu Mar 31, 2005 8:26 am Post subject: Re: Native Stretchdraw again.. |
|
|
Hi Jon
waiting to see what you made.
| Quote: | XLR8 will also be dedicated to this board, since it contains inspiration
from just about everyone.
|
so what was my bit (inspiration) in XLR8 ? :p
Best Regards
X
|
|
| Back to top |
|
 |
Jon Lennart Aasenden Guest
|
Posted: Thu Mar 31, 2005 2:58 pm Post subject: Re: Native Stretchdraw again.. |
|
|
It works perfectly under freepascal.
In fact, i partly wrote it because freepascal has so crap support for
graphics.
It would be great to check out the embedded options as well.
Jon Lennart Aasenden
"Steve" <nospam (AT) nospam (DOT) com> wrote
| Quote: | Hi Jon Lennart,
Any plan to make a freepascal version of XLR8?
So the lib will be useable under Windows, Linux and MacOSX...
thanks
Steve
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|