Dark Bit Factory & Gravity
PROGRAMMING => Other languages => Blitz => Topic started by: mike_g 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?
-
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..
-
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.
-
Please post what you do.. If you are stuck or dont understand it all, please post again :)
-
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.
-
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.
-
Good tip :) K+
-
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 :)
-
c = r;
if(g > c) c = g;
if(b > c) c = b;
Another possibility is
c = (r+g+b)/3
Jim
-
On the subject of 'greyscale'
Intensity calculation, which tends to give a better 'grey'...
c = ((R * 61) +(G * 174) + (B * 21)) / 256
-
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 (http://dbfinteractive.com/index.php?action=tpmod;dl=item48)
-
Actually that is really handy.... Nice. :goodpost:
-
Cheers Tetra :) :goodpost:
-
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.