swf_tree/
lib.rs

1use ::serde::{Deserialize, Serialize};
2pub use ::swf_fixed as fixed;
3
4pub use crate::basic_types::ColorTransform;
5pub use crate::basic_types::ColorTransformWithAlpha;
6pub use crate::basic_types::LanguageCode;
7pub use crate::basic_types::Matrix;
8pub use crate::basic_types::NamedId;
9pub use crate::basic_types::Rect;
10pub use crate::basic_types::SRgb8;
11pub use crate::basic_types::StraightSRgba8;
12pub use crate::basic_types::Vector2D;
13pub use crate::button::ButtonCond;
14pub use crate::button::ButtonCondAction;
15pub use crate::button::ButtonRecord;
16pub use crate::button::ButtonSound;
17pub use crate::gradient::ColorSpace;
18pub use crate::gradient::ColorStop;
19pub use crate::gradient::Gradient;
20pub use crate::gradient::GradientSpread;
21pub use crate::gradient::MorphColorStop;
22pub use crate::gradient::MorphGradient;
23pub use crate::image::ImageType;
24pub use crate::movie::CompressionMethod;
25pub use crate::movie::Header;
26pub use crate::movie::Movie;
27pub use crate::movie::SwfSignature;
28pub use crate::shape::shape_records;
29pub use crate::shape::CapStyle;
30pub use crate::shape::ClipAction;
31pub use crate::shape::ClipEventFlags;
32pub use crate::shape::FillStyle;
33pub use crate::shape::Glyph;
34pub use crate::shape::JoinStyle;
35pub use crate::shape::LineStyle;
36pub use crate::shape::MorphFillStyle;
37pub use crate::shape::MorphLineStyle;
38pub use crate::shape::MorphShape;
39pub use crate::shape::MorphShapeRecord;
40pub use crate::shape::MorphShapeStyles;
41pub use crate::shape::Shape;
42pub use crate::shape::ShapeRecord;
43pub use crate::shape::ShapeStyles;
44pub use crate::sound::AudioCodingFormat;
45pub use crate::sound::SoundEnvelope;
46pub use crate::sound::SoundInfo;
47pub use crate::sound::SoundRate;
48pub use crate::sound::SoundSize;
49pub use crate::sound::SoundType;
50pub use crate::video::VideoCodec;
51pub use crate::video::VideoDeblocking;
52
53mod float_is;
54
55mod helpers;
56
57pub mod fill_styles;
58pub mod filters;
59pub mod join_styles;
60pub mod tags;
61pub mod text;
62
63mod basic_types;
64
65mod button;
66
67mod gradient;
68
69mod image;
70
71mod movie;
72
73mod shape;
74
75mod sound;
76
77mod video;
78
79#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
80#[serde(rename_all = "kebab-case")]
81pub enum BlendMode {
82  Normal,
83  Layer,
84  Multiply,
85  Screen,
86  Lighten,
87  Darken,
88  Difference,
89  Add,
90  Subtract,
91  Invert,
92  Alpha,
93  Erase,
94  Overlay,
95  Hardlight,
96}
97
98#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
99#[serde(tag = "filter", rename_all = "kebab-case")]
100pub enum Filter {
101  Blur(filters::Blur),
102  Bevel(filters::Bevel),
103  ColorMatrix(filters::ColorMatrix),
104  Convolution(filters::Convolution),
105  DropShadow(filters::DropShadow),
106  Glow(filters::Glow),
107  GradientBevel(filters::GradientBevel),
108  GradientGlow(filters::GradientGlow),
109}
110
111#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
112#[serde(rename_all = "snake_case")]
113pub struct TagHeader {
114  pub code: u16,
115  pub length: u32,
116}
117
118#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
119#[serde(tag = "type", rename_all = "kebab-case")]
120pub enum Tag {
121  CsmTextSettings(tags::CsmTextSettings),
122  DefineBinaryData(tags::DefineBinaryData),
123  DefineBitmap(tags::DefineBitmap),
124  DefineButton(tags::DefineButton),
125  DefineButtonColorTransform(tags::DefineButtonColorTransform),
126  DefineButtonSound(tags::DefineButtonSound),
127  DefineCffFont(tags::DefineCffFont),
128  DefineDynamicText(tags::DefineDynamicText),
129  DefineFont(tags::DefineFont),
130  DefineFontAlignZones(tags::DefineFontAlignZones),
131  DefineFontInfo(tags::DefineFontInfo),
132  DefineFontName(tags::DefineFontName),
133  DefineGlyphFont(tags::DefineGlyphFont),
134  DefineJpegTables(tags::DefineJpegTables),
135  DefineMorphShape(tags::DefineMorphShape),
136  DefineScalingGrid(tags::DefineScalingGrid),
137  DefineSceneAndFrameLabelData(tags::DefineSceneAndFrameLabelData),
138  DefineShape(tags::DefineShape),
139  DefineSound(tags::DefineSound),
140  DefineSprite(tags::DefineSprite),
141  DefineText(tags::DefineText),
142  DefineVideoStream(tags::DefineVideoStream),
143  EnablePostscript,
144  DoAbc(tags::DoAbc),
145  DoAction(tags::DoAction),
146  DoInitAction(tags::DoInitAction),
147  EnableDebugger(tags::EnableDebugger),
148  ExportAssets(tags::ExportAssets),
149  FileAttributes(tags::FileAttributes),
150  FrameLabel(tags::FrameLabel),
151  ImportAssets(tags::ImportAssets),
152  Metadata(tags::Metadata),
153  PlaceObject(tags::PlaceObject),
154  Protect(tags::Protect),
155  RemoveObject(tags::RemoveObject),
156  ScriptLimits(tags::ScriptLimits),
157  SetBackgroundColor(tags::SetBackgroundColor),
158  SetTabIndex(tags::SetTabIndex),
159  ShowFrame,
160  SoundStreamBlock(tags::SoundStreamBlock),
161  SoundStreamHead(tags::SoundStreamHead),
162  StartSound(tags::StartSound),
163  StartSound2(tags::StartSound2),
164  SymbolClass(tags::SymbolClass),
165  Telemetry(tags::Telemetry),
166  Unknown(tags::Unknown),
167  VideoFrame(tags::VideoFrame),
168}
169
170#[cfg(test)]
171mod tests {
172  use std::path::Path;
173
174  use ::test_generator::test_expand_paths;
175
176  use crate::Movie;
177
178  test_expand_paths! { test_movie; "../tests/movies/*/" }
179  fn test_movie(path: &str) {
180    let path: &Path = Path::new(path);
181    let _name = path
182      .components()
183      .last()
184      .unwrap()
185      .as_os_str()
186      .to_str()
187      .expect("Failed to retrieve sample name");
188    let ast_path = path.join("ast.json");
189
190    let value_json = ::std::fs::read_to_string(ast_path).expect("Failed to read AST file");
191
192    let value: Movie = serde_json_v8::from_str(&value_json).expect("Failed to read AST");
193
194    let output_json = serde_json_v8::to_string_pretty(&value).expect("Failed to write AST");
195    let output_json = format!("{}\n", output_json);
196
197    assert_eq!(output_json, value_json)
198  }
199
200  macro_rules! test_various_impl {
201    ($name:ident, $glob:expr, $type:ty) => {
202      test_expand_paths! { $name; $glob }
203      fn $name(path: &str) {
204        let path: &Path = Path::new(path);
205        let _name = path
206          .components()
207          .last()
208          .unwrap()
209          .as_os_str()
210          .to_str()
211          .expect("Failed to retrieve sample name");
212        let value_path = path.join("value.json");
213
214        let value_json = ::std::fs::read_to_string(value_path).expect("Failed to read value file");
215
216        let value: $type = serde_json_v8::from_str(&value_json).expect("Failed to read value");
217
218        let output_json = serde_json_v8::to_string_pretty(&value).expect("Failed to write value");
219        let output_json = format!("{}\n", output_json);
220
221        assert_eq!(output_json, value_json)
222      }
223    };
224  }
225
226  use crate::Tag;
227  test_various_impl!(test_tag, "../tests/tags/*/*/", Tag);
228
229  use crate::ColorTransformWithAlpha;
230  test_various_impl!(
231    test_color_transform_with_alpha,
232    "../tests/various/color-transform-with-alpha/*/",
233    ColorTransformWithAlpha
234  );
235
236  // TODO: f16
237  test_various_impl!(test_float16_le, "../tests/various/float16-le/*/", f32);
238
239  use crate::Header;
240  test_various_impl!(test_header, "../tests/various/header/*/", Header);
241
242  use crate::Matrix;
243  test_various_impl!(test_matrix, "../tests/various/matrix/*/", Matrix);
244
245  use crate::Rect;
246  test_various_impl!(test_rect, "../tests/various/rect/*/", Rect);
247
248  use crate::SwfSignature;
249  test_various_impl!(test_swf_signature, "../tests/various/swf-signature/*/", SwfSignature);
250
251  test_various_impl!(test_leb128_u32, "../tests/various/uint32-leb128/*/", u32);
252}