Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Guillaume Martres
aom-rav1e
Commits
254889cd
Commit
254889cd
authored
Dec 06, 2011
by
Yunqing Wang
Committed by
Gerrit Code Review
Dec 06, 2011
Browse files
Merge "Allow aligning the raw image buffer"
parents
aa7335e6
be5bbc96
Changes
2
Hide whitespace changes
Inline
Side-by-side
vpx/src/vpx_image.c
View file @
254889cd
...
...
@@ -13,10 +13,42 @@
#include
<string.h>
#include
"vpx/vpx_image.h"
#define ADDRESS_STORAGE_SIZE sizeof(size_t)
/*returns an addr aligned to the byte boundary specified by align*/
#define align_addr(addr,align) (void*)(((size_t)(addr) + ((align) - 1)) & (size_t)-(align))
/* Memalign code is copied from vpx_mem.c */
static
void
*
img_buf_memalign
(
size_t
align
,
size_t
size
)
{
void
*
addr
,
*
x
=
NULL
;
addr
=
malloc
(
size
+
align
-
1
+
ADDRESS_STORAGE_SIZE
);
if
(
addr
)
{
x
=
align_addr
((
unsigned
char
*
)
addr
+
ADDRESS_STORAGE_SIZE
,
(
int
)
align
);
/* save the actual malloc address */
((
size_t
*
)
x
)[
-
1
]
=
(
size_t
)
addr
;
}
return
x
;
}
static
void
img_buf_free
(
void
*
memblk
)
{
if
(
memblk
)
{
void
*
addr
=
(
void
*
)(((
size_t
*
)
memblk
)[
-
1
]);
free
(
addr
);
}
}
static
vpx_image_t
*
img_alloc_helper
(
vpx_image_t
*
img
,
vpx_img_fmt_t
fmt
,
unsigned
int
d_w
,
unsigned
int
d_h
,
unsigned
int
buf_align
,
unsigned
int
stride_align
,
unsigned
char
*
img_data
)
{
...
...
@@ -24,6 +56,14 @@ static vpx_image_t *img_alloc_helper(vpx_image_t *img,
unsigned
int
h
,
w
,
s
,
xcs
,
ycs
,
bps
;
int
align
;
/* Treat align==0 like align==1 */
if
(
!
buf_align
)
buf_align
=
1
;
/* Validate alignment (must be power of 2) */
if
(
buf_align
&
(
buf_align
-
1
))
goto
fail
;
/* Treat align==0 like align==1 */
if
(
!
stride_align
)
stride_align
=
1
;
...
...
@@ -119,7 +159,8 @@ static vpx_image_t *img_alloc_helper(vpx_image_t *img,
if
(
!
img_data
)
{
img
->
img_data
=
malloc
((
fmt
&
VPX_IMG_FMT_PLANAR
)
?
h
*
w
*
bps
/
8
:
h
*
s
);
img
->
img_data
=
img_buf_memalign
(
buf_align
,
((
fmt
&
VPX_IMG_FMT_PLANAR
)
?
h
*
s
*
bps
/
8
:
h
*
s
));
img
->
img_data_owner
=
1
;
}
...
...
@@ -150,9 +191,9 @@ vpx_image_t *vpx_img_alloc(vpx_image_t *img,
vpx_img_fmt_t
fmt
,
unsigned
int
d_w
,
unsigned
int
d_h
,
unsigned
int
stride_
align
)
unsigned
int
align
)
{
return
img_alloc_helper
(
img
,
fmt
,
d_w
,
d_h
,
stride_
align
,
NULL
);
return
img_alloc_helper
(
img
,
fmt
,
d_w
,
d_h
,
align
,
align
,
NULL
);
}
vpx_image_t
*
vpx_img_wrap
(
vpx_image_t
*
img
,
...
...
@@ -162,7 +203,9 @@ vpx_image_t *vpx_img_wrap(vpx_image_t *img,
unsigned
int
stride_align
,
unsigned
char
*
img_data
)
{
return
img_alloc_helper
(
img
,
fmt
,
d_w
,
d_h
,
stride_align
,
img_data
);
/* By setting buf_align = 1, we don't change buffer alignment in this
* function. */
return
img_alloc_helper
(
img
,
fmt
,
d_w
,
d_h
,
1
,
stride_align
,
img_data
);
}
int
vpx_img_set_rect
(
vpx_image_t
*
img
,
...
...
@@ -254,7 +297,7 @@ void vpx_img_free(vpx_image_t *img)
if
(
img
)
{
if
(
img
->
img_data
&&
img
->
img_data_owner
)
free
(
img
->
img_data
);
img_buf_
free
(
img
->
img_data
);
if
(
img
->
self_allocd
)
free
(
img
);
...
...
vpx/vpx_image.h
View file @
254889cd
...
...
@@ -160,7 +160,8 @@ extern "C" {
* \param[in] fmt Format for the image
* \param[in] d_w Width of the image
* \param[in] d_h Height of the image
* \param[in] align Alignment, in bytes, of each row in the image.
* \param[in] align Alignment, in bytes, of the image buffer and
* each row in the image(stride).
*
* \return Returns a pointer to the initialized image descriptor. If the img
* parameter is non-null, the value of the img parameter will be
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment