Page 1 of 2
More precise quality for saveimage.
Posted: Sat Dec 10, 2005 9:44 am
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.
Posted: Sat Dec 10, 2005 10:36 am
by nco2k
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
Posted: Sat Dec 10, 2005 10:58 am
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.

Posted: Sat Dec 10, 2005 11:13 am
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
no but serious, i think the other apps do the same thing.
c ya,
nco2k
Posted: Sat Dec 10, 2005 11:22 am
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.

Posted: Sat Dec 10, 2005 11:43 am
by PB
> Besides, 1-100 sounds, um, intuitive.
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.
Posted: Sat Dec 10, 2005 11:46 am
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.
Posted: Sat Dec 10, 2005 12:16 pm
by Dare2
I still like the idea of 1-100. Even if PureBasic fudges as per nco2k's example.

Posted: Sat Dec 10, 2005 12:44 pm
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)
Posted: Sat Dec 10, 2005 3:52 pm
by blueznl
and such a complex one at that!

Re: More precise quality for saveimage.
Posted: Sat Dec 10, 2005 11:30 pm
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.
Posted: Sun Dec 11, 2005 5:42 am
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.
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.
@CONVERT
can you email me the example file you tried, so i can test it with ps.
c ya,
nco2k
Posted: Sun Dec 11, 2005 12:00 pm
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
Posted: Sun Dec 11, 2005 12:24 pm
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.
Posted: Sun Dec 11, 2005 1:19 pm
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.
p.s.: the saved image was destroyed by using lvl0.
@CONVERT
thanks for sharing.
c ya,
nco2k