Author Topic: About Colour Palettes[BB2D]  (Read 6458 times)

0 Members and 1 Guest are viewing this topic.

Offline mike_g

  • Amiga 1200
  • ****
  • Posts: 435
  • Karma: 34
    • View Profile
About Colour Palettes[BB2D]
« on: March 16, 2007 »
Using a colour palette is fast, but what happens when you use bitmap images with them? It seems to work very well for creating stuff like gradients (the Pixel Fire fire .bb code being one of my favorites), but if you use images then how do you know where in the array each colour is?

I dont know maybe I dont quite understand the concept yet, or is this just a limitation/complexity that comes with using palettes?
« Last Edit: July 21, 2007 by Shockwave »

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17417
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: About Colour Palettes
« Reply #1 on: March 16, 2007 »
Usually I'd use palettes just for the effect Mike, I'd use them usually where some alpha is needed because it simplifies the calculations and makes it a lot faster.

When you put an image into the equation it gets different for the reasons that you said.
If you just want to draw a logo, render your palletted effect and then just draw the logo over the top.

If you want your logo to be part of the effect then you need to create a palette for your logo which is a pain in the arse and fiddly.. It can be done though.

If you are going to convert a logo to a palette, the fewer colours it uses, the easier it would be. You'll need to write a utility to convert the logo into two seperate files. A palette file and a bitmap file.

The bitmap file should contain X*Y indexes to a colour palette.

For example, pixel 0,0 could be : 10 which in the colour palette would be $FF00FF for instance.

I don't know if thats vague, if it's not clear, please post again and I'll explain further..
Shockwave ^ Codigos
Challenge Trophies Won:

Offline mike_g

  • Amiga 1200
  • ****
  • Posts: 435
  • Karma: 34
    • View Profile
Re: About Colour Palettes
« Reply #2 on: March 16, 2007 »
Yeah Its one of those things I couldent work out when I was using sprites. Anyway I'm going to have a go at using palettes for some stuff, as I still aint got around to it. Maybe a simple greyscale overlay might be able to produce some cool effects. I'll see what I can come up with, cheers.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17417
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: About Colour Palettes
« Reply #3 on: March 16, 2007 »
Please post what you do.. If you are stuck or dont understand it all, please post again :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Tetra

  • DBF Aficionado
  • ******
  • Posts: 2532
  • Karma: 83
  • Pirate Monkey!
    • View Profile
Re: About Colour Palettes
« Reply #4 on: March 17, 2007 »
Just to expand on what Nick said or to say it a different way. Probably no need to but I feel its always good to hear things in a different way :)

In blitz, atleas there is no such paletts for images you load. Although some bmps and other file formats do contain paletts, blitz does not give you access to that info.

However, you can create a palette for the purpose of speed in blitz, and oh how you need to every trick you can in blitz!

A palette is simply an array of colors(integers) information. Each color is then reprisented by the array index.

Traditionally an array of 256 colors is used. This is because gray scale images range from 0 to 255. In addition the array reprisenting the screen is usually a byte array, although this isnt possible in blitz.

To keep things simple, especially if you intend on using grayscale images to draw onto you screen array, then I would suggest you stick to a 256 palette. But if you really wanted to you could create a larger palette, and use the RGB of the picture to reprisent the index. So Red could mean index 0->255, Green 256->511, Blue 512->1023 wich would give you a palette of 1024 colors.

There is also another benefit of using a palette. This is indeed highlighted in a fire routine and thats the added bonus of blending. By that I mean you can add two indexes, such as 200 + 150 then divide it by 2 and you get 175 which if the palette is set up right should nicely blend in the middle.

« Last Edit: March 17, 2007 by Tetra »
Challenge Trophies Won:

Offline ferris

  • Pentium
  • *****
  • Posts: 841
  • Karma: 84
    • View Profile
    • Youth Uprising Home
Re: About Colour Palettes
« Reply #5 on: March 20, 2007 »
If you want all your images to be drawn paletted, and don't want to generate a new palette for each image, then just convert the image to greyscale, which is simple:

c = r;
if(g > c) c = g;
if(b > c) c = b;

where c is the final color for greyscale and ultimately the palette index for a given pixel.
http://iamferris.com/
http://youth-uprising.com/

Where the fun's at.
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17417
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: About Colour Palettes
« Reply #6 on: March 20, 2007 »
Good tip :) K+
Shockwave ^ Codigos
Challenge Trophies Won:

Offline mike_g

  • Amiga 1200
  • ****
  • Posts: 435
  • Karma: 34
    • View Profile
Re: About Colour Palettes
« Reply #7 on: March 20, 2007 »
Thanks for the help guys. This is still something I havent got around to doing yet, I got a few things that I need to do right now so it will probably be over the weekend or something. This stuff should come be useful to me when I do so yeah, cheers :)

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: About Colour Palettes
« Reply #8 on: March 20, 2007 »
Code: [Select]
c = r;
if(g > c) c = g;
if(b > c) c = b;

Another possibility is
Code: [Select]
c = (r+g+b)/3

Jim
Challenge Trophies Won:

Offline GrahamK

  • Atari ST
  • ***
  • Posts: 118
  • Karma: 17
    • View Profile
Re: About Colour Palettes
« Reply #9 on: March 20, 2007 »
On the subject of 'greyscale'
Intensity calculation, which tends to give a better 'grey'...

Code: [Select]
c =  ((R * 61) +(G * 174) + (B * 21)) / 256

Offline Tetra

  • DBF Aficionado
  • ******
  • Posts: 2532
  • Karma: 83
  • Pirate Monkey!
    • View Profile
Re: About Colour Palettes
« Reply #10 on: March 21, 2007 »
Completely not needed, as you are more than capable of implementig the various methods, but just to visualize the above methods for anyone who mite be reading the grayscale stuff in this thread, i've made a little app with code in BlitzBasic

http://dbfinteractive.com/index.php?action=tpmod;dl=item48
Challenge Trophies Won:

Offline GrahamK

  • Atari ST
  • ***
  • Posts: 118
  • Karma: 17
    • View Profile
Re: About Colour Palettes
« Reply #11 on: March 21, 2007 »
Actually that is really handy.... Nice.  :goodpost:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17417
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: About Colour Palettes
« Reply #12 on: March 21, 2007 »
Cheers Tetra :)  :goodpost:
Shockwave ^ Codigos
Challenge Trophies Won:

Offline mike_g

  • Amiga 1200
  • ****
  • Posts: 435
  • Karma: 34
    • View Profile
Re: About Colour Palettes
« Reply #13 on: March 21, 2007 »
Cool :) It goes to show that theres quite a difference in contrast/brightness and stuff dependant on the technique used. I'll keep hold of this, cheers.