BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Skewing an image

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Graphics
View previous topic :: View next topic  
Author Message
Harold
Guest





PostPosted: Tue Aug 23, 2005 9:48 pm    Post subject: Skewing an image Reply with quote



I've found lots of components that will deskew but I'm looking for a
function to actually skew an image. I looked through efg.com and a few other
places and couldn't see anything. Anyone know where there might be a skew
function out there?
--
Best regards,
Harold


Back to top
John
Guest





PostPosted: Wed Aug 24, 2005 7:09 am    Post subject: Re: Skewing an image Reply with quote




Harold,

I think that GDI+ hace this so look at GDI+ header for delphi.

John


Back to top
Harold
Guest





PostPosted: Sun Aug 28, 2005 4:51 am    Post subject: Re: Skewing an image Reply with quote



Quote:
I think that GDI+ hace this so look at GDI+ header for delphi.

I've gone through the samples and a couple of the header and haven't seen
anything. I'm floored though that there isn't some source out there that
skews an image.

Harold



Back to top
Daniel
Guest





PostPosted: Tue Aug 30, 2005 7:19 am    Post subject: Re: Skewing an image Reply with quote

try this


procedure MakeThumbnail_Bit24(src, dest:Graphics.TBitmap);
var
x, y, ix, iy: integer;
x1, x2, x3: integer;

xscale, yscale: single;
iRed, iGrn, iBlu, iRatio: Longword;
pt, pt1: pRGB24;
iSrc, iDst, s1: integer;
i, j, r, g, b, tmpY: integer;

RowDest, RowSource, RowSourceStart: integer;
w, h: integer;
dxmin, dymin: integer;
ny1, ny2, ny3: integer;
dx, dy: integer;
lutX, lutY: array of integer;

begin

if (src=nil) or (dest=nil) then exit;

with src do
if (Width=0) or (Height=0) then exit;

with dest do
if (Width=0) or (Height=0) then exit;



if src.PixelFormat <> pf24bit then src.PixelFormat := pf24bit;
if dest.PixelFormat <> pf24bit then dest.PixelFormat := pf24bit;
w := Dest.Width;
h := Dest.Height;

iDst := (w * 24 + 31) and not 31;
iDst := iDst div 8; //BytesPerScanline
iSrc := (Src.Width * 24 + 31) and not 31;
iSrc := iSrc div 8;

xscale := 1 / (w / src.Width);
yscale := 1 / (h / src.Height);

// X lookup table
SetLength(lutX, w);
x1 := 0;
x2 := trunc(xscale);
for x := 0 to w - 1 do
begin
lutX[x] := x2 - x1;
x1 := x2;
x2 := trunc((x + 2) * xscale);
end;

// Y lookup table
SetLength(lutY, h);
x1 := 0;
x2 := trunc(yscale);
for x := 0 to h - 1 do
begin
lutY[x] := x2 - x1;
x1 := x2;
x2 := trunc((x + 2) * yscale);
end;

dec(w);
dec(h);
RowDest := integer(Dest.Scanline[0]);
RowSourceStart := integer(Src.Scanline[0]);
RowSource := RowSourceStart;
for y := 0 to h do
begin
dy := lutY[y];
x1 := 0;
x3 := 0;
for x := 0 to w do
begin
dx:= lutX[x];
iRed:= 0;
iGrn:= 0;
iBlu:= 0;
RowSource := RowSourceStart;
for iy := 1 to dy do
begin
pt := PRGB24(RowSource + x1);
for ix := 1 to dx do
begin
iRed := iRed + pt.R;
iGrn := iGrn + pt.G;
iBlu := iBlu + pt.B;
inc(pt);
end;
RowSource := RowSource - iSrc;
end;
iRatio := 65535 div (dx * dy);
pt1 := PRGB24(RowDest + x3);
pt1.R := (iRed * iRatio) shr 16;
pt1.G := (iGrn * iRatio) shr 16;
pt1.B := (iBlu * iRatio) shr 16;
x1 := x1 + 3 * dx;
inc(x3,3);
end;
RowDest := RowDest - iDst;
RowSourceStart := RowSource;
end;

end;


"Harold" <h.holmes@n.o.spam.lincolnbeach.com> 撰寫於郵件新聞:430feee6$1 (AT) newsgroups (DOT) borland.com...
Quote:
I think that GDI+ hace this so look at GDI+ header for delphi.

I've gone through the samples and a couple of the header and haven't seen
anything. I'm floored though that there isn't some source out there that
skews an image.

Harold





Back to top
Harold
Guest





PostPosted: Thu Sep 01, 2005 7:17 am    Post subject: Re: Skewing an image Reply with quote


"Daniel" <dan59314 (AT) ms3 (DOT) hinet.net> wrote


Quote:
procedure MakeThumbnail_Bit24(src, dest:Graphics.TBitmap);

By skewing I meant to take the top edge and move it over the the left or
right and leaving the bottom where it is located. like this:


From: To:
Quote:
-------------| /------------/
| / /
| / /
-------------| /------------/

This function just put a crosshatch appearance on the destination bitmap.

--
Best regards,
Harold Holmes



Back to top
Lord Crc
Guest





PostPosted: Thu Sep 01, 2005 2:47 pm    Post subject: Re: Skewing an image Reply with quote

On Thu, 1 Sep 2005 02:17:52 -0500, "Harold"
<h.holmes@n.o.spam.lincolnbeach.com> wrote:

