ImagePlugin Module (Cross platform multi format de-/encoder)

Share your advanced PureBasic knowledge/code with the community.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: ImagePlugin Module (Cross platform multi format de-/enco

Post by wilbert »

Keya wrote:confirmed encoder + decoder both working fine in my Windows XP 32, Windows 7 64, Linux Mint 32, Linux Mint 64, and OSX El Capitan 64. Has anyone been able to test on Windows 10? my W10 VM needs a makeover so i cant test atm
Thanks for reporting Keya :D
Nice to know it is working on all those OS versions.
Windows 10 is the Windows version I have so I can confirm it is working fine on Windows 10 as well. :wink:
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 627
Joined: Mon May 09, 2011 9:36 am

Re: ImagePlugin Module (Cross platform multi format de-/enco

Post by VB6_to_PBx »

Code: Select all

; Save as jpeg with quality 70
  SaveImage(1, "test_jpg.jpg", #SystemImagePlugin, #SystemImagePlugin_JPEG | 20)
the JPEG Quality setting does not seem to change the actual Quality of the Saved Image or the file size

setting anywhere between 10 to 100 makes no difference ??
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: ImagePlugin Module (Cross platform multi format de-/enco

Post by netmaestro »

My tests confirm no filesize change between jpeg quality setting 10 vs 100 on Windows 7 x64 with PB 5.5 x86.

May I ask what is the purpose of this approach to SaveImage for the jpeg encoder: [..], #SystemImagePlugin_JPEG | <quality> when the PureBasic SaveImage command has a parameter following imageplugin for flags, which is where PB currently handles its own jpeg quality?
BERESHEIT
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: ImagePlugin Module (Cross platform multi format de-/enco

Post by wilbert »

VB6_to_PBx wrote:the JPEG Quality setting does not seem to change the actual Quality of the Saved Image or the file size
I find it difficult sometimes how to convert a C structure to PureBasic, when to use #PB_Structure_AlignC or not.
I made some changes to the structure definitions on Windows. Please test it and let me know if it works now.
netmaestro wrote:May I ask what is the purpose of this approach to SaveImage for the jpeg encoder: [..], #SystemImagePlugin_JPEG | <quality> when the PureBasic SaveImage command has a parameter following imageplugin for flags, which is where PB currently handles its own jpeg quality?
For every encoder plugin you register, you need two functions Encode24 and Encode32 (if you want to support 32 bit as well).
Encoding is almost the same for every image type so instead of registering an individual plugin for every image type, I chose to use one named #SystemImagePlugin .
You put this where you normally specify the plugin like #PB_ImagePlugin_PNG . This leaves only one argument left for the procedure that can be used (Flags) and for JPEG you need to specify both the format and the quality so I had to combine those into one value.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: ImagePlugin Module (Cross platform multi format de-/enco

Post by netmaestro »

Ok, thanks for the explanation, I don't see any real downside to doing it that way, the alternative being multiple Use[..] commands. This is clean, compact and quite usable. I like it.
Please test it and let me know if it works now.
On a more somber note: still no difference in jpeg filesize between quality 20 and quality 100.
BERESHEIT
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: ImagePlugin Module (Cross platform multi format de-/enco

Post by wilbert »

netmaestro wrote:On a more somber note: still no difference in jpeg filesize between quality 20 and quality 100.
That's strange :?
I tested both x86 and x64 version on Windows 10 and tried 5 different quality settings and all gave a different filesize.
Are you sure you tried the updated code ?
Windows (x64)
Raspberry Pi OS (Arm64)
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: ImagePlugin Module (Cross platform multi format de-/enco

Post by walbus »

A short test v1.52 on Linux Mint x64 and Win10 x64 looking absolutely OK with jpg quality settings
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: ImagePlugin Module (Cross platform multi format de-/enco

Post by netmaestro »

False alarm here, my test was faulty. A proper test with a suitable image shows significant filesize changes with different qualities. Sorry for the inconvenience.
BERESHEIT
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: ImagePlugin Module (Cross platform multi format de-/enco

Post by wilbert »

Thanks for testing.
Good to hear it is working now. :)
Windows (x64)
Raspberry Pi OS (Arm64)
PeDe
Enthusiast
Enthusiast
Posts: 278
Joined: Sun Nov 26, 2017 3:13 pm

Re: ImagePlugin Module (Cross platform multi format de-/enco

Post by PeDe »

I used the ImagePlugin from wilbert for a longer time without any problems.
But now I have a problem that I do not understand. When I load an image from a file or from memory that is not in BMP format, the format is not recognized and scaling the image is very slow. With a BMP format I do not have this problem.
When I use the PureBasic decoders everything works normally.

I have provided here an example with test images (200 kB):
https://peter.dreisiebner.at/purebasic/ ... ginPng.zip

I have tested with Windows 7 x64 and PureBasic x86 and x64. I use a slow PC, scaling takes ~ 0.3 seconds.
Does anyone know what the problem could be?

Peter
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: ImagePlugin Module (Cross platform multi format de-/enco

Post by Saki »

On Win 10 I see no negative effect
地球上の平和
PeDe
Enthusiast
Enthusiast
Posts: 278
Joined: Sun Nov 26, 2017 3:13 pm

Re: ImagePlugin Module (Cross platform multi format de-/enco

Post by PeDe »

Saki wrote:On Win 10 I see no negative effect
When you scale the window, you don't have any jerking, you don't see any difference between BMP and PNG/JPG?
Probably your PC is so fast.

Peter
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: ImagePlugin Modul (Cross-Plattform Multi-Format de-/enco

Post by Saki »

Hi,
i use 4K Resolution.
On Full Desktop-size image all OK.
But on a modern very fast Machine.
Last edited by Saki on Tue Sep 01, 2020 9:56 am, edited 2 times in total.
地球上の平和
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: ImagePlugin Module (Cross platform multi format de-/enco

Post by wilbert »

PeDe wrote:I used the ImagePlugin from wilbert for a longer time without any problems.
But now I have a problem that I do not understand. When I load an image from a file or from memory that is not in BMP format, the format is not recognized and scaling the image is very slow. With a BMP format I do not have this problem.
When I use the PureBasic decoders everything works normally.
Unfortunately I don't have Windows 7 to test with.
The only difference I can think of once the image has been decoded is that the PureBasic JPG and PNG decoders decode to 24 bit and the ImagePlugin module always decodes to 32 bit internally.
What you could try is create a 24 bit image and draw the loaded image to that so you got a 24 bit copy of it but on most computers 32 bit shouldn't be a problem.

If you have a very old PC, the live resize may cause a delay.
When you resize the image the resize event occurs a lot of times. All those events are placed in a queue.
When the drawing procedure can't keep up, it will result in a delay since it still processes all the resize events places in the queue.
Windows (x64)
Raspberry Pi OS (Arm64)
PeDe
Enthusiast
Enthusiast
Posts: 278
Joined: Sun Nov 26, 2017 3:13 pm

Re: ImagePlugin Module (Cross platform multi format de-/enco

Post by PeDe »

Thanks wilbert,
your idea with the conversion to 24 bit works. Scaling is again as fast as with the internal decoders.
My graphics card is set to 32 bit, is an integrated Intel HD in a Celeron J1900.

Peter
Post Reply