So I've been working on a oxygen and just ran into some "errors" testing out sprite masking.
I need to grab the currently set gfx transparent color.

Users stated in the chat why don't I just set a variable to the transparent color.

I simple don't risk increase the size of oxygen and making it more complicated for devs to use, or I can simple you force devs to set a variable to a transparent color ... or I can simply grab it from the memory or something.

here's some code: (Not finished)


Code:
void oxy_ApplyMaskToSprite(gfx_sprite_t *in_sprite, const gfx_sprite_t *mask_sprite)
{   
   uint8_t *in_data = in_sprite->data;
   uint8_t in_width = in_sprite->width;
   uint8_t in_height = in_sprite->height;
   
   uint8_t *mask_data = mask_sprite->data;
   uint8_t mask_width = mask_sprite->width;
   uint8_t mask_height = mask_sprite->height;
   
   uint8_t dim_error;
   
   if (mask_width != in_width)
      dim_error = 1;
   
   if (mask_hieght != in_hieght)
      dim_error = 1;
   
   if (dim_error){
      gfx_sprite_t *NewMask_Sprite;
      gfx_MallocSprite(in_width, in_hieght);
      gfx_ScaleSprite(mask_sprite, NewMask_Sprite);
      
      // resets all mask info
      mask_data = NewMask_Sprite->data;
      mask_width = NewMask_Sprite->width;
      mask_height = NewMask_Sprite->height;
      
      // process
      for (int i; i < mask_width * mask_hieght; i++){
         if (mask_data[i] == oxy_ReturnTransparentColor()){
            in_data[i] = oxy_ReturnTransparentColor();
         }
      }
      return;
   }
   
   for (int i; i < mask_width * mask_hieght; i++){
      if (mask_data[i] == oxy_ReturnTransparentColor()){
            in_data[i] = oxy_ReturnTransparentColor();
      }
   }
   
   return;
}


The dev gives a sprite they want to put a mask on and it set it to the transparent color.

// Don't mind the typo's <_<
Why not just have an additional argument in the function for the caller to provide the index of the transparent color?

It would make this particular function more versatile since the caller could then use it to mask with any palette index, rather than being required to have already set it in graphx.

There is a simple way in C to fetch graphx's transparent index, but that would actually be larger and slower than an additional function argument in this case.
KryptonicDragon wrote:
Why not just have an additional argument in the function for the caller to provide the index of the transparent color?

It would make this particular function more versatile since the caller could then use it to mask with any palette index, rather than being required to have already set it in graphx.

There is a simple way in C to fetch graphx's transparent index, but that would actually be larger and slower than an additional function argument in this case.


Simply put, the "caller" has already set the transparent color at the beginning of his or her program making it wayyy more simpler for the "caller".

Calling the set transparent color function is the same as putting it in the function ... but setting it outside the function makes the function way smaller (needs less arguments).

I would love to know how to fetch the transparent color even if it way to big, or slow. "I'm testing the function out."
Alright, it's your hammer to hit your thumb with.
Per the documentation, when you call gfx_SetTransparentColor(), it returns the previous transparent index.
So, call it with an arbitrary index, like 0, and store what it returns into a variable. Then call gfx_SetTransparentColor() again with that variable to set it back to what it was before, if you need to.
KryptonicDragon wrote:
Alright, it's your hammer to hit your thumb with.
Per the documentation, when you call gfx_SetTransparentColor(), it returns the previous transparent index.
So, call it with an arbitrary index, like 0, and store what it returns into a variable. Then call gfx_SetTransparentColor() again with that variable to set it back to what it was before, if you need to.


I just wrote some code to fetch the transparent color.

Code:
uint8_t oxy_ReturnTransparentColor(void)
{
   int color; //returns this
   color = gfx_SetTransparentColor(0);
   gfx_SetTransparentColor(color);
   return color;
}


I'm sure this should work Smile
I would probably have color be a uint8_t, but other than that it looks fine.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement