9 Replies Latest reply on Jul 13, 2011 8:44 AM by er453r

    Is it possible to implement a 4bit image?

    er453r Level 1

      Hi!

       

      I have some exotic image files with one, 16bit channel. Currently I am able to display them in flex by translating this to 4 8it channels in a bitmapData and using a shader. But, the problem with this is it takes twice the memory it should (16bit to 32bit...).

       

      I am wondering is it possible to somehow extend the BitmapImage class and override important methods to somehow solve this problem?

       

      Thx for help!

        • 1. Re: Is it possible to implement a 4bit image?
          er453r Level 1

          Sorry for bumping, but I may not have been too clear about the problem.

           

          1. Images in Flex are 8bit per 4 channels (32 bits per pixel)

          2. I have 16bit 1 channel image (16 bits per pixel)

           

          To avoid wasting data (16bits per pixel, 50% wasted memory), I would like to somehow extend the BitmapData class. Create an interface for such an image format to be understood by Flex components. Is this somehow possible?

          • 2. Re: Is it possible to implement a 4bit image?
            Karl_Sigiscar_1971 Level 3

            Hi,

             

            I understand your problem.

             

            In Adobe Director, you have the possibility to use 15 bit and 16 bit images from Windows BMP directly for example. No waste of memory.

             

            In Flex, we don't have this. The problem with BitmapData is that this class resides in the Flash Player API, not the Flex one. So, you do not have access to its implementation. What is in the Flash Player is mostly C++ code (ActionScript methods exposed are wrappers for C++ ones).

             

            But in theory, there is nothing preventing you from extending this class as it is public and so are most of its methods. However, will you have access to the inner data manipulation part, that's the question.

             

            Another way would be to use 16bit PNG files if possible in your project. But it only works with grayscale...

            1 person found this helpful
            • 3. Re: Is it possible to implement a 4bit image?
              er453r Level 1

              16bit PNG files would do just fine! I just need a pixel container that fits my data (16bit!). Does Flex support this files? If there is a way to create such an empty PNG file and fill its pixels with values - it would solve all my problems. Could you please write something more about using this format in flex, maybe provide some links/examples?

               

              Big thanks!

              • 4. Re: Is it possible to implement a 4bit image?
                Karl_Sigiscar_1971 Level 3

                Hi,

                 

                I do not have any example but the documentation states that you can load such images. I would surmise the data buffer with grayscale will be automatically 16 bits

                 

                http://livedocs.adobe.com/flex/3/html/help.html?content=Working_with_Bitmaps_02.html


                From the documentation

                 

                "The quality of a bitmap image is determined by combining the resolution of the image with its color depth bit value. Resolution relates to the number of pixels contained within an image. The greater  the number of pixels, the higher the resolution and the finer the image  appears. Color depth relates to the amount of information a pixel  can contain. For example, an image that has a color depth value of 16  bits per pixel cannot represent the same number of colors as an image  that has a color depth of 48 bits. As a result, the 48-bit image will  have smoother degrees of shading than its 16-bit counterpart."

                • 5. Re: Is it possible to implement a 4bit image?
                  Karl_Sigiscar_1971 Level 3

                  Get the Debabelizer software:

                  http://www.debabelizer.com/Internet/Equil/Products/DeBabelizer/index.html

                   

                  It should allow you to create 16 bit grayscale PNG files.

                  • 6. Re: Is it possible to implement a 4bit image?
                    er453r Level 1

                    So I've done some testing with PNG formats, with test cases from this page: http://www.schaik.com/pngsuite2011/pngsuite_bas_png.html

                     

                    Flex handles all this formats well, but it still converts the output to raw 4 8bit channel BitmapData :/

                     

                    Test in the Profiler with this code:

                    <?xml version="1.0" encoding="utf-8"?>
                    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                                      xmlns:s="library://ns.adobe.com/flex/spark" 
                                      xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
                                      backgroundColor="0xff0000">
                         <fx:Script>
                              <![CDATA[
                                   [Bindable] private var source:String;
                                   
                                   private function investigate():void{
                                        trace("lold");
                                   }
                              ]]>
                         </fx:Script>
                         <s:VGroup>
                              <s:Label text="PNG test"/>
                              
                              <s:Image id="image"
                                         source="{source}"
                                         cachePolicy="off"
                                         cacheAsBitmap="false"/>
                              
                              <s:List id="list"
                                        labelField="desc"
                                        change=" source = list.selectedItem.source; ">
                                   <s:dataProvider>
                                        <s:ArrayCollection>
                                             <fx:Object desc="bit1" source="http://www.schaik.com/pngsuite2011/basn0g01.png"/>
                                             <fx:Object desc="bit16" source="http://www.schaik.com/pngsuite2011/basn0g16.png"/>
                                             <fx:Object desc="bit64" source="http://www.schaik.com/pngsuite2011/basn6a16.png"/>
                                             <fx:Object desc="bit32" source="http://www.schaik.com/pngsuite2011/basn3p08.png"/>                         
                                        </s:ArrayCollection>
                                   </s:dataProvider>
                              </s:List>
                              <s:Button click="investigate();"/>
                         </s:VGroup>
                    </s:Application>
                    

                    • 7. Re: Is it possible to implement a 4bit image?
                      Karl_Sigiscar_1971 Level 3

                      Hi

                       

                      I think the documentation is crystal clear:

                      Either type of BitmapData object is stored as a buffer of 32-bit integers.   Each 32-bit integer determines the properties of a single pixel in the bitmap.

                       

                      I checked on the Flash Player JIRA and some people have the same issue:

                      https://bugs.adobe.com/jira/browse/FP-441

                       

                      Login/register and vote for this issue. Let Thibault Imbert ( Flash Player product manager) know what your requirements are by posting a comment.

                       

                      And if as many people as possible could vote for this issue in JIRA, that would give it a push.

                       

                      Regards,
                      Karl.

                      • 8. Re: Is it possible to implement a 4bit image?
                        Karl_Sigiscar_1971 Level 3

                        Adobe might implement the variable depth BitmapData (from 8 to 48 bits) in Flash Player 11 (hopefully) but in the meantime, why not doing this:

                         

                        The idea would be to have three kinds of BitmapData instances.

                         

                        Loading, storing, displaying

                         

                        1- Load 16 bits PNGs into a regular BitmapData

                         

                        2- Create a destination BitmapData where you copy the information of two 16 bits PNGs using copyChannel(). PNG 1: Copy the 1st and 2nd byte to the 1st and 2nd byte of the destination. PNG 2: Copy the 1st and 2nd byte to the 3rd and 4th byte of the destination.

                         

                        3- When you are ready to display a picture, use another BitmapData instance to which you copyChannel() the information from either the 1st and 2nd byte of the source or 3rd and 4th byte of the source to the 1st and 2nd bytes of the destination

                         

                        So, the idea here would be to have only one loading BitmapData, only one displaying BitmapData (or as many as the number of images you need to display at the same time) and many BitmapData used to their full 32 bit capacity for storage.

                        • 9. Re: Is it possible to implement a 4bit image?
                          er453r Level 1

                          I voted and commented about this issue.

                           

                          About the triple BitmapData solution - it is a good concept, but I have already handled loading, and storing. I just really need the memory for the display part