DefineBitsLossLessTag is used to define an image compressed using the lossless zlib compression algorithm.

The class supports color-mapped images where the image data contains an index into a color table or images where the image data specifies the color directly.

For color-mapped images the color table contains up to 256, 24-bit colors. The image contains one byte for each pixel which is an index into the table to specify the color for that pixel. The color table and the image data are compressed as a single block, with the color table placed before the image.

For images where the color is specified directly, the image data contains either 16 or 24 bit color values. For 16-bit color values the most significant bit is zero followed by three, 5-bit fields for the red, green and blue channels.

Four bytes are used to represent 24-bit colors. The first byte is always set to zero and the following bytes contain the color values for the red, green and blue color channels.

The number of bytes in each row of an image must be aligned to a 32-bit word boundary. For example if an image if an icon is 25 pixels wide, then for an 8-bit color mapped image an additional three bytes (0x00) must be used to pad each row; for a 16-bit direct mapped color image an additional two bytes must be used as padding.

The image data is stored in zlib compressed form within the object. For color-mapped images the compressed data contains the color table followed by the image data. The color table is omitted for direct-mapped images.

This tag was introduced in Flash 2.

상속: BaseTag, DefineTag
예제 #1
0
        /// <summary>
        /// Construct a new DefineBitsLossLessTag object
        /// from a file.
        /// </summary>
        /// <param name="characterId">Character id.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <returns></returns>
        public static DefineBitsLossLessTag FromFile(ushort characterId, string fileName)
        {
            FileStream            stream = File.OpenRead(fileName);
            DefineBitsLossLessTag res    = FromImage(characterId, Image.FromStream(stream));

            stream.Close();
            return(res);
        }
예제 #2
0
        /// <summary>
        /// Construct a new DefineBitsLossLessTag object 
        /// from an image object.
        /// </summary>
        /// <param name="characterId">Character id.</param>
        /// <param name="image">Image.</param>
        /// <returns></returns>
        public static DefineBitsLossLessTag FromImage(ushort characterId, Image image)
        {
            if (image.RawFormat.Equals(ImageFormat.Bmp) == false &&
                image.RawFormat.Equals(ImageFormat.MemoryBmp) == false)
                throw new InvalidImageFormatException();

            Bitmap bitmap = (Bitmap)image;
            byte format = 0;
            PixelFormat pxFormat = bitmap.PixelFormat;
            if (pxFormat.Equals(PixelFormat.Format8bppIndexed))
                format = 3;
            else if (pxFormat.Equals(PixelFormat.Format16bppRgb555) ||
                pxFormat.Equals(PixelFormat.Format16bppRgb565))
                format = 4;
            else if (pxFormat.Equals(PixelFormat.Format24bppRgb))
                format = 5;
            else
                throw new InvalidPixelFormatException();

            DefineBitsLossLessTag bmp = new DefineBitsLossLessTag();
            bmp.CharacterId = characterId;
            bmp.BitmapFormat = format;
            bmp.BitmapWidth = (ushort)bitmap.Width;
            bmp.BitmapHeight = (ushort)bitmap.Height;

            int imageSize = bitmap.Width * bitmap.Height;

            if (bmp.BitmapFormat == 3)
            {
                //TODO
            }
            else if (bmp.BitmapFormat == 4)
            {
                Pix15[] bitmapPixelData = new Pix15[imageSize];
                int k = 0;
                for (int i = 0; i < bitmap.Height; i++)
                {
                    for (int j = 0; j < bitmap.Width; j++)
                    {
                        Color color = bitmap.GetPixel(j, i);
                        bitmapPixelData[k] = new Pix15((byte)color.R, (byte)color.G, (byte)color.B);
                        k++;
                    }
                }
                bmp.BitmapData = new BitmapColorData(bitmapPixelData);
            }
            else if	(bmp.BitmapFormat == 5)
            {
                Pix24[] bitmapPixelData = new Pix24[imageSize];
                int k = 0;
                for (int i = 0; i < bitmap.Height; i++)
                {
                    for (int j = 0; j < bitmap.Width; j++)
                    {
                        Color color = bitmap.GetPixel(j, i);
                        bitmapPixelData[k] = new Pix24((byte)color.R, (byte)color.G, (byte)color.B);
                        k++;
                    }
                }
                bmp.BitmapData = new BitmapColorData(bitmapPixelData);
            }

            return bmp;
        }
예제 #3
0
 static Tuple<int, Image> DecodeLossLess(DefineBitsLossLessTag tag)
 {
     return Tuple.Create((int)tag.CharacterId, tag.DecompileToImage());
 }
예제 #4
0
        /// <summary>
        /// Read next tag from swf input stream.
        /// </summary>
        /// <param name="version">Version.</param>
        /// <param name="binaryReader">Binary reader.</param>
        /// <param name="tagList">Tag list.</param>
        /// <returns></returns>
        internal static BaseTag ReadTag(byte version, BufferedBinaryReader binaryReader, BaseTagCollection tagList)
        {
            long posBefore = binaryReader.BaseStream.Position;
            RecordHeader rh = new RecordHeader();
            rh.ReadData(binaryReader);

            int offset = (int)(binaryReader.BaseStream.Position - posBefore);
            binaryReader.BaseStream.Position = posBefore;

            BaseTag resTag = null;

            switch (rh.TagCode)
            {
                case (int)TagCodeEnum.DefineBits: resTag = new DefineBitsTag(); break;
                case (int)TagCodeEnum.DefineBitsJpeg2: resTag = new DefineBitsJpeg2Tag(); break;
                case (int)TagCodeEnum.DefineBitsJpeg3: resTag = new DefineBitsJpeg3Tag(); break;
                case (int)TagCodeEnum.DefineBitsLossLess: resTag = new DefineBitsLossLessTag(); break;
                case (int)TagCodeEnum.DefineBitsLossLess2: resTag = new DefineBitsLossLess2Tag(); break;
                case (int)TagCodeEnum.DefineButton: resTag = new DefineButtonTag(); break;
                case (int)TagCodeEnum.DefineButton2: resTag = new DefineButton2Tag(); break;
                case (int)TagCodeEnum.DefineButtonCxForm: resTag = new DefineButtonCxFormTag(); break;
                case (int)TagCodeEnum.DefineButtonSound: resTag = new DefineButtonSoundTag(); break;
                case (int)TagCodeEnum.DefineEditText: resTag = new DefineEditTextTag(); break;
                case (int)TagCodeEnum.DefineFont: resTag = new DefineFontTag(); break;
                case (int)TagCodeEnum.DefineFont2: resTag = new DefineFont2Tag(); break;
                case (int)TagCodeEnum.DefineFontInfo: resTag = new DefineFontInfoTag(); break;
                case (int)TagCodeEnum.DefineFontInfo2: resTag = new DefineFontInfo2Tag(); break;
                case (int)TagCodeEnum.DefineMorphShape: resTag = new DefineMorphShapeTag(); break;
                case (int)TagCodeEnum.DefineShape: resTag = new DefineShapeTag(); break;
                case (int)TagCodeEnum.DefineShape2: resTag = new DefineShape2Tag(); break;
                case (int)TagCodeEnum.DefineShape3: resTag = new DefineShape3Tag(); break;
                case (int)TagCodeEnum.DefineSound: resTag = new DefineSoundTag(); break;
                case (int)TagCodeEnum.DefineSprite: resTag = new DefineSpriteTag(); break;
                case (int)TagCodeEnum.DefineText: resTag = new DefineTextTag(); break;
                case (int)TagCodeEnum.DefineText2: resTag = new DefineText2Tag(); break;
                case (int)TagCodeEnum.DefineVideoStream: resTag = new DefineVideoStreamTag(); break;
                case (int)TagCodeEnum.DoAction: resTag = new DoActionTag(); break;
                case (int)TagCodeEnum.EnableDebugger: resTag = new EnableDebuggerTag(); break;
                case (int)TagCodeEnum.EnableDebugger2: resTag = new EnableDebugger2Tag(); break;
                case (int)TagCodeEnum.End: resTag = new EndTag(); break;
                case (int)TagCodeEnum.ExportAssets: resTag = new ExportAssetsTag(); break;
                case (int)TagCodeEnum.FrameLabel: resTag = new FrameLabelTag(); break;
                case (int)TagCodeEnum.ImportAssets: resTag = new ImportAssetsTag(); break;
                case (int)TagCodeEnum.InitAction: resTag = new InitActionTag(); break;
                case (int)TagCodeEnum.JpegTable: resTag = new JpegTableTag(); break;
                case (int)TagCodeEnum.PlaceObject: resTag = new PlaceObjectTag(); break;
                case (int)TagCodeEnum.PlaceObject2:	resTag = new PlaceObject2Tag(); break;
                case (int)TagCodeEnum.Protect: resTag = new ProtectTag(); break;
                case (int)TagCodeEnum.RemoveObject: resTag = new RemoveObjectTag(); break;
                case (int)TagCodeEnum.RemoveObject2: resTag = new RemoveObject2Tag(); break;
                case (int)TagCodeEnum.ScriptLimit: resTag = new ScriptLimitTag(); break;
                case (int)TagCodeEnum.SetBackgroundColor: resTag = new SetBackgroundColorTag(); break;
                case (int)TagCodeEnum.SetTabIndex: resTag = new SetTabIndexTag(); break;
                case (int)TagCodeEnum.ShowFrame: resTag = new ShowFrameTag(); break;
                case (int)TagCodeEnum.SoundStreamBlock: resTag = new SoundStreamBlockTag(); break;
                case (int)TagCodeEnum.SoundStreamHead: resTag = new SoundStreamHeadTag(); break;
                case (int)TagCodeEnum.SoundStreamHead2: resTag = new SoundStreamHead2Tag(); break;
                case (int)TagCodeEnum.StartSound: resTag = new StartSoundTag(); break;
                //TODO: Sorenson Codec
                case (int)TagCodeEnum.VideoFrame: resTag = ReadVideoFrameTag(binaryReader, tagList); break;
                default: resTag = new BaseTag(binaryReader.ReadBytes(System.Convert.ToInt32(rh.TagLength + offset))); break;
            }

            //Read the data of the current tag
            resTag.ReadData(version, binaryReader);

            //LOG
            long mustRead = rh.TagLength + offset;
            if (posBefore + mustRead != binaryReader.BaseStream.Position)
            {
                binaryReader.BaseStream.Position = posBefore + rh.TagLength + offset;
                if (log.IsErrorEnabled)
                    log.Error(Enum.GetName(TagCodeEnum.DefineBits.GetType(), rh.TagCode) + "....KO");
            }
            else if (log.IsInfoEnabled)
                log.Info(Enum.GetName(TagCodeEnum.DefineBits.GetType(), rh.TagCode) + "....OK (" + mustRead + ")");

            return resTag;
        }
예제 #5
0
        /// <summary>
        /// Construct a new DefineBitsLossLessTag object
        /// from an image object.
        /// </summary>
        /// <param name="characterId">Character id.</param>
        /// <param name="image">Image.</param>
        /// <returns></returns>
        public static DefineBitsLossLessTag FromImage(ushort characterId, Image image)
        {
            if (image.RawFormat.Equals(ImageFormat.Bmp) == false &&
                image.RawFormat.Equals(ImageFormat.MemoryBmp) == false)
            {
                throw new InvalidImageFormatException();
            }

            Bitmap      bitmap   = (Bitmap)image;
            byte        format   = 0;
            PixelFormat pxFormat = bitmap.PixelFormat;

            if (pxFormat.Equals(PixelFormat.Format8bppIndexed))
            {
                format = 3;
            }
            else if (pxFormat.Equals(PixelFormat.Format16bppRgb555) ||
                     pxFormat.Equals(PixelFormat.Format16bppRgb565))
            {
                format = 4;
            }
            else if (pxFormat.Equals(PixelFormat.Format24bppRgb))
            {
                format = 5;
            }
            else
            {
                throw new InvalidPixelFormatException();
            }

            DefineBitsLossLessTag bmp = new DefineBitsLossLessTag();

            bmp.CharacterId  = characterId;
            bmp.BitmapFormat = format;
            bmp.BitmapWidth  = (ushort)bitmap.Width;
            bmp.BitmapHeight = (ushort)bitmap.Height;

            int imageSize = bitmap.Width * bitmap.Height;

            if (bmp.BitmapFormat == 3)
            {
                //TODO
            }
            else if (bmp.BitmapFormat == 4)
            {
                Pix15[] bitmapPixelData = new Pix15[imageSize];
                int     k = 0;
                for (int i = 0; i < bitmap.Height; i++)
                {
                    for (int j = 0; j < bitmap.Width; j++)
                    {
                        Color color = bitmap.GetPixel(j, i);
                        bitmapPixelData[k] = new Pix15((byte)color.R, (byte)color.G, (byte)color.B);
                        k++;
                    }
                }
                bmp.BitmapData = new BitmapColorData(bitmapPixelData);
            }
            else if (bmp.BitmapFormat == 5)
            {
                Pix24[] bitmapPixelData = new Pix24[imageSize];
                int     k = 0;
                for (int i = 0; i < bitmap.Height; i++)
                {
                    for (int j = 0; j < bitmap.Width; j++)
                    {
                        Color color = bitmap.GetPixel(j, i);
                        bitmapPixelData[k] = new Pix24((byte)color.R, (byte)color.G, (byte)color.B);
                        k++;
                    }
                }
                bmp.BitmapData = new BitmapColorData(bitmapPixelData);
            }

            return(bmp);
        }
예제 #6
0
        /// <summary>
        /// Construct a new DefineBitsLossLessTag object
        /// from a stream.
        /// </summary>
        /// <param name="characterId">Character id.</param>
        /// <param name="stream">Stream.</param>
        /// <returns></returns>
        public static DefineBitsLossLessTag FromStream(ushort characterId, Stream stream)
        {
            DefineBitsLossLessTag res = FromImage(characterId, Image.FromStream(stream));

            return(res);
        }