Page 2 of 5

Posted: Mon Dec 15, 2008 10:19 am
by srod
pant pant drool drool hubba hubbaa woof woof........

Aye, and the girl's not bad either!

I think this is another instance when that Sparkie fella start's worring! :wink:

Seriously; some excellent work here netty. Great stuff.

Posted: Mon Dec 15, 2008 10:36 am
by djes
Great! This is how "levels" works (one of the most useful photoshop's tool). It creates an histogram of used colours, and you can see how colours are used in the picture, to adjust them accordingly to your perception, the black and white points, and so on.
Now it's time for dithering ;)

Posted: Mon Dec 15, 2008 12:25 pm
by Rings
great work!!

Posted: Mon Dec 15, 2008 2:28 pm
by Coolman
There is an error message:

'Ligne 188 :ArraySize() is not a function, array, macro or linked list'

Add this :

; Author: freak (updated for PB 4.00 by Deeem2031)
Procedure ArraySize(*Array)
ProcedureReturn PeekL(*Array-8)
EndProcedure

great work

However, IrfanView is more efficient ...

Posted: Mon Dec 15, 2008 4:47 pm
by srod
On PB 4.3, ArraySize() is a native function.

Posted: Tue Dec 16, 2008 2:52 pm
by Coolman
srod wrote:On PB 4.3, ArraySize() is a native function.
******************
; Library commands: ImageTo8bit() and Save8bitImage()
; Author: Lloyd Gallant (netmaestro)
; Date: December 12, 2008
; Target OS: Microsoft Windows All
; Target Compiler: PureBasic 4.0 and later
; License: Free, unrestricted, no warranty
******************

I thought it was compatible PureBasic 4.00...

However, good to know, I never used a beta version of PureBasic

8)

Posted: Wed Dec 17, 2008 4:01 am
by netmaestro
-Fixed a bug where some images were being rendered upside down

-Modified the adaptive colortable routine to avoid placing duplicate entries in the color table

-Removed some small memory leaks

Code is updated in the first post.

Posted: Wed Dec 17, 2008 11:41 am
by srod
netmaestro wrote:-Fixed a bug where some images were being rendered upside down
Interested to see how you fixed that part! :) Had decided that the best way was to retrieve the DIB bits first as there seems to be no simple way of getting a hold of a valid bitmapinfoheader structure for the original DIB etc. I think you've just confirmed my supposition! :)

Again, great code.

Posted: Wed Dec 17, 2008 1:16 pm
by netmaestro
Yes, the trick is to get the DIBits in the same format that you're going to set them. I was taking a shortcut and just feeding SetDIBits the pointer from the object but I see now that you can't do that. The quality difference between this and the professional programs seems to be in the lack of dithering. I have no idea how to do dithering but I'll research it and give it a go. Any thoughts or suggestions on approach would be most appreciated.

Posted: Wed Dec 17, 2008 2:07 pm
by djes
netmaestro wrote:Yes, the trick is to get the DIBits in the same format that you're going to set them. I was taking a shortcut and just feeding SetDIBits the pointer from the object but I see now that you can't do that. The quality difference between this and the professional programs seems to be in the lack of dithering. I have no idea how to do dithering but I'll research it and give it a go. Any thoughts or suggestions on approach would be most appreciated.
http://en.wikipedia.org/wiki/Floyd-Steinberg_dithering

Posted: Sun Jan 04, 2009 1:45 am
by LCD
Great work! The MSX2 Palette is excellent for ordered dither (I included it in my Retro-X), because you can dither 3, 3 and 2 Bits (8, 8 and 4 levels) and join the bits together.
The adaptive palette calculation is something I was looking for, for the Sprinter 2000 picture conversion.

Posted: Sun Jan 04, 2009 7:57 am
by Blue
As you say, netmaestro, the adaptive colortable delivers a truly amazing approximation of the original color distribution.
Very nice work and demonstration.

Now waiting for the dithering procedure to clear up the blotches on that poor girl's skin :shock:
She must be impatient too... :lol:

BTW:
to better compare the original picture with the modified one, i added 3 lines to your example code, just before the Events loop:

Code: Select all

j = hImage
OpenWindow(1,WindowWidth(0)+24,0,ImageWidth(j),ImageHeight(j),"") 
ImageGadget(1,0,0,0,0,ImageID(j))

Posted: Sun Jan 04, 2009 9:51 am
by Michael Vogel
Blue wrote: BTW:
to better compare the original picture with the modified one, i added 3 lines to your example code, just before the Events loop:

Code: Select all

j = hImage
OpenWindow(1,WindowWidth(0)+24,0,ImageWidth(j),ImageHeight(j),"") 
ImageGadget(1,0,0,0,0,ImageID(j))
Cool Code, thanks :!:

For even more comfort, you can add some constants...

Code: Select all

#Eight_BlackWhite=0
#Eight_StandardPalette=1
#Eight_AdaptivePalette=2

hImage = LoadImage(#PB_Any, "girl.jpg")
i = ImageTo8bit(hImage, #Eight_AdaptivePalette,0)
and name the windows "8 Bit Picture" and "Original Picture" - because the new picture can look quite similar like the original (because netmaestro did a brilliant job -- once again)

Posted: Mon Jan 05, 2009 1:14 am
by LCD
Just changed the code a little for testing 16 colours Palette reduction, and it still looks very okay. It can be easy modified to work with almost any number of colours.

Posted: Sun Aug 30, 2009 8:57 pm
by netmaestro
Code is updated to work with PB v4.40, should still be fine with earlier versions of PB.