Thread: Software blitter

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    So I should do some pre-processing when I load my sprites?

    Code:
    struct drawPart{
      byte startPixel;
      int size;
    }
    
    while(not at end of sprite)
       if(currentPixel.alpha != 0)
           increase drawPart.size;
       else
           create new drawPart;
    And then when drawing it I just draw all the drawParts that is created by the pre-processing?
    Thanks for the input so far

    EDIT:
    Clipping would break the data that is created when loading the sprite I think. The only way to get it to work this way is to create a list of drawParts each time I want to draw the sprite? I think that would be slower then what I have so far.
    Last edited by h3ro; 04-17-2008 at 12:29 PM.

  2. #2
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218

    Thumbs up

    Sort of, but remember you have to toggle between read/write states. I'm writing this off the top of my head so the pseudocode may still have errors in it, but something like:
    Code:
    Uint32 skip_write[10000];
    
    Precalc(image im)
        int size = im.x * im.y;
        bool state = 0;
        int index = 0;
        int count = 0;
        for(int i=0; i<size; i++)
            if(state)
                if(im.pixel[i] == MASK)
                      count++;
                else
                      skip_write[index] = count;
                      count = 1;
                      index++;
                      state = false;
            else
               if(im.pixel[i] != MASK)
                      count++;
               else
                      skip_write[index] = count;
                      count =1;
                      index++;
                      state = true;
    Edit: you also need to note if the first pixel is masked or not, also using a linked list for this can save a lot of memory.
    Last edited by mike_g; 04-17-2008 at 12:39 PM.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    Thank you very much mike_g, Ill try to implement it to see how much faster it is.

    One last question, coming from this article:
    gameDev_Link

    In the article the author combines two 16bit pixels into one int so he can process two at the same time. Would that work with a two 32 bits colors on a 64bits system?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Software Developer Opportunity in Delaware
    By Jdorazio in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 04-28-2009, 10:58 AM
  2. Software Design/Test - Redmond, WA
    By IRVolt in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 06-11-2008, 10:26 AM
  3. Why C Matters
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 136
    Last Post: 01-16-2008, 09:09 AM
  4. Adding trial period to software
    By BobS0327 in forum C Programming
    Replies: 17
    Last Post: 01-03-2006, 02:13 PM