render: Moved render utils from core to render

This commit is contained in:
Nathan Adams 2022-08-14 00:58:40 +02:00 committed by Mike Welsh
parent bc0c7cbccb
commit 9fd8fd938e
8 changed files with 31 additions and 25 deletions

7
Cargo.lock generated
View File

@ -3025,12 +3025,10 @@ dependencies = [
"futures",
"gc-arena",
"generational-arena",
"gif",
"h263-rs",
"h263-rs-yuv",
"indexmap",
"instant",
"jpeg-decoder",
"log",
"lzma-rs",
"minimp3",
@ -3041,7 +3039,6 @@ dependencies = [
"num-derive",
"num-traits",
"percent-encoding",
"png",
"quick-xml",
"rand",
"regress",
@ -3102,8 +3099,12 @@ dependencies = [
name = "ruffle_render"
version = "0.1.0"
dependencies = [
"flate2",
"gc-arena",
"gif",
"jpeg-decoder",
"log",
"png",
"swf",
]

View File

@ -12,11 +12,9 @@ flate2 = "1.0.24"
fnv = "1.0.7"
gc-arena = { git = "https://github.com/ruffle-rs/gc-arena" }
generational-arena = "0.2.8"
gif = "0.11.4"
indexmap = "1.9.1"
log = "0.4"
minimp3 = { version = "0.5.1", optional = true }
png = { version = "0.17.5" }
ruffle_render = { path = "../render" }
ruffle_macros = { path = "macros" }
ruffle_wstr = { path = "../wstr" }
@ -49,10 +47,6 @@ nihav_core = { git = "https://github.com/ruffle-rs/nihav-vp6", rev = "9416fcc9fc
nihav_codec_support = { git = "https://github.com/ruffle-rs/nihav-vp6", rev = "9416fcc9fc8aab8f4681aa9093b42922214abbd3", optional = true }
nihav_duck = { git = "https://github.com/ruffle-rs/nihav-vp6", rev = "9416fcc9fc8aab8f4681aa9093b42922214abbd3", optional = true }
[dependencies.jpeg-decoder]
version = "0.2.6"
default-features = false # can't use rayon on web
[target.'cfg(not(target_family = "wasm"))'.dependencies.futures]
version = "0.3.21"

View File

@ -1,14 +1,14 @@
mod null;
mod utils;
pub use null::{NullBitmapSource, NullRenderer};
pub use utils::{determine_jpeg_tag_format, remove_invalid_jpeg_data};
pub use ruffle_render::utils::{determine_jpeg_tag_format, remove_invalid_jpeg_data};
use crate::matrix::Matrix;
use crate::shape_utils::DistilledShape;
pub use crate::transform::Transform;
use downcast_rs::Downcast;
use ruffle_render::bitmap::{Bitmap, BitmapFormat, BitmapHandle, BitmapInfo, BitmapSource};
use ruffle_render::bitmap::{Bitmap, BitmapHandle, BitmapInfo, BitmapSource};
use ruffle_render::utils;
pub use swf;
pub trait RenderBackend: Downcast {
@ -107,14 +107,3 @@ type Error = Box<dyn std::error::Error>;
#[derive(Copy, Clone, Debug)]
pub struct ShapeHandle(pub usize);
/// The format of image data in a DefineBitsJpeg2/3 tag.
/// Generally this will be JPEG, but according to SWF19, these tags can also contain PNG and GIF data.
/// SWF19 pp.138-139
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum JpegTagFormat {
Jpeg,
Png,
Gif,
Unknown,
}

View File

@ -13,7 +13,6 @@ use crate::avm2::{
Value as Avm2Value,
};
use crate::backend::navigator::{OwnedFuture, Request};
use crate::backend::render::{determine_jpeg_tag_format, JpegTagFormat};
use crate::context::{ActionQueue, ActionType, UpdateContext};
use crate::display_object::{
Bitmap, DisplayObject, TDisplayObject, TDisplayObjectContainer, TInteractiveObject,
@ -26,6 +25,7 @@ use crate::vminterface::Instantiator;
use encoding_rs::UTF_8;
use gc_arena::{Collect, CollectionContext};
use generational_arena::{Arena, Index};
use ruffle_render::utils::{determine_jpeg_tag_format, JpegTagFormat};
use std::fmt;
use std::sync::{Arc, Mutex, Weak};
use swf::read::read_compression_type;

View File

@ -9,4 +9,11 @@ license = "MIT OR Apache-2.0"
swf = {path = "../swf"}
gc-arena = { git = "https://github.com/ruffle-rs/gc-arena" }
log = "0.4"
gif = "0.11.4"
png = { version = "0.17.5" }
flate2 = "1.0.24"
[dependencies.jpeg-decoder]
version = "0.2.6"
default-features = false # can't use rayon on web

1
render/src/error.rs Normal file
View File

@ -0,0 +1 @@
pub type Error = Box<dyn std::error::Error>;

View File

@ -1 +1,3 @@
pub mod bitmap;
pub mod error;
pub mod utils;

View File

@ -1,8 +1,20 @@
use crate::backend::render::{Bitmap, BitmapFormat, Error, JpegTagFormat};
use crate::bitmap::{Bitmap, BitmapFormat};
use crate::error::Error;
use std::borrow::Cow;
use std::io::Read;
use swf::Color;
/// The format of image data in a DefineBitsJpeg2/3 tag.
/// Generally this will be JPEG, but according to SWF19, these tags can also contain PNG and GIF data.
/// SWF19 pp.138-139
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum JpegTagFormat {
Jpeg,
Png,
Gif,
Unknown,
}
/// Determines the format of the image data in `data` from a DefineBitsJPEG2/3 tag.
pub fn determine_jpeg_tag_format(data: &[u8]) -> JpegTagFormat {
match data {