Author Topic: Cheap Dithering?  (Read 3962 times)

0 Members and 1 Guest are viewing this topic.

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Cheap Dithering?
« on: July 29, 2008 »
Anyone know how dithering works, cos I havent a clue. Of course this is for the compo so its extreme dithering I need with only 4 colours to choose from. Any body here that can explain how to match a colour to a 4 colour pallet

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17394
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Cheap Dithering?
« Reply #1 on: July 29, 2008 »
It depends on how you're going about writing the program.

I am using software rendering so for the bits that will need dithering I'm going to have several pre-calculated buffers that I can copy dithered pixels straight out of.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1292
  • Karma: 466
    • View Profile
    • my stuff
Re: Cheap Dithering?
« Reply #2 on: July 29, 2008 »
Wikipedia: Dithering in image processing.
Since you're aiming for a low-resolution, the dither-matrix shouldn't be too random.

Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Cheap Dithering?
« Reply #3 on: July 29, 2008 »
Would it be easier if I sort of work backwards, If I start with my 4 colours then make many colours from them so I will have say 10 4x4 blocks for 10 different colours then use those blocks to make images. Rather than starting with the image and reducing the colours

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Cheap Dithering?
« Reply #4 on: July 29, 2008 »
That will work.  Maybe a 2x2, with each one having 1 of the 4 colours, that gives you a lot more combinations, but effectively it halves the screen resolution as your 'pixels' are now 2x2.

To work out which colour is the closest to another, you can use Pythagoras on the rgb values.  ie.
distance_between_colours = (r1-r2)^2  +  (g1-g2)^2 + (b1-b2)^2
(no need to do the square root)
pick the shortest distance.

A better visual result comes from converting both colours from RGB to HSV and doing Pythagoras on those values.

Jim
Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Cheap Dithering?
« Reply #5 on: July 29, 2008 »
So I compute the distance between the colour I want to dither and all the colours in the pallete and choose the smallest distance.

Thanks Jim I will play around with this and see what I can do with it. I think I will stick with comparing rgb values for simplicity.

Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1292
  • Karma: 466
    • View Profile
    • my stuff
Re: Cheap Dithering?
« Reply #6 on: July 30, 2008 »
Quote
I compute the distance between the colour I want to dither and all the colours in the pallete and choose the smallest distance.
That's quantization.
But you also want to quantize the surrounding pixels in such a manner that the pixels' average represent the desired colour as closely as possible.
Another tricky task is to select a colour-table which introduces the smallest average error (check neural networks).
And, as Jim pointed out already, you should perform all these operations in a colour-model which closely represents human perception.
Challenge Trophies Won:

Offline stormbringer

  • Time moves by fast, no second chance
  • Amiga 1200
  • ****
  • Posts: 453
  • Karma: 73
    • View Profile
    • www.retro-remakes.net
We once had a passion
It all seemed so right
So young and so eager
No end in sight
But now we are prisoners
In our own hearts
Nothing seems real
It's all torn apart

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17394
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Cheap Dithering?
« Reply #8 on: July 30, 2008 »
It's a really cool topic, however, if you are going to use dithering, you may find it's use limited :)

Don't forget that the resolution is pretty blocky for the competition and the colour blending side effect will be largely lost due to the big pixels.

Unless of course you intend to use a higher resolution (which is still legal for the comp as long as you only use 4 colours).

This task is a really tough challenge but it's good that anyone can have a go at it.
Shockwave ^ Codigos
Challenge Trophies Won: