Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
preview-generator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mediaflix
preview-generator
Commits
ecc3b823
Commit
ecc3b823
authored
5 years ago
by
Janne Mareike Koschinski
Browse files
Options
Downloads
Patches
Plain Diff
add more configurable image formats
parent
188f0862
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/ingest/extract.rs
+2
-1
2 additions, 1 deletion
src/ingest/extract.rs
src/ingest/spritesheet.rs
+41
-19
41 additions, 19 deletions
src/ingest/spritesheet.rs
src/main.rs
+11
-3
11 additions, 3 deletions
src/main.rs
with
54 additions
and
23 deletions
src/ingest/extract.rs
+
2
−
1
View file @
ecc3b823
use
std
::
path
::
Path
;
use
failure
::{
format_err
,
Error
};
use
image
::
ImageOutputFormat
;
use
crate
::
ffmpeg_api
::
api
::
*
;
use
crate
::
ffmpeg_api
::
enums
::
*
;
...
...
@@ -15,7 +16,7 @@ pub fn extract(
frame_interval
:
MediaTime
,
input_file
:
&
Path
,
output_folder
:
&
Path
,
format
:
impl
AsRef
<
str
>
,
format
:
ImageOutputFormat
,
scaler
:
SwsScaler
,
flags
:
SwsFlags
,
)
->
Result
<
(),
Error
>
{
...
...
This diff is collapsed.
Click to expand it.
src/ingest/spritesheet.rs
+
41
−
19
View file @
ecc3b823
use
std
::
fs
::
File
;
use
std
::
io
::
BufWriter
;
use
std
::
path
::
PathBuf
;
use
failure
::{
bail
,
format_err
,
Error
};
use
image
::{
ImageBuffer
,
RgbImage
};
use
image
::{
DynamicImage
,
ImageOutputFormat
,
RgbImage
};
use
crate
::
util
::
media_time
::
MediaTime
;
use
crate
::
util
::
webvtt
::{
WebVTTCue
,
WebVTTFile
};
pub
enum
ImageFormat
{
Jpeg
(
i32
),
Png
,
}
pub
struct
SpritesheetManager
{
num_horizontal
:
u32
,
num_vertical
:
u32
,
...
...
@@ -19,7 +26,7 @@ pub struct SpritesheetManager {
metadata
:
WebVTTFile
,
output_path
:
PathBuf
,
name
:
String
,
format
:
String
,
format
:
ImageOutputFormat
,
initialized
:
bool
,
}
...
...
@@ -31,7 +38,7 @@ impl SpritesheetManager {
frame_interval
:
MediaTime
,
output_path
:
impl
Into
<
PathBuf
>
,
name
:
impl
AsRef
<
str
>
,
format
:
impl
AsRef
<
str
>
,
format
:
ImageOutputFormat
,
)
->
SpritesheetManager
{
SpritesheetManager
{
num_horizontal
,
...
...
@@ -39,14 +46,14 @@ impl SpritesheetManager {
max_side
,
sprite_width
:
0
,
sprite_height
:
0
,
spritesheet
:
Image
Buffer
::
new
(
0
,
0
),
spritesheet
:
Rgb
Image
::
new
(
0
,
0
),
current_image
:
0
,
last_timestamp
:
MediaTime
::
from_millis
(
0
),
frame_interval
,
metadata
:
WebVTTFile
::
new
(),
output_path
:
output_path
.into
(),
name
:
String
::
from
(
name
.as_ref
()),
format
:
String
::
from
(
format
.as_ref
())
,
format
,
initialized
:
false
,
}
}
...
...
@@ -59,15 +66,15 @@ impl SpritesheetManager {
self
.sprite_height
=
self
.max_side
;
self
.sprite_width
=
self
.sprite_height
*
width
/
height
;
}
self
.reinit_buffer
();
self
.spritesheet
=
self
.reinit_buffer
();
self
.initialized
=
true
;
}
fn
reinit_buffer
(
&
mut
self
)
{
self
.spritesheet
=
ImageBuffer
::
new
(
fn
reinit_buffer
(
&
self
)
->
RgbImage
{
RgbImage
::
new
(
self
.sprite_width
*
self
.num_horizontal
,
self
.sprite_height
*
self
.num_vertical
,
)
;
)
}
pub
fn
initialized
(
&
self
)
->
bool
{
...
...
@@ -95,6 +102,15 @@ impl SpritesheetManager {
index
*
self
.sprite_width
}
fn
ending
(
&
self
)
->
String
{
String
::
from
(
match
self
.format
{
ImageOutputFormat
::
Png
=>
"png"
,
ImageOutputFormat
::
Jpeg
(
_
)
=>
"jpeg"
,
ImageOutputFormat
::
Bmp
=>
"bmp"
,
_
=>
panic!
(
"Invalid image format: {:?}"
,
self
.format
),
})
}
fn
y
(
&
self
,
current
:
u32
)
->
u32
{
let
index
=
(
current
/
self
.num_horizontal
)
%
self
.num_vertical
;
index
*
self
.sprite_height
...
...
@@ -141,7 +157,7 @@ impl SpritesheetManager {
"{}_{}.{}#xywh={},{},{},{}"
,
self
.name
,
self
.spritesheet_index
(
self
.current_image
-
1
),
self
.
format
,
self
.
ending
()
,
self
.x
(
self
.current_image
-
1
),
self
.y
(
self
.current_image
-
1
),
self
.sprite_width
,
...
...
@@ -151,15 +167,21 @@ impl SpritesheetManager {
}
fn
save_spritesheet
(
&
mut
self
)
->
Result
<
(),
Error
>
{
self
.spritesheet
.save
(
self
.output_path
.join
(
format!
(
let
name
=
format!
(
"{}_{}.{}"
,
self
.name
,
self
.spritesheet_index
(
self
.current_image
),
self
.format
)))
.map_err
(|
error
|
format_err!
(
"Could not write spritesheet: {}"
,
error
))
?
;
self
.reinit_buffer
();
self
.ending
(),
);
let
file
=
File
::
create
(
self
.output_path
.join
(
&
name
))
.map_err
(|
err
|
format_err!
(
"Could not create spritesheet {}: {}"
,
&
name
,
err
))
?
;
let
new_buffer
=
self
.reinit_buffer
();
DynamicImage
::
ImageRgb8
(
std
::
mem
::
replace
(
&
mut
self
.spritesheet
,
new_buffer
))
.write_to
(
&
mut
BufWriter
::
new
(
file
),
self
.format
.clone
())
.map_err
(|
err
|
format_err!
(
"Could not write spritesheet {}: {}"
,
&
name
,
err
))
?
;
Ok
(())
}
...
...
This diff is collapsed.
Click to expand it.
src/main.rs
+
11
−
3
View file @
ecc3b823
...
...
@@ -11,6 +11,7 @@ use structopt::StructOpt;
use
crate
::
ffmpeg_api
::
enums
::{
SwsFlags
,
SwsScaler
};
use
crate
::
util
::
media_time
::
MediaTime
;
use
image
::
ImageOutputFormat
;
fn
parse_scaler
(
src
:
&
str
)
->
Result
<
SwsScaler
,
String
>
{
match
src
{
...
...
@@ -40,10 +41,12 @@ struct Options {
num_horizontal
:
u32
,
#[structopt(long
=
"num-vertical"
,
default_value
=
"5"
)]
num_vertical
:
u32
,
#[structopt(long
=
"max-size"
,
default_value
=
"
16
0"
)]
#[structopt(long
=
"max-size"
,
default_value
=
"
24
0"
)]
max_size
:
u32
,
#[structopt(long
=
"format"
,
default_value
=
"p
n
g"
)]
#[structopt(long
=
"format"
,
default_value
=
"
j
pg"
)]
format
:
String
,
#[structopt(long
=
"quality"
,
default_value
=
"90"
)]
quality
:
u8
,
#[structopt(long
=
"scaler"
,
default_value
=
"area"
,
parse(try_from_str
=
parse_scaler))]
scaler
:
SwsScaler
,
#[structopt(long
=
"fast-chroma"
)]
...
...
@@ -75,7 +78,12 @@ fn main() -> Result<(), Error> {
MediaTime
::
from_seconds
(
options
.frame_interval
),
Path
::
new
(
&
options
.input
),
Path
::
new
(
&
options
.output
),
options
.format
,
match
options
.format
.as_str
()
{
"jpeg"
|
"jpg"
=>
ImageOutputFormat
::
Jpeg
(
options
.quality
),
"png"
=>
ImageOutputFormat
::
Png
,
"bmp"
=>
ImageOutputFormat
::
Bmp
,
_
=>
panic!
(
"Unsupported image format: {}"
,
options
.format
),
},
options
.scaler
,
flags
,
)
?
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment