More precise quality for saveimage.

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
CONVERT
Enthusiast
Enthusiast
Posts: 130
Joined: Fri May 02, 2003 12:19 pm
Location: France

More precise quality for saveimage.

Post by CONVERT »

Hello,

The saveimage command allows quality from 0 to 10 by step of 1.

Would it be possible to set quality from 0 to 100 in a future version of PB?

I build photos web sites. Sometimes 8 is not enough, and 9 gives sometimes big file. I would try 8.5, as it is possible in photo softs.

Thanks
Jean.
PureBasic 6.20 beta 2 (x64) | Windows 10 Pro x64 | Intel(R) Core(TM) i7-8700 CPU @ 3.20Ghz 16 GB RAM, SSD 500 GB, PC locally assembled.
Come back to 6.11 LTS 64 bits because of an issue with #PB_ComboBox_UpperCase in ComboBoxGadget() (Oct. 10, 2024).
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Post by nco2k »

0 to 100 ?!!??! :shock:

i really dont think, this is a good idea. i dont even know if this is possible due the jpeg format specifications. :?

if 8 is not enough for you, then use 9. with 9 i cant see any difference, if i dont zoom the image. so where is the problem. :?: otherwise use 10. if 10 is not enough, you should be maybe using, a different format, like png, targa or tiff for example. :idea:

photoshop for example, provides a quality from 0-12. :wink:

p.s.: the size depends on the image itself. you can save two different files, one with a lot of stuff on it, the other with just few. save them both with the same flag and you will see, its a big difference in size, for each file. it depends on, how good the image can be compressed.

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> photoshop for example, provides a quality from 0-12

But Paint Shop Pro allows 1-100 for JPG quality, as do other apps and third
party tools (eg. the ever-popular NViewLib.dll). I think 1-100 is a standard.
I'd never seen just 1-10 except in PureBasic, so I can fully relate as to why
Convert's asking for it. Even one of my friends asked me why my app only
lets me select 1-10 for JPG saving; I told him they're 10%, 20%, and so on
up to 100%. He didn't like the explanation. :(
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Post by nco2k »

@PB
yes maybe, but i think internal its really 0-100%. so maybe you should just check in your app the quality step.

something like:

Code: Select all

Quality.s = "74"
If Val(Quality) => 0 And Val(Quality) <= 100
  If Val(Mid(Quality, Len(Quality), Len(Quality))) => 5
    Debug Val(Mid(Quality, 1, Len(Quality) - 1)) + 1
  Else
    Debug Val(Mid(Quality, 1, Len(Quality) - 1))
  EndIf
EndIf
:lol: :lol: :lol:

no but serious, i think the other apps do the same thing. :)

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

I haven't tried this for a while but I recall that down the other end of the scale the differences are (were?) quite dramatic and can (could have?) use(d) some in-between value.

Besides, 1-100 sounds, um, intuitive. :D
@}--`--,-- A rose by any other name ..
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> Besides, 1-100 sounds, um, intuitive. :D

Isn't it meant to mean a percentage of the original quality? So if you saved
at 50%, then the saved image would only look half as good as the original.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
CONVERT
Enthusiast
Enthusiast
Posts: 130
Joined: Fri May 02, 2003 12:19 pm
Location: France

Post by CONVERT »

Yes, 0 to 100.

It is the case of Ulead PhotoImpact, even in the old versions.

Code: Select all

An example with Ulead PhotoImpact 11,

for a 800 x 600 pixels JPEG (size in KB):

Quality       PB    Ulead
    8        111      140  (not quite good for mountains in the sky)
    8.5               158  (good quality)
    9        165      189  (good quality)
In fact, the 9 of PB is near of 8.5 of Ulead, in size and quality, and is sufficient.

So, you're right. It is not useful to have more precise quality.

Jean.
PureBasic 6.20 beta 2 (x64) | Windows 10 Pro x64 | Intel(R) Core(TM) i7-8700 CPU @ 3.20Ghz 16 GB RAM, SSD 500 GB, PC locally assembled.
Come back to 6.11 LTS 64 bits because of an issue with #PB_ComboBox_UpperCase in ComboBoxGadget() (Oct. 10, 2024).
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

I still like the idea of 1-100. Even if PureBasic fudges as per nco2k's example. :)
@}--`--,-- A rose by any other name ..
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Here's a procedure to convert a percentage (1-100) to PureBasic's range (1-10):