Quote:
By skewing I meant to take the top edge and move it over the the left or
right and leaving the bottom where it is located.

Try something like this:

var
c: TCanvas;
bmp: TBitmap;
p: array[0..3] of TPoint;
xf, yf: single;
begin
c:= Canvas;
bmp:= Image1.Picture.Bitmap;

xf:= 0.2;
yf:= 0.0;

p[0]:= point(round(bmp.Width * xf), 0);
p[1]:= point(round(bmp.Width * (1+xf)), round(bmp.Height * yf));
p[2]:= point(0, bmp.Height);
p[3]:= point(bmp.Width, round(bmp.Height * (1 + yf)));

PlgBlt(c.Handle, p, bmp.Canvas.Handle, 0, 0, bmp.Width, bmp.Height,
0, 0, 0);
end;


You can read up on PlgBlt here
http://msdn.microsoft.com/library/en-us/gdi/bitmaps_2dis.asp

Note that it's NT+ only, no win9x.

- Asbj鷨n

Back to top
Daniel
Guest





PostPosted: Mon Sep 05, 2005 3:57 am    Post subject: Re: Skewing an image Reply with quote

I think that won't be more difficult.

Just create a new TBitmap with new width ( old width + shift pixels), then
scan each line in old bitmap and copy it to new bitmap start at increasing
shfit pixels.


"Harold" <h.holmes@n.o.spam.lincolnbeach.com> 撰寫於郵件新聞:4316aa95$1 (AT) newsgroups (DOT) borland.com...
Quote:

"Daniel" <dan59314 (AT) ms3 (DOT) hinet.net> wrote


procedure MakeThumbnail_Bit24(src, dest:Graphics.TBitmap);

By skewing I meant to take the top edge and move it over the the left or
right and leaving the bottom where it is located. like this:


From: To:
|-------------| /------------/
| | / /
| | / /
|-------------| /------------/

This function just put a crosshatch appearance on the destination bitmap.

--
Best regards,
Harold Holmes





Back to top
Sasa Zeman
Guest





PostPosted: Tue Sep 06, 2005 8:31 pm    Post subject: Re: Skewing an image Reply with quote

Harold wrote:

Quote:
By skewing I meant to take the top edge and move it over the the left or
right and leaving the bottom where it is located. like this:


From: To:
-------------| /------------/
| / /
| / /
-------------| /------------/


It is actually quite simple. In Decart's coordinate system, definition of a line through two points is as follows:

Quote:
x y 1|
x1 y1 1| = 0
x2 y2 1|

When calculate this determinant and simplify, well known formula will be shown:

y - y1= (Y2-y1)/(x2-x1)* (x-x1)

Expression (Y2-y1)/(x2-x1) is actualy tangens of angle which line creates with x-ordinate. Then formula can be shown like this:

y - y1= a * (x-x1), where a=tan(phi)

As here line starts in coordinate begining, formula simply become:

y = tan (phi) * x

Since we here need to calculate starting position of x for each needed y by complement angle, formula looks like this:

x = y / tan(PI/2 - phi) * x, where phi is angle in radian.


That is basic math background. I have created, not quite well optimized skew clockwise only procedure for 32-bits bitmaps, just to demonstrate the whole process:

procedure SZHorSkew(Src, Dest: TBitmap; DegreeAngle: Double);
var
x,y : integer;
H, W: integer; // Height and Weight variables
P,D : PDWORD; // Pixel pointers
DIF : integer; // Translation diference by given angle
begin

if (DegreeAngle<=0) or (DegreeAngle>=90) then
exit;

try

if Src.PixelFormat <> pf32bit then
Src.PixelFormat := pf32bit;

if Dest.PixelFormat <> pf32bit then
Dest.PixelFormat := pf32bit;

DIF:=round(Src.Height/tan(DegToRad(90-DegreeAngle)));

Dest.Width := Src.Width+DIF;
Dest.Height := Src.Height;

// This can also be optimized
Dest.Canvas.Pen.Color:=clWhite;
Dest.Canvas.Rectangle(0,0,Dest.Width,Dest.Height);

H:=Dest.Height-1;
W:=SRC.Width-1;

// Skew vertical
for y := 0 to H do
begin

P:=Src.ScanLine[y];
D:=Dest.ScanLine[y];

// Slow, but precise calculation. Can be optimized
DIF:=round((H-y)/tan(DegToRad(90-DegreeAngle)));

inc(D,DIF);

for x := 0 to W do
begin
D^:=P^;
inc(D);
inc(P);
end;
end;

finally end;
end;

Sasa
--
www.szutils.net

Back to top
dd
Guest





PostPosted: Tue Sep 06, 2005 9:01 pm    Post subject: Re: Skewing an image Reply with quote

Harold wrote:
Quote:
I've found lots of components that will deskew but I'm looking for a
function to actually skew an image. I looked through efg.com and a few other
places and couldn't see anything. Anyone know where there might be a skew
function out there?

From the win32 help:

"A horizontal shear can be represented by the following algorithm:

x' = x + (Sx * y)


where x is the original x-coordinate, Sx is the proportionality
constant, and x' is the result of the shear transformation.
A vertical shear can be represented by the following algorithm:

y' = y + (Sy * x)


where y is the original y-coordinate, Sy is the proportionality
constant, and y' is the result of the shear transformation."

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Graphics All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.