Page 1 of 2

Vector Lib: Rotate: Lost Pixels

Posted: Mon Mar 29, 2021 12:53 am
by IdeasVacuum
I'm doing something wrong :shock:

Set an image on a Canvas, top left corner. Rotate it 90 degrees anticlockwise. The rotated image is out by 1 pixel. Image width and height are even numbers (104 x 184) - so I suspect that might be the issue, but I don't recall seeing a wonky result using Luis's code:
viewtopic.php?f=12&t=38975

TestImageDownload

Edit: Perhaps rotate about 0,0 and then move-translate?

Code: Select all

Enumeration
#Win
#Canvas
#Img
EndEnumeration

UsePNGImageDecoder()

Procedure Win()
;#-------------

               If OpenWindow(#Win, 0, 0, 220, 220, "Rotate 90", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

                         SetWindowColor(#Win, RGB(064,252,064))
                           CanvasGadget(#Canvas, 10, 10, 200, 200)
               EndIf
EndProcedure

Procedure Vimg()
;#--------------
Protected dImgW.d, dImgH.d

               If LoadImage(#Img, "C:\Test.png")

                         dImgW = ImageWidth(#Img)
                         dImgH = ImageHeight(#Img)

                         Debug "dImgW-->" + StrD(dImgW) + "<--"
                         Debug "dImgH-->" + StrD(dImgH) + "<--"

                         SetGadgetAttribute(#Canvas, #PB_Canvas_Image, ImageID(#Img))

                         Delay(2000) ;just to see original orientation

                         If StartVectorDrawing(CanvasVectorOutput(#Canvas))

                                   VectorSourceColor(RGBA(255,255,255,255))
                                          AddPathBox(0, 0, 220, 220)
                                            FillPath()

                                      MovePathCursor(0, 0)
                                      MovePathCursor(dImgW * 0.50, dImgW * 0.50)
                                   RotateCoordinates(dImgW * 0.50, dImgW * 0.50, -(90))
                                      MovePathCursor(0, 0)
                                     DrawVectorImage(ImageID(#Img), 255)

                                   StopVectorDrawing()
                         EndIf
               EndIf
EndProcedure

Win()
Vimg()

Repeat
Until WaitWindowEvent(1) = #PB_Event_CloseWindow

Re: Vector Lib: Rotate: Lost Pixels

Posted: Mon Mar 29, 2021 11:40 am
by Saki
This is a discrepancy of the coordinate zero point between Canvas and Image.
It is different for the OS, it is a old "unknown" bug on Windows.

Code: Select all

Enumeration
#Win
#Canvas
#Img
EndEnumeration

UsePNGImageDecoder()

Procedure Win()
;#-------------

               If OpenWindow(#Win, 0, 0, 220, 220, "Rotate 90", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

                         SetWindowColor(#Win, RGB(064,252,064))
                           CanvasGadget(#Canvas, 10, 10, 200, 200)
               EndIf
EndProcedure

Procedure Vimg()
;#--------------
Protected dImgW.d, dImgH.d

               If LoadImage(#Img, "C:\Users\Tanaka\Desktop\Test.png")
                 
                 
                         dImgW = ImageWidth(#Img)
                         dImgH = ImageHeight(#Img)

                         Debug "dImgW-->" + StrD(dImgW) + "<--"
                         Debug "dImgH-->" + StrD(dImgH) + "<--"

                         SetGadgetAttribute(#Canvas, #PB_Canvas_Image, ImageID(#Img))

                         Delay(2000) ;just to see original orientation

                         If StartVectorDrawing(CanvasVectorOutput(#Canvas))

                                   VectorSourceColor(RGBA(255,255,255,255))
                                          AddPathBox(0, 0, 220, 220)
                                            FillPath()

                                      MovePathCursor(0, 0)
                                      MovePathCursor(dImgW * 0.50, dImgW * 0.50)
                                   RotateCoordinates(dImgW * 0.50, dImgW * 0.50, -(90))
                                      MovePathCursor(-1, 2)
                                     DrawVectorImage(ImageID(#Img), 255)

                                   StopVectorDrawing()
                         EndIf
               EndIf
EndProcedure

Win()
Vimg()

Repeat
Until WaitWindowEvent(1) = #PB_Event_CloseWindow

Re: Vector Lib: Rotate: Lost Pixels

Posted: Mon Mar 29, 2021 7:10 pm
by IdeasVacuum
it is a old "unknown" bug on Windows.
Wow, thanks Saki - really surprised that MS would just leave it like that :shock:

Re: Vector Lib: Rotate: Lost Pixels

Posted: Mon Mar 29, 2021 7:25 pm
by Saki
Hi, it is a PB Bug
Best Regards Saki

Re: Vector Lib: Rotate: Lost Pixels

Posted: Mon Mar 29, 2021 8:31 pm
by IdeasVacuum
Testing my examples here, it is still an issue. SetGadgetAttribute() places the image at 0,0 - i.e. the left and top image edges are on the edge of the canvas. No matter what values I apply to MovePathCursor(), this is never achieved after a rotate or flip.

.... that has me thinking that the Vector Lib has an issue too.

Re: Vector Lib: Rotate: Lost Pixels

Posted: Mon Mar 29, 2021 9:15 pm
by Saki
The behavior is now correct.
The problem was only that the left margin was out of range and so clipped away.

Code: Select all

Enumeration
#Win
#Canvas
#Img
EndEnumeration

UsePNGImageDecoder()

Procedure Win()
;#-------------

               If OpenWindow(#Win, 0, 0, 220, 220, "Rotate 90", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

                         SetWindowColor(#Win, RGB(064,252,064))
                           CanvasGadget(#Canvas, 10, 10, 200, 200)
               EndIf
EndProcedure

Procedure Vimg(x, y)
;#--------------
Protected dImgW.d, dImgH.d

               If LoadImage(#Img, "C:\Users\Tanaka\Desktop\Test.png")
                 
                 
                         dImgW = ImageWidth(#Img)
                         dImgH = ImageHeight(#Img)

                         Debug "dImgW-->" + StrD(dImgW) + "<--"
                         Debug "dImgH-->" + StrD(dImgH) + "<--"

                         SetGadgetAttribute(#Canvas, #PB_Canvas_Image, ImageID(#Img))

                         Delay(2000) ;just to see original orientation

                         If StartVectorDrawing(CanvasVectorOutput(#Canvas))

                                   VectorSourceColor(RGBA(255,255,255,255))
                                          AddPathBox(0, 0, 220, 220)
                                            FillPath()

                                      MovePathCursor(0, 0)
                                      MovePathCursor(dImgW * 0.50, dImgW * 0.50)
                                   RotateCoordinates(dImgW * 0.50, dImgW * 0.50, -(90))
                                      MovePathCursor(-1-y, 2+x)
                                     DrawVectorImage(ImageID(#Img), 255)

                                   StopVectorDrawing()
                         EndIf
               EndIf
EndProcedure

Win()
Vimg(10, 10)

Repeat
Until WaitWindowEvent(1) = #PB_Event_CloseWindow

Re: Vector Lib: Rotate: Lost Pixels

Posted: Mon Mar 29, 2021 11:09 pm
by IdeasVacuum
Hi Saki

I shall have a go with your new code thank you. I have in the meantime tested the code by Luis from September 2009, written for PB5.30, and that works perfectly in PB5.73 LTS 64bit :D

viewtopic.php?f=12&t=38975

So I think that does mean it's a PB bug in the Vector Lib.

Re: Vector Lib: Rotate: Lost Pixels

Posted: Mon Mar 29, 2021 11:23 pm
by IdeasVacuum
Hi Saki

Just tested your version of the code (verbatim except for the file path) and the resulting image is complete but it is 13pix away from the Canvas left edge and 11pix from the top edge (± 1pix) :mrgreen:

PB 5.73 LTS Windows 7 64bit

Re: Vector Lib: Rotate: Lost Pixels

Posted: Mon Mar 29, 2021 11:25 pm
by Saki
Hi,
yes, that is correct.
Your code can be used for a bug report.

Re: Vector Lib: Rotate: Lost Pixels

Posted: Mon Mar 29, 2021 11:28 pm
by IdeasVacuum
Moderator

Please move this post to Windows Bugs

Re: Vector Lib: Rotate: Lost Pixels

Posted: Tue Mar 30, 2021 1:34 am
by RASHAD
There is always light at the end of the tunnel
Adapt it for your needs

Code: Select all

Enumeration
#Win
#Canvas
#Img
EndEnumeration

UsePNGImageDecoder()

Procedure Win()
;#-------------

               If OpenWindow(#Win, 0, 0, 220, 220, "Rotate 90", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

                         SetWindowColor(#Win, RGB(064,252,064))
                           CanvasGadget(#Canvas, 10, 10, 200, 200)
               EndIf
EndProcedure

Procedure Vimg()
;#--------------
Protected dImgW.d, dImgH.d

               If LoadImage(#Img, "g:\mmedia\pic_test\Test.png")

                         dImgW = ImageWidth(#Img)
                         dImgH = ImageHeight(#Img)


                         SetGadgetAttribute(#Canvas, #PB_Canvas_Image, ImageID(#Img))

                         Delay(2000) ;just to see original orientation

                         If StartVectorDrawing(CanvasVectorOutput(#Canvas))
                            RotateCoordinates(80,110,90)
                            VectorSourceImage(ImageID(#Img))
                            FillVectorOutput()
                            ResetCoordinates()
                            StopVectorDrawing()
                         EndIf
               EndIf
EndProcedure

Win()
Vimg()

Repeat
Until WaitWindowEvent(1) = #PB_Event_CloseWindow

Re: Vector Lib: Rotate: Lost Pixels

Posted: Tue Mar 30, 2021 11:09 am
by Saki
You don't do it on the canvas anyway, you do it on temporary images.
It was primarily about the detection and handling of the bug.

Re: Vector Lib: Rotate: Lost Pixels

Posted: Tue Mar 30, 2021 11:50 am
by RASHAD
It's not your concern dear
You are not the owner of the thread
So keep quit and keep working with odometer, too many posts for nothing

Re: Vector Lib: Rotate: Lost Pixels

Posted: Tue Mar 30, 2021 12:17 pm
by Saki
Just like your post now dear ! :wink:

Re: Vector Lib: Rotate: Lost Pixels

Posted: Tue Mar 30, 2021 12:26 pm
by IdeasVacuum
Hi Rashad

Thanks for your response. As-is, the rotation results in a complete image, but my original code can do that too. The issue is that the image should be in the top corner of the Canvas (Canvas 0,0) - as it is before the rotate. If I add a Move Cursor to your code, it's result is the same as mine, close, but not close enough:

Code: Select all

Enumeration
#Win
#Canvas
#Img
EndEnumeration

UsePNGImageDecoder()

Procedure Win()
;#-------------

               If OpenWindow(#Win, 0, 0, 220, 220, "Rotate 90", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

                         SetWindowColor(#Win, RGB(064,252,064))
                           CanvasGadget(#Canvas, 10, 10, 200, 200)
               EndIf
EndProcedure

Procedure Vimg()
;#--------------
Protected dImgW.d, dImgH.d
Protected iImgCtrX.i, iImgCtrY.i

               If LoadImage(#Img, "C:\Test2.png")

                         dImgW = ImageWidth(#Img)
                         dImgH = ImageHeight(#Img)
                      iImgCtrX = Round(dImgW * 0.50, #PB_Round_Up)
                      iImgCtrY = Round(dImgH * 0.50, #PB_Round_Up)

                         SetGadgetAttribute(#Canvas, #PB_Canvas_Image, ImageID(#Img))

                         Delay(2000) ;just to see original orientation

                         If StartVectorDrawing(CanvasVectorOutput(#Canvas))
                             RotateCoordinates(iImgCtrY, iImgCtrX, 90)
                                MovePathCursor(iImgCtrX, iImgCtrX)
                             VectorSourceImage(ImageID(#Img))
                              FillVectorOutput()
                              ResetCoordinates()
                             StopVectorDrawing()
                         EndIf
               EndIf
EndProcedure

Win()
Vimg()

Repeat
Until WaitWindowEvent(1) = #PB_Event_CloseWindow