3 Replies Latest reply on Jan 12, 2011 10:26 PM by Flex harUI

    Dynamic BitmapData / Redraw / Invalidation

    TheSuese

      I've scoured the net for an answer to this and can't find one.  I think I will need an Adobe Developer to answer this...

       

      I am working on a character terminal emulator.  Glyphs are 8x8, 1bit raw  bitmaps  There are 256 glyphs in the palette. A character buffer is a  grid of single bytes, referencing the various glyphs in the 256  glyph palette.

      Essentially a character buffer is a big blocky bitmap,  only instead of pixels it has glyphs.

      Rendering the character buffer is a rather quick, self-contained job in  theory.  The memory required is very low and the execution time is  similar to a hardware blit. 

      It is redundant to have a 'back buffer', i.e. a BitmapData to store a  rendering of the character buffer.  it's too costly in memory and way  overkill for the complexity of what is being rendered.

      I want to know if it is possible to feed data to the video memory similar to the way it is done with SampleDataEvents. 

      I do not want to store a redundant BitmapData object since some of these  character buffers are huge and rarely need to be rendered all at once.   They only need to be 'invalidated', i.e. they only need to update small  portions at a time as they are 'exposed'.

      I have searched high and low and read the manual a million times.  The  closest thing I could find were the stage.invalidate() and RENDER  events, but they don't seem to give me a rectangular area to feed data  to.  I also tried extending Bitmap, but could not figure out how to  override it's default behaviour of reading pixels from a BitmapData.

      An example of what I'm doing can be found when using GTK's DrawingArea  widget and it's 'expose' events, used for very fast rendering.

      I also DO NOT need scaling or filtering of any kind, it would be best if  I can avoid filtering or anything that might slow this down at all.

       

      I tried using this to no avail...

      package  
      {
           import flash.display.BitmapData;
           import flash.geom.Rectangle;
           import flash.utils.ByteArray;
           /**
            * ...
            * @author Dan McKinnon
            */
           public class Buaa extends BitmapData{
                
                public function Buaa() {
                     super(1, 1);
                }
                public override function get rect():Rectangle {
                     return new Rectangle(0, 0, 320, 240);
                }
                
                public override function getPixels(r:Rectangle):ByteArray {
                     var b:ByteArray = new ByteArray();
                     for ( var x:int = 0; x < r.width; x++) {
                          for ( var y:int = 0; y < r.height; y++ ) {
                               b.writeByte(128);
                               b.writeByte(255);
                               b.writeByte(0);
                               b.writeByte(0);
                          }
                     }
                     return b;
                }
                
           }
      
      }
      


      Is what I'm asking for even possible?


      Thanks

        • 1. Re: Dynamic BitmapData / Redraw / Invalidation
          Flex harUI Adobe Employee

          I don't know of any way to get called back for rendering data.  The player

          is a deferred display list renderer.

           

          It only re-renders dirty display objects so in theory you could carve your

          screen up into tiles and save some that way.

           

          Are you sure you don't just want to find a fixed-width font that will look

          just like the glyphs?  Then you should get faster rendering as well.

          • 2. Re: Dynamic BitmapData / Redraw / Invalidation
            TheSuese Level 1

            The font subsystem does not allow for background colors on individual glyphs,  also, it seems silly that a TTF rasterizer would be faster than something as simple as a 1bit glyph rasterizer.   Also, we use a LOT of switching of character colors and background (>2000 per screen sometimes),  having that many HTML tags would surely eat at the memory and slow down crucial manipulation functions. We'd also have to map the UTF glyphs to the 256 IBM/OEM glyphs and that table-conversion process would ALSO be another bottleneck, and we are striving for top speed here. I hope that makes it obvious as to why the TTF rasterizer is overkill and likely too slow and too bulky for our needs.

             

            In my experience this process is called 'invalidation',  and in  invalidation there is always an 'expose' event, that gives the program  time to update the areas of the screen that need 'tidying up'.  If I could capture these 'dirty rectangle events', as you put it,  and supply them with my own pixels, that would be the ultimate in memory/cpu saving I think.  I take it that is not possible yet, 

             

            Can it be a feature request?

             

             

            Thanks.

            • 3. Re: Dynamic BitmapData / Redraw / Invalidation
              Flex harUI Adobe Employee

              The player is a deferred display list renderer.  It does the rendering in a

              whole different portion of the player code and the overhead of calling back

              into the actionscript side would probably defeat any gains for what you are

              asking for.  But you can always file an enhancement request at

              bugs.adobe.com/jira.

               

              The font system does not allow for background colors, but with a fixed width

              font, it should be simple enough to draw shapes behind the characters.

               

              I've tried to out-perform the TTF rasterizer by creating a set of

              single-line vectors per character and failed because I was moving the

              vectors in the ActionScript VM and the rasterizer is working at machine-code

              speeds.  That's why I suggested trying that.  Yes, your code does get JIT'd

              to machine code, but it tends not to be as efficient.  I was also thinking

              of the original IBM PC character mode where you wrote the 8-byte character

              and hardware rasterized the character.  If you have to use slower

              Actionscript to do a lot of processing, it might be better to just set the

              character and have the faster player rasterizer do the heavy lifting.

               

              That said, I also know that many Flash games use blits instead of modifying

              the vector list because it performs better once the vector list gets large.

               

              So, I think there is a trade-off in there and I don't know of anyone who has

              done a terminal emulator in Flash so I can't point you in a particular

              direction.  I'm just trying to point out how the player is different from

              just trying to solve this problem in a native app.

               

              You could also look into using PixelBender to do the rasterizing.