예제 #1
0
파일: Swf2.cs 프로젝트: tdenc/nicorank
        public void Parse(Stream stream)
        {
            uint b   = 0;
            int  rem = 0;
            byte c   = (byte)StreamUtil.GetBit(stream, ref rem, ref b, 1);

            if (c != 0)
            {
                int scale_bits = (int)StreamUtil.GetBit(stream, ref rem, ref b, 5);
                scale_x = (short)StreamUtil.GetBit(stream, ref rem, ref b, scale_bits);
                scale_y = (short)StreamUtil.GetBit(stream, ref rem, ref b, scale_bits);
            }
            c = (byte)StreamUtil.GetBit(stream, ref rem, ref b, 1);
            if (c != 0)
            {
                int rotate_bits = (int)StreamUtil.GetBit(stream, ref rem, ref b, 5);
                rotate_skew0 = (short)StreamUtil.GetBit(stream, ref rem, ref b, rotate_bits);
                rotate_skew1 = (short)StreamUtil.GetBit(stream, ref rem, ref b, rotate_bits);
            }
            int translate_bits = (int)StreamUtil.GetBit(stream, ref rem, ref b, 5);

            translate_x = (short)StreamUtil.GetBit(stream, ref rem, ref b, translate_bits);
            translate_y = (short)StreamUtil.GetBit(stream, ref rem, ref b, translate_bits);
        }
예제 #2
0
파일: Swf2.cs 프로젝트: tdenc/nicorank
        public void SaveJPG(string dir)
        {
            if (!dir.EndsWith("\\"))
            {
                dir += "\\";
            }
            Directory.CreateDirectory(dir);
            int count = 1;

            byte[] jpeg_tables = null;

            for (int i = 0; i < tag_list_.Count; ++i)
            {
                if ((int)tag_list_[i].tag == (int)ObjectType.DefineBitsJPEG || (int)tag_list_[i].tag == (int)ObjectType.DefineBitsJPEG2 ||
                    (int)tag_list_[i].tag == (int)ObjectType.DefineBitsJPEG3)
                {
                    FileStream fs = null;
                    try
                    {
                        fs = new FileStream(dir + count.ToString("0000") + ".jpg", FileMode.Create, FileAccess.Write);
                        if ((int)tag_list_[i].tag == (int)ObjectType.DefineBitsJPEG3)
                        {
                            // 最初の2バイトはタグなので無視
                            data_reader_.BaseStream.Seek(tag_list_[i].position + 2, SeekOrigin.Begin);
                            int image_data_size = data_reader_.ReadInt32();

                            StreamUtil.Copy(data_stream_, fs, image_data_size);
                        }
                        else
                        {
                            const int header_size = 20;
                            byte[]    pre_search  = new byte[6];
                            data_stream_.Seek(tag_list_[i].position, SeekOrigin.Begin);
                            data_stream_.Read(pre_search, 0, pre_search.Length);
                            int offset = 2;
                            if (pre_search[3] == 0xD9 && pre_search[5] == 0xD8)
                            {
                                offset += 4;
                            }
                            data_stream_.Seek(tag_list_[i].position + offset, SeekOrigin.Begin);
                            StreamUtil.Copy(data_stream_, fs, header_size);
                            if (tag_list_[i].tag == 6 && jpeg_tables != null)
                            {
                                fs.Write(jpeg_tables, 2, jpeg_tables.Length - 4); // 最初と最後2バイトずつは除く
                            }
                            StreamUtil.Copy(data_stream_, fs, (int)tag_list_[i].size - header_size - offset);
                        }
                        ++count;
                    }
                    finally
                    {
                        if (fs != null)
                        {
                            fs.Close();
                        }
                    }
                }
                else if ((int)tag_list_[i].tag == (int)ObjectType.JPEGTables)
                {
                    jpeg_tables = new byte[tag_list_[i].size];
                    data_stream_.Seek(tag_list_[i].position, SeekOrigin.Begin);
                    data_stream_.Read(jpeg_tables, 0, (int)tag_list_[i].size);
                }
            }
        }