Oh god, why do you hate whitespace so much, ProgrammerNerd? Here's a more consistent and readable version of your routine, with no major code changes (please see ProgrammerNerd's post for more details on using this):


Code:
/* Note it is up to the caller to ensure that alpha is in range of 1-31.
 * Also make sure width is a multiple of two.
 */
void CopySpriteMaskedAlpha(unsigned *data, unsigned x, unsigned y, unsigned width, unsigned height,
                           unsigned maskcolor, unsigned alpha)
{
   unsigned short* v = (unsigned short*)0xa8000000;
   unsigned* VRAM, w, alphai;

   width >>= 1;       // Most compilers know int/2 = int>>1; just making sure
   v += 384 * y + x;
   VRAM = v;
   alphai = 32 - alpha;

   // Note I have decided to do a minor tradeoff for speed.
   // Make sure your alpha pixels are multiple of two*/
   maskcolor |= maskcolor << 8;

   // Note that this will not work for height=0 or width=0
   while(height--) {
      w = width;
      while(w--) {
         unsigned color1 = *data++;

         if (color1 != maskcolor) {
            // Note this is based on the source code of Fblend's function fblend_rect_trans_16
            unsigned rbg_source, grb_source, temp1;
            // Split up components to allow us to do operations
            // on all of them at the same time
            rbg_source = *VRAM & 0xF81F07E0,
            grb_source = *VRAM & 0x07E0F81F;

            // Multiply the source by the factor
            rbg_source = ((rbg_source >> 5) * alpha) & 0xF81F07E0;
            grb_source = ((grb_source * alpha) >> 5) & 0x07E0F81F;

            // Split up RGB -> R-B and G
            temp1 = color1 & 0x7E0F81F;
            color1 &= 0xF81F07E0;

            // Multiply the source by the factor
            color1 = ((((color1 >> 5) * alphai) & 0xF81F07E0) + rbg_source) & 0xF81F07E0;
            temp1  = ((((temp1 * alphai) >> 5)  & 0x07E0F81F) + grb_source) & 0x07E0F81F;

            color1 |= temp1;
            *VRAM++ = color1;
         } else {
            ++VRAM;
         }
      }
      VRAM += (384/2) - width;
   }
}
Sorry if it was a bit messy.
It is always good to know what others think of my code.
ProgrammerNerd wrote:
Sorry if it was a bit messy.
It is always good to know what others think of my code.
It's good code, certainly; I'm just increasingly picky about code style the more I work with others on C/C++ coding projects. Smile To your credit (and Fblend's credit), I saw very little to optimize there that a decent compiler wouldn't catch anyway.
ProgrammerNerd, this is what I'm getting when I use your routine:



The mask color is 0xf800.
That was a minor bug in my code. I only bothered to test an image with a mask color of 0 hence me not noticing the bug.
Replace

Code:

maskcolor |= maskcolor << 8;

With

Code:

maskcolor |= maskcolor << 16;
Again, may I suggest using Bdisp_WriteGraphVRAM? Last time I checked it supported setting a mask color (that's how icons in the OS file manager are displayed) and a transparency level (presumably for things like fading g3p pictures on the background, but it works with any bitmap really). Tell me if you need help with it.
I have nothing against custom functions but I think you could save some binary space and possibly gain a little speed by using the syscall.
gbl08ma wrote:
Again, may I suggest using Bdisp_WriteGraphVRAM? Last time I checked it supported setting a mask color (that's how icons in the OS file manager are displayed) and a transparency level (presumably for things like fading g3p pictures on the background, but it works with any bitmap really). Tell me if you need help with it.
I have nothing against custom functions but I think you could save some binary space and possibly gain a little speed by using the syscall.

I would like help on this and was also trying to implement Optimization suggestions from http://prizm.cemetech.net/index.php/Display but must have messed up iterations as the sprites appeared double the size and could not shrink them - has anyone implemented the "unsigned int *" version successfully for like drawing black lines etc or anything more complex please?
ignore my comment about double the size - I somehow had the sprite of double the size by mistake to begin with - so will revisit unsigned int testing again when I have more time. Any help/examples of Bdisp_WriteGraphVRAM will be much appreciated from gbl08ma and all of you. Kind regards
Sorry about jumping to another question: Is there a system call to get a folder size please? Or any routine doing it efficiently if someone already had to deal with this before?

I was playing with Bfile_FindFirst/Next calls so far and only could retrieve sizes for files not folders and very oddly their _NON_SMEM versions are the calls I have success (for files not folders) with using \\\\fls0\\ prefix so any tips what I'm doing wrong will be greatly appreciated.
  
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
» Goto page Previous  1, 2, 3 ... 10, 11, 12
» View previous topic :: View next topic  
Page 12 of 12
» 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