Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Timothy B. Terriberry
rav1e
Commits
8058856a
Commit
8058856a
authored
May 02, 2019
by
Luca Barbato
Committed by
Luca Barbato
May 02, 2019
Browse files
Move Frame to a separate file
parent
1bed1eb2
Changes
12
Hide whitespace changes
Inline
Side-by-side
src/api.rs
View file @
8058856a
...
...
@@ -10,6 +10,7 @@
use
arg_enum_proc_macro
::
ArgEnum
;
use
bitstream_io
::
*
;
use
crate
::
encoder
::
*
;
use
crate
::
frame
::
Frame
;
use
crate
::
metrics
::
calculate_frame_psnr
;
use
crate
::
partition
::
*
;
use
crate
::
rate
::
RCState
;
...
...
src/bin/decoder/y4m.rs
View file @
8058856a
...
...
@@ -6,7 +6,7 @@ use crate::decoder::Decoder;
use
crate
::
decoder
::
VideoDetails
;
use
crate
::
ChromaSamplePosition
;
use
crate
::
ChromaSampling
;
use
crate
::
encoder
::
Frame
;
use
crate
::
Frame
;
use
rav1e
::
*
;
impl
Decoder
for
y4m
::
Decoder
<
'_
,
Box
<
dyn
Read
>>
{
...
...
src/cdef.rs
View file @
8058856a
...
...
@@ -10,8 +10,8 @@
#![allow(safe_extern_statics)]
use
crate
::
context
::
*
;
use
crate
::
Frame
;
use
crate
::
FrameInvariants
;
use
crate
::
frame
::
Frame
;
use
crate
::
encoder
::
FrameInvariants
;
use
crate
::
plane
::
*
;
use
crate
::
tiling
::
*
;
use
crate
::
util
::{
clamp
,
msb
,
Pixel
,
CastFromPrimitive
};
...
...
src/encoder.rs
View file @
8058856a
...
...
@@ -11,9 +11,9 @@ use crate::api::*;
use
crate
::
cdef
::
*
;
use
crate
::
context
::
*
;
use
crate
::
deblock
::
*
;
use
crate
::
frame
::
*
;
use
crate
::
ec
::
*
;
use
crate
::
lrf
::
*
;
use
crate
::
mc
::
*
;
use
crate
::
me
::
*
;
use
crate
::
partition
::
*
;
use
crate
::
plane
::
*
;
...
...
@@ -41,128 +41,11 @@ use std::io::Read;
use
std
::
sync
::
Arc
;
use
std
::
fs
::
File
;
#[derive(Debug,
Clone)]
pub
struct
Frame
<
T
:
Pixel
>
{
pub
planes
:
[
Plane
<
T
>
;
3
]
}
pub
static
TEMPORAL_DELIMITER
:
[
u8
;
2
]
=
[
0x12
,
0x00
];
const
FRAME_MARGIN
:
usize
=
16
+
SUBPEL_FILTER_SIZE
;
impl
<
T
:
Pixel
>
Frame
<
T
>
{
pub
fn
new
(
width
:
usize
,
height
:
usize
,
chroma_sampling
:
ChromaSampling
)
->
Self
{
let
luma_width
=
width
.align_power_of_two
(
3
);
let
luma_height
=
height
.align_power_of_two
(
3
);
let
luma_padding
=
MAX_SB_SIZE
+
FRAME_MARGIN
;
let
(
chroma_sampling_period_x
,
chroma_sampling_period_y
)
=
chroma_sampling
.sampling_period
();
let
chroma_width
=
luma_width
/
chroma_sampling_period_x
;
let
chroma_height
=
luma_height
/
chroma_sampling_period_y
;
let
chroma_padding_x
=
luma_padding
/
chroma_sampling_period_x
;
let
chroma_padding_y
=
luma_padding
/
chroma_sampling_period_y
;
let
chroma_decimation_x
=
chroma_sampling_period_x
-
1
;
let
chroma_decimation_y
=
chroma_sampling_period_y
-
1
;
Frame
{
planes
:
[
Plane
::
new
(
luma_width
,
luma_height
,
0
,
0
,
luma_padding
,
luma_padding
),
Plane
::
new
(
chroma_width
,
chroma_height
,
chroma_decimation_x
,
chroma_decimation_y
,
chroma_padding_x
,
chroma_padding_y
),
Plane
::
new
(
chroma_width
,
chroma_height
,
chroma_decimation_x
,
chroma_decimation_y
,
chroma_padding_x
,
chroma_padding_y
)
]
}
}
pub
fn
pad
(
&
mut
self
,
w
:
usize
,
h
:
usize
)
{
for
p
in
self
.planes
.iter_mut
()
{
p
.pad
(
w
,
h
);
}
}
#[inline(always)]
pub
fn
as_tile
(
&
self
)
->
Tile
<
'_
,
T
>
{
let
PlaneConfig
{
width
,
height
,
..
}
=
self
.planes
[
0
]
.cfg
;
Tile
::
new
(
self
,
TileRect
{
x
:
0
,
y
:
0
,
width
,
height
})
}
#[inline(always)]
pub
fn
as_tile_mut
(
&
mut
self
)
->
TileMut
<
'_
,
T
>
{
let
PlaneConfig
{
width
,
height
,
..
}
=
self
.planes
[
0
]
.cfg
;
TileMut
::
new
(
self
,
TileRect
{
x
:
0
,
y
:
0
,
width
,
height
})
}
/// Returns a `PixelIter` containing the data of this frame's planes in YUV format.
/// Each point in the `PixelIter` is a triple consisting of a Y, U, and V component.
/// The `PixelIter` is laid out as contiguous rows, e.g. to get a given 0-indexed row
/// you could use `data.skip(width * row_idx).take(width)`.
///
/// This data retains any padding, e.g. it uses the width and height specifed in
/// the Y-plane's `cfg` struct, and not the display width and height specied in
/// `FrameInvariants`.
pub
fn
iter
(
&
self
)
->
PixelIter
<
'_
,
T
>
{
PixelIter
::
new
(
&
self
.planes
)
}
}
#[derive(Debug)]
pub
struct
PixelIter
<
'a
,
T
:
Pixel
>
{
planes
:
&
'a
[
Plane
<
T
>
;
3
],
y
:
usize
,
x
:
usize
,
}
impl
<
'a
,
T
:
Pixel
>
PixelIter
<
'a
,
T
>
{
pub
fn
new
(
planes
:
&
'a
[
Plane
<
T
>
;
3
])
->
Self
{
PixelIter
{
planes
,
y
:
0
,
x
:
0
,
}
}
fn
width
(
&
self
)
->
usize
{
self
.planes
[
0
]
.cfg.width
}
fn
height
(
&
self
)
->
usize
{
self
.planes
[
0
]
.cfg.height
}
}
impl
<
'a
,
T
:
Pixel
>
Iterator
for
PixelIter
<
'a
,
T
>
{
type
Item
=
(
T
,
T
,
T
);
fn
next
(
&
mut
self
)
->
Option
<<
Self
as
Iterator
>
::
Item
>
{
if
self
.y
==
self
.height
()
-
1
&&
self
.x
==
self
.width
()
-
1
{
return
None
;
}
let
pixel
=
(
self
.planes
[
0
]
.p
(
self
.x
,
self
.y
),
self
.planes
[
1
]
.p
(
self
.x
>>
self
.planes
[
1
]
.cfg.xdec
,
self
.y
>>
self
.planes
[
1
]
.cfg.ydec
),
self
.planes
[
2
]
.p
(
self
.x
>>
self
.planes
[
2
]
.cfg.xdec
,
self
.y
>>
self
.planes
[
2
]
.cfg.ydec
),
);
if
self
.x
==
self
.width
()
-
1
{
self
.x
=
0
;
self
.y
+=
1
;
}
else
{
self
.x
+=
1
;
}
Some
(
pixel
)
}
}
const
MAX_NUM_TEMPORAL_LAYERS
:
usize
=
8
;
const
MAX_NUM_SPATIAL_LAYERS
:
usize
=
4
;
const
MAX_NUM_OPERATING_POINTS
:
usize
=
MAX_NUM_TEMPORAL_LAYERS
*
MAX_NUM_SPATIAL_LAYERS
;
#[derive(Debug,
Clone)]
pub
struct
ReferenceFrame
<
T
:
Pixel
>
{
...
...
@@ -189,9 +72,7 @@ impl<T: Pixel> ReferenceFramesSet<T> {
}
}
const
MAX_NUM_TEMPORAL_LAYERS
:
usize
=
8
;
const
MAX_NUM_SPATIAL_LAYERS
:
usize
=
4
;
const
MAX_NUM_OPERATING_POINTS
:
usize
=
MAX_NUM_TEMPORAL_LAYERS
*
MAX_NUM_SPATIAL_LAYERS
;
#[derive(ArgEnum,
Copy,
Clone,
Debug,
PartialEq)]
#[repr(C)]
...
...
src/frame.rs
0 → 100644
View file @
8058856a
// Copyright (c) 2018, The rav1e contributors. All rights reserved
//
// This source code is subject to the terms of the BSD 2 Clause License and
// the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
// was not distributed with this source code in the LICENSE file, you can
// obtain it at www.aomedia.org/license/software. If the Alliance for Open
// Media Patent License 1.0 was not distributed with this source code in the
// PATENTS file, you can obtain it at www.aomedia.org/license/patent.
use
crate
::
util
::
*
;
use
crate
::
plane
::
*
;
use
crate
::
tiling
::
*
;
use
crate
::
api
::
ChromaSampling
;
use
crate
::
context
::
MAX_SB_SIZE
;
use
crate
::
mc
::
SUBPEL_FILTER_SIZE
;
const
FRAME_MARGIN
:
usize
=
16
+
SUBPEL_FILTER_SIZE
;
#[derive(Debug,
Clone)]
pub
struct
Frame
<
T
:
Pixel
>
{
pub
planes
:
[
Plane
<
T
>
;
3
]
}
impl
<
T
:
Pixel
>
Frame
<
T
>
{
pub
fn
new
(
width
:
usize
,
height
:
usize
,
chroma_sampling
:
ChromaSampling
)
->
Self
{
let
luma_width
=
width
.align_power_of_two
(
3
);
let
luma_height
=
height
.align_power_of_two
(
3
);
let
luma_padding
=
MAX_SB_SIZE
+
FRAME_MARGIN
;
let
(
chroma_sampling_period_x
,
chroma_sampling_period_y
)
=
chroma_sampling
.sampling_period
();
let
chroma_width
=
luma_width
/
chroma_sampling_period_x
;
let
chroma_height
=
luma_height
/
chroma_sampling_period_y
;
let
chroma_padding_x
=
luma_padding
/
chroma_sampling_period_x
;
let
chroma_padding_y
=
luma_padding
/
chroma_sampling_period_y
;
let
chroma_decimation_x
=
chroma_sampling_period_x
-
1
;
let
chroma_decimation_y
=
chroma_sampling_period_y
-
1
;
Frame
{
planes
:
[
Plane
::
new
(
luma_width
,
luma_height
,
0
,
0
,
luma_padding
,
luma_padding
),
Plane
::
new
(
chroma_width
,
chroma_height
,
chroma_decimation_x
,
chroma_decimation_y
,
chroma_padding_x
,
chroma_padding_y
),
Plane
::
new
(
chroma_width
,
chroma_height
,
chroma_decimation_x
,
chroma_decimation_y
,
chroma_padding_x
,
chroma_padding_y
)
]
}
}
pub
fn
pad
(
&
mut
self
,
w
:
usize
,
h
:
usize
)
{
for
p
in
self
.planes
.iter_mut
()
{
p
.pad
(
w
,
h
);
}
}
#[inline(always)]
pub
fn
as_tile
(
&
self
)
->
Tile
<
'_
,
T
>
{
let
PlaneConfig
{
width
,
height
,
..
}
=
self
.planes
[
0
]
.cfg
;
Tile
::
new
(
self
,
TileRect
{
x
:
0
,
y
:
0
,
width
,
height
})
}
#[inline(always)]
pub
fn
as_tile_mut
(
&
mut
self
)
->
TileMut
<
'_
,
T
>
{
let
PlaneConfig
{
width
,
height
,
..
}
=
self
.planes
[
0
]
.cfg
;
TileMut
::
new
(
self
,
TileRect
{
x
:
0
,
y
:
0
,
width
,
height
})
}
/// Returns a `PixelIter` containing the data of this frame's planes in YUV format.
/// Each point in the `PixelIter` is a triple consisting of a Y, U, and V component.
/// The `PixelIter` is laid out as contiguous rows, e.g. to get a given 0-indexed row
/// you could use `data.skip(width * row_idx).take(width)`.
///
/// This data retains any padding, e.g. it uses the width and height specifed in
/// the Y-plane's `cfg` struct, and not the display width and height specied in
/// `FrameInvariants`.
pub
fn
iter
(
&
self
)
->
PixelIter
<
'_
,
T
>
{
PixelIter
::
new
(
&
self
.planes
)
}
}
#[derive(Debug)]
pub
struct
PixelIter
<
'a
,
T
:
Pixel
>
{
planes
:
&
'a
[
Plane
<
T
>
;
3
],
y
:
usize
,
x
:
usize
,
}
impl
<
'a
,
T
:
Pixel
>
PixelIter
<
'a
,
T
>
{
pub
fn
new
(
planes
:
&
'a
[
Plane
<
T
>
;
3
])
->
Self
{
PixelIter
{
planes
,
y
:
0
,
x
:
0
,
}
}
fn
width
(
&
self
)
->
usize
{
self
.planes
[
0
]
.cfg.width
}
fn
height
(
&
self
)
->
usize
{
self
.planes
[
0
]
.cfg.height
}
}
impl
<
'a
,
T
:
Pixel
>
Iterator
for
PixelIter
<
'a
,
T
>
{
type
Item
=
(
T
,
T
,
T
);
fn
next
(
&
mut
self
)
->
Option
<<
Self
as
Iterator
>
::
Item
>
{
if
self
.y
==
self
.height
()
-
1
&&
self
.x
==
self
.width
()
-
1
{
return
None
;
}
let
pixel
=
(
self
.planes
[
0
]
.p
(
self
.x
,
self
.y
),
self
.planes
[
1
]
.p
(
self
.x
>>
self
.planes
[
1
]
.cfg.xdec
,
self
.y
>>
self
.planes
[
1
]
.cfg.ydec
),
self
.planes
[
2
]
.p
(
self
.x
>>
self
.planes
[
2
]
.cfg.xdec
,
self
.y
>>
self
.planes
[
2
]
.cfg.ydec
),
);
if
self
.x
==
self
.width
()
-
1
{
self
.x
=
0
;
self
.y
+=
1
;
}
else
{
self
.x
+=
1
;
}
Some
(
pixel
)
}
}
src/lib.rs
View file @
8058856a
...
...
@@ -51,12 +51,15 @@ pub mod tiling;
mod
api
;
mod
header
;
mod
frame
;
pub
use
crate
::
api
::
*
;
pub
use
crate
::
encoder
::
*
;
pub
use
crate
::
header
::
*
;
pub
use
crate
::
util
::{
CastFromPrimitive
,
Pixel
};
pub
use
crate
::
frame
::
Frame
;
#[cfg(all(test,
any(feature=
"decode_test"
,
feature=
"decode_test_dav1d"
)))]
mod
test_encode_decode
;
...
...
src/lrf.rs
View file @
8058856a
...
...
@@ -9,7 +9,7 @@
#![allow(safe_extern_statics)]
use
crate
::
encoder
::
Frame
;
use
crate
::
frame
::
Frame
;
use
crate
::
encoder
::
FrameInvariants
;
use
crate
::
context
::
PLANES
;
use
crate
::
context
::
MAX_SB_SIZE
;
...
...
src/metrics.rs
View file @
8058856a
...
...
@@ -7,7 +7,7 @@
// Media Patent License 1.0 was not distributed with this source code in the
// PATENTS file, you can obtain it at www.aomedia.org/license/patent.
use
crate
::
encoder
::
Frame
;
use
crate
::
frame
::
Frame
;
use
crate
::
plane
::
Plane
;
use
crate
::
util
::{
CastFromPrimitive
,
Pixel
};
...
...
src/rdo.rs
View file @
8058856a
...
...
@@ -19,8 +19,8 @@ use crate::header::ReferenceMode;
use
crate
::
encode_block_a
;
use
crate
::
encode_block_b
;
use
crate
::
encode_block_with_modes
;
use
crate
::
FrameInvariants
;
use
crate
::
Frame
;
use
crate
::
encoder
::
FrameInvariants
;
use
crate
::
frame
::
Frame
;
use
crate
::
luma_ac
;
use
crate
::
me
::
*
;
use
crate
::
motion_compensate
;
...
...
src/scenechange/mod.rs
View file @
8058856a
...
...
@@ -7,7 +7,7 @@
// Media Patent License 1.0 was not distributed with this source code in the
// PATENTS file, you can obtain it at www.aomedia.org/license/patent.
use
crate
::
encoder
::
Frame
;
use
crate
::
frame
::
Frame
;
use
crate
::
util
::{
CastFromPrimitive
,
Pixel
};
use
std
::
sync
::
Arc
;
...
...
src/tiling/tile.rs
View file @
8058856a
...
...
@@ -10,7 +10,7 @@
use
super
::
*
;
use
crate
::
context
::
*
;
use
crate
::
encoder
::
*
;
use
crate
::
frame
::
*
;
use
crate
::
plane
::
*
;
use
crate
::
util
::
*
;
...
...
src/tiling/tile_state.rs
View file @
8058856a
...
...
@@ -11,6 +11,7 @@ use super::*;
use
crate
::
context
::
*
;
use
crate
::
encoder
::
*
;
use
crate
::
frame
::
*
;
use
crate
::
plane
::
*
;
use
crate
::
quantize
::
*
;
use
crate
::
rdo
::
*
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment