Image Rotation routines for 24/32 bit with optional AA

Share your advanced PureBasic knowledge/code with the community.
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Image Rotation routines for 24/32 bit with optional AA

Post by luis »

Made some little modifications to my copy of the sources so I've updated them here too.
"Have you tried turning it off and on again ?"
A little PureBasic review
zikitrake
Addict
Addict
Posts: 834
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Re: Image Rotation routines for 24/32 bit with optional AA

Post by zikitrake »

First of all, thank you for this great contribution!

When I try RotateImageFree with flgAntiAliasing enabled sometime it get me an Invalid Memory in line 531 (icr = *tRGBAs\R * fXfs1less)
As with this image https://drive.google.com/file/d/1qBv3P0 ... j_enH/view
Simple code:

Code: Select all

;This code fails

UseJPEGImageDecoder()
UsePNGImageDecoder()
Define imgOrigen = LoadImage(#PB_Any, "d:\himalayas.jpg")
Define imgDestino = RotateImageFree(imgOrigen, 45, #True)
If IsImage(imgDestino)
  Debug "rotation OK"
EndIf
I suspect it may be because of the width/height ratio (1344x350), because if I rotate it previously 90º, it works fine.

Code: Select all

;This code works fine

UseJPEGImageDecoder()
UsePNGImageDecoder()
Define imgOrigen = LoadImage(#PB_Any, "d:\himalayas.jpg")
Define imgOrigen90 = RotateImage(imgOrigen, 90)
Define imgDestino = RotateImageFree(imgOrigen90, 45, #True)
If IsImage(imgDestino)
  Debug "rotation OK"
EndIf
If you disable AntiAliasing flags both codes work fine.
zikitrake
Addict
Addict
Posts: 834
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Re: Image Rotation routines for 24/32 bit with optional AA

Post by zikitrake »

:oops: Sorry, I was deleted the image link in my previous post
Image
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Image Rotation routines for 24/32 bit with optional AA

Post by luis »

Hi there zikitrake, sorry but I saw your post only today, I come to the forum very infrequently now and I'm not into the "purebasic scene" any longer so to speak :)
I will look into it this evening, it looks like the a rounding problem and the code sometimes goes out of bounds accessing the buffer memory beyond the x-y boundaries of the rotated image. I'll try to fix it.
Bye !

EDIT: Should work now.
I made a loop from 0 to 360 to rotate your test image one degree at a time and it didn't crash.
https://www.purebasic.fr/english/viewto ... 73#p298873
Last edited by luis on Thu Apr 21, 2022 10:48 am, edited 1 time in total.
"Have you tried turning it off and on again ?"
A little PureBasic review
zikitrake
Addict
Addict
Posts: 834
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Re: Image Rotation routines for 24/32 bit with optional AA

Post by zikitrake »

luis wrote: Wed Apr 20, 2022 7:10 pm Hi there zikitrake, sorry but I saw your post only today, I come to the forum very infrequently now and I'm not into the "purebasic scene" any longer so to speak :)
Sorry to read this. I hope it's for something positive for you!
You are part (personally speaking) of that group of users that give so much value to Purebasic. Best regards!
EDIT: Should work now.
I made a loop from 0 to 360 to rotate your test image one degree at the time and it didn't crash.
https://www.purebasic.fr/english/viewto ... 73#p298873
It works perfectly, as you would expect! :D
Post Reply