Jump to content
  • Advertisement
Sign in to follow this  
Nokturnal

Transparency of pixels

This topic is 4811 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am citing an example for tricks book which i am following :- for plotting a pixel , andre says he is first testing for transparency of the pixel and then plotting it. From what i have read , transparency deals with a scenario such that a pixel is behind a pixel and is it visible. the transparency component is how ever available only in 32 bpp , i belive and not in 8bpp. this example deals with 8 bpp , and a section of the code goes a follows :- for (int index_y = 0; index_y < dy; index_y++) { // inner loop, where the action takes place for (int index_x = 0; index_x < dx; index_x++) { // read pixel from source bitmap, test for transparency and plot if ((pixel = bitmap[index_x])) video_buffer[index_x] = pixel; } // end for index_x // advance pointers video_buffer+=mempitch; // bytes per scanline bitmap +=width; // bytes per bitmap row } // end for index_y i ll explain all the variables involved a bitmap needs to be copied at a location x,y, index_x & index_y are number of rows and columns to be plotted [ dx/dy are used for clipping] , pixel variable is used only to hold the pixel value [ 8bpp , unsigned char]. Video buffer is the pointer to the surface & bitmap is a bitmap created with dimensions 8x8. width being widht of the bitmap , mempitch being the memory pitch of the surface. If you guys still find ambiguities with the explanation , i ll post the entire code. My problem is with the statement : - // read pixel from source bitmap, test for transparency and plot if ((pixel = bitmap[index_x])) if i am not wrong , pixel=bitmap[index_x] is more of a assignment , than of a test , so how is the test for transparency done here ?

Share this post


Link to post
Share on other sites
Advertisement
Maybe he's taking the value of bitmap[index_x] to d othe test..

if (bitmap[index_c] == 0), then the condition is false
if (bitmap[index_c] != 0), then the condition is true

Share this post


Link to post
Share on other sites
In C you can put assignments in the if clause, and the return value will be true if the assigned value is not equal 0.

You saw it right:

if ((pixel = bitmap[index_x]))

This assigns the value of bitmap[index_x] to the variable pixel. The assigned value is also tested if its equal to 0. If it is not the result is true and the pixel is put into the the video buffer.


So the test here is if the value is equal to 0. This would be the first entry in the palette (it's 8bit mode).

Share this post


Link to post
Share on other sites
The above explanations are correct however if you want to optimize the algorithm for displaying tranparencies you might want to use a check for a tranparency color rather than just 0 which is what your code does already.

One more point is the nested for loop you don't need to use a nested for loop to go through each pixel of the bitmap.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!