Vector Lib: Rotate: Lost Pixels

Windows specific forum
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Vector Lib: Rotate: Lost Pixels

Post 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
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: Vector Lib: Rotate: Lost Pixels

Post 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
地球上の平和
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Vector Lib: Rotate: Lost Pixels

Post by IdeasVacuum »

it is a old "unknown" bug on Windows.
Wow, thanks Saki - really surprised that MS would just leave it like that :shock:
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: Vector Lib: Rotate: Lost Pixels

Post by Saki »

Hi, it is a PB Bug
Best Regards Saki
地球上の平和
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Vector Lib: Rotate: Lost Pixels

Post 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.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: Vector Lib: Rotate: Lost Pixels

Post 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
地球上の平和
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Vector Lib: Rotate: Lost Pixels

Post 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.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Vector Lib: Rotate: Lost Pixels

Post 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
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: Vector Lib: Rotate: Lost Pixels

Post by Saki »

Hi,
yes, that is correct.
Your code can be used for a bug report.
Last edited by Saki on Sun Apr 04, 2021 9:37 pm, edited 1 time in total.
地球上の平和
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Vector Lib: Rotate: Lost Pixels

Post by IdeasVacuum »

Moderator

Please move this post to Windows Bugs
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4637
Joined: Sun Apr 12, 2009 6:27 am

Re: Vector Lib: Rotate: Lost Pixels

Post 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
Egypt my love
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: Vector Lib: Rotate: Lost Pixels

Post 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.
地球上の平和
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4637
Joined: Sun Apr 12, 2009 6:27 am

Re: Vector Lib: Rotate: Lost Pixels

Post 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
Egypt my love
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: Vector Lib: Rotate: Lost Pixels

Post by Saki »

Just like your post now dear ! :wink:
地球上の平和
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Vector Lib: Rotate: Lost Pixels

Post 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
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply