More precise quality for saveimage.
More precise quality for saveimage.
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.
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).
Come back to 6.11 LTS 64 bits because of an issue with #PB_ComboBox_UpperCase in ComboBoxGadget() (Oct. 10, 2024).
0 to 100 ?!!??!
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.
photoshop for example, provides a quality from 0-12.
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

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.


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

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
> 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.
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.
"PureBasic won't be object oriented, period" - Fred.
@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:
no but serious, i think the other apps do the same thing.
c ya,
nco2k
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



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

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Yes, 0 to 100.
It is the case of Ulead PhotoImpact, even in the old versions.
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.
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)
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).
Come back to 6.11 LTS 64 bits because of an issue with #PB_ComboBox_UpperCase in ComboBoxGadget() (Oct. 10, 2024).
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.
"PureBasic won't be object oriented, period" - Fred.
and such a complex one at that!


( 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... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
-
- Enthusiast
- Posts: 362
- Joined: Wed Aug 06, 2003 2:49 pm
- Location: Venice - Italy, Japan when possible.
- Contact:
Re: More precise quality for saveimage.
This is what happens when a programmer have never seriously used a paint program 
As correctly CONVERT stated:
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.

As correctly CONVERT stated:
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.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.
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.
@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.
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:
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:
and when i look at this:
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.
@CONVERT
can you email me the example file you tried, so i can test it with ps.
c ya,
nco2k
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.

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
but look at purebasic:
Code: Select all
purebasic quality 8 - 95.4kb
purebasic quality 9 - 125kb
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)
because the pb encoder is actually not the "best" one, maybe more precision control would be helpfull here.
but thats fred's decision anyway.

@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
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:
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).
Come back to 6.11 LTS 64 bits because of an issue with #PB_ComboBox_UpperCase in ComboBoxGadget() (Oct. 10, 2024).
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.
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).
Come back to 6.11 LTS 64 bits because of an issue with #PB_ComboBox_UpperCase in ComboBoxGadget() (Oct. 10, 2024).
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

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.

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

@CONVERT
thanks for sharing.

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