Code: Select all

Procedure SelectJPGSetting(percentage)
  purebasic.f=percentage/10
  If ValF(Mid(StrF(purebasic),2,9))>0.4 : roundup=1 : EndIf
  ProcedureReturn Round(purebasic,roundup)
EndProcedure

Debug SelectJPGSetting(74)
Debug SelectJPGSetting(75)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

and such a complex one at that!

:-P
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Blade
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Aug 06, 2003 2:49 pm
Location: Venice - Italy, Japan when possible.
Contact:

Re: More precise quality for saveimage.

Post by Blade »

This is what happens when a programmer have never seriously used a paint program :)

As correctly CONVERT stated:
CONVERT wrote:I build photos web sites. Sometimes 8 is not enough, and 9 gives sometimes big file. I would try 8.5, as it is possible in photo softs.
The difference between 80% ( 8 ) and 90% ( 9 ) is huge: many times the quality difference can't be easily seen, but the file size is way bigger.
This is not linear too: between 50% or 60%, visually there is a big difference, but the file size doesn't change much. At higher quality level, the visual difference is low, and the file size difference is high.
So yes, we need a better control on file saving quality.
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Post by nco2k »

@Blade
well i dont know, about any paint programms, because i am used to the professional photoshop and this is with no doubt the best app you can get. :D

if you want more control about the quality/size, you should better request for optimizations, like baseline and multipass.

i tried a 2.25mb wallpaper with different settings in photoshop:

Code: Select all

quality 8, baseline standard - 139kb
quality 8, baseline optimized - 136kb
quality 8, multipass 3 - 137kb
quality 8, multipass 4 - 137kb
quality 8, multipass 5 - 137kb

quality 9, baseline standard - 150kb
quality 9, baseline optimized - 145kb
quality 9, multipass 3 - 147kb
quality 9, multipass 4 - 147kb
quality 9, multipass 5 - 148kb
for me at least, there is no need for more precise quality control. i wont die if the file gets 10kb bigger.

but look at purebasic:

Code: Select all

purebasic quality 8 - 95.4kb
purebasic quality 9 - 125kb
and when i look at this:

Code: Select all

An example with Ulead PhotoImpact 11, 

for a 800 x 600 pixels JPEG (size in KB): 

Quality       PB    Ulead 
    8        111      140  (not quite good for mountains in the sky) 
    8.5               158  (good quality) 
    9        165      189  (good quality)
the size difference is pretty strange. so maybe ps has "only" 0-12 because the encoder is simple better and it would not take any big effect if they would have 0-100.

because the pb encoder is actually not the "best" one, maybe more precision control would be helpfull here.

but thats fred's decision anyway. :wink:

@CONVERT
can you email me the example file you tried, so i can test it with ps.

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
User avatar
CONVERT
Enthusiast
Enthusiast
Posts: 130
Joined: Fri May 02, 2003 12:19 pm
Location: France

Post by CONVERT »

You can load the image from here:

http://pg.ctjean.com/tests/Out_ulead9157_100.JPG

It is a 800 x 600 photo. 449 KB.

Here is the code to test saveimage:

Code: Select all

; test quality saveimage

UseJPEGImageDecoder()
UseJPEGImageEncoder()

wfile_in$  = "Out_ulead9157_100.JPG"

If LoadImage(0,wfile_in$) = 0
  MessageRequester("Test save image quality","Err loadimage " + wfile_in$)
  End
EndIf

For quality = 80 To 90 Step 5
  wfile_dest$ = "OUT_" + Str(quality) + "_PB.JPG"
  w.f = quality / 10
  If SaveImage(0, wfile_dest$ , #PB_ImagePlugin_JPEG , w.f) = 0
    MessageRequester("Test save image quality","Err saveimage " + wfile_dest$ + " " + StrF(w.f,2))
  EndIf
Next quality

End
PureBasic 6.20 beta 2 (x64) | Windows 10 Pro x64 | Intel(R) Core(TM) i7-8700 CPU @ 3.20Ghz 16 GB RAM, SSD 500 GB, PC locally assembled.
Come back to 6.11 LTS 64 bits because of an issue with #PB_ComboBox_UpperCase in ComboBoxGadget() (Oct. 10, 2024).
User avatar
CONVERT
Enthusiast
Enthusiast
Posts: 130
Joined: Fri May 02, 2003 12:19 pm
Location: France

Post by CONVERT »

An add to my precedent message.

The true original photo is here:

http://pg.ctjean.com/tests/DSCN9157.JPG

2560 x 1920 (1,6 MB)

It shows many details (the houses in the village), and a difficult part to compress for jpeg (the sky just above the mountains).

It comes from a CoolPix 5700 in fine quality.

I used Ulead PhotoImpact 11 to resize it at 800 x 600, then saved in jpeg with 100 % quality, with no mask, mode progressive and subsampling = YUV411. These are the default options.

This gives http://pg.ctjean.com/tests/Out_ulead9157_100.JPG

800 x 600 (449 KB)

And I use this file to save it with PB, with 8 and 9 qualities.
PureBasic 6.20 beta 2 (x64) | Windows 10 Pro x64 | Intel(R) Core(TM) i7-8700 CPU @ 3.20Ghz 16 GB RAM, SSD 500 GB, PC locally assembled.
Come back to 6.11 LTS 64 bits because of an issue with #PB_ComboBox_UpperCase in ComboBoxGadget() (Oct. 10, 2024).
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Post by nco2k »

Code: Select all

photoshop quality 0, baseline standard - 47.9kb
photoshop quality 0, baseline optimized - 45.4kb

photoshop quality 1, baseline standard - 51.4kb
photoshop quality 1, baseline optimized - 49.1kb

photoshop quality 2, baseline standard - 61.9kb
photoshop quality 2, baseline optimized - 59.7kb

photoshop quality 3, baseline standard - 84.6kb
photoshop quality 3, baseline optimized - 81.0kb

photoshop quality 4, baseline standard - 97.5kb
photoshop quality 4, baseline optimized - 93.8kb

photoshop quality 5, baseline standard - 113.0kb
photoshop quality 5, baseline optimized - 109.0kb

photoshop quality 6, baseline standard - 137.0kb
photoshop quality 6, baseline optimized - 134.0kb

photoshop quality 7, baseline standard - 132.0kb <- strange, smaller than lvl6
photoshop quality 7, baseline optimized - 127.0kb <- strange, smaller than lvl6

photoshop quality 8, baseline standard - 169.0kb
photoshop quality 8, baseline optimized - 166.0kb

photoshop quality 9, baseline standard - 208.0kb
photoshop quality 9, baseline optimized - 206.0kb

photoshop quality 10, baseline standard - 267.0kb
photoshop quality 10, baseline optimized - 264.0kb

photoshop quality 11, baseline standard - 370.0kb
photoshop quality 11, baseline optimized - 365.0kb

photoshop quality 12, baseline standard - 524.0kb
photoshop quality 12, baseline optimized - 507.0kb


purebasic quality 0 - 8.28kb <- destroyes the image
purebasic quality 1 - 18.7kb
purebasic quality 2 - 31.7kb
purebasic quality 3 - 42.8kb
purebasic quality 4 - 52.3kb
purebasic quality 5 - 61.3kb
purebasic quality 6 - 71.3kb
purebasic quality 7 - 86.5kb
purebasic quality 8 - 110.0kb
purebasic quality 9 - 164.0kb
purebasic quality 10 - 452.0kb <- huge difference
i havent tested multipass, because i am too lazy. :)

in overall the pb size is smaller, but the quality is not that good. lvl8 is ok and lvl9 is good, but everything below is bad imho. the lvl9 -> lvl10 size difference is way too big. so yes, we need a more precise quality control. for me, 0-12 would be more than enough, but fine, if you guys want 0-100 then lets vote for 0-100. :wink:

p.s.: the saved image was destroyed by using lvl0. :shock:

@CONVERT
thanks for sharing. 8)

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Post Reply