Mercurial > libavcore.hg
annotate imgutils.c @ 26:ec642b5a1d0a libavcore
Add missing checks on invalid pixel format in
av_image_fill_linesizes/pointers.
author | stefano |
---|---|
date | Tue, 07 Sep 2010 23:41:18 +0000 |
parents | 63d8168fa16a |
children |
rev | line source |
---|---|
8
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
1 /* |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
2 * This file is part of FFmpeg. |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
3 * |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
4 * FFmpeg is free software; you can redistribute it and/or |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
5 * modify it under the terms of the GNU Lesser General Public |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
6 * License as published by the Free Software Foundation; either |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
7 * version 2.1 of the License, or (at your option) any later version. |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
8 * |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
9 * FFmpeg is distributed in the hope that it will be useful, |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
12 * Lesser General Public License for more details. |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
13 * |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
14 * You should have received a copy of the GNU Lesser General Public |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
15 * License along with FFmpeg; if not, write to the Free Software |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
17 */ |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
18 |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
19 /** |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
20 * @file |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
21 * misc image utilities |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
22 */ |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
23 |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
24 #include "imgutils.h" |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
25 #include "libavutil/pixdesc.h" |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
26 |
22
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
27 void av_image_fill_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4], |
21
3b8eec1cfdaa
Make av_fill_image_max_pixsteps() non static non inline.
stefano
parents:
19
diff
changeset
|
28 const AVPixFmtDescriptor *pixdesc) |
3b8eec1cfdaa
Make av_fill_image_max_pixsteps() non static non inline.
stefano
parents:
19
diff
changeset
|
29 { |
3b8eec1cfdaa
Make av_fill_image_max_pixsteps() non static non inline.
stefano
parents:
19
diff
changeset
|
30 int i; |
3b8eec1cfdaa
Make av_fill_image_max_pixsteps() non static non inline.
stefano
parents:
19
diff
changeset
|
31 memset(max_pixsteps, 0, 4*sizeof(max_pixsteps[0])); |
3b8eec1cfdaa
Make av_fill_image_max_pixsteps() non static non inline.
stefano
parents:
19
diff
changeset
|
32 if (max_pixstep_comps) |
3b8eec1cfdaa
Make av_fill_image_max_pixsteps() non static non inline.
stefano
parents:
19
diff
changeset
|
33 memset(max_pixstep_comps, 0, 4*sizeof(max_pixstep_comps[0])); |
3b8eec1cfdaa
Make av_fill_image_max_pixsteps() non static non inline.
stefano
parents:
19
diff
changeset
|
34 |
3b8eec1cfdaa
Make av_fill_image_max_pixsteps() non static non inline.
stefano
parents:
19
diff
changeset
|
35 for (i = 0; i < 4; i++) { |
3b8eec1cfdaa
Make av_fill_image_max_pixsteps() non static non inline.
stefano
parents:
19
diff
changeset
|
36 const AVComponentDescriptor *comp = &(pixdesc->comp[i]); |
3b8eec1cfdaa
Make av_fill_image_max_pixsteps() non static non inline.
stefano
parents:
19
diff
changeset
|
37 if ((comp->step_minus1+1) > max_pixsteps[comp->plane]) { |
3b8eec1cfdaa
Make av_fill_image_max_pixsteps() non static non inline.
stefano
parents:
19
diff
changeset
|
38 max_pixsteps[comp->plane] = comp->step_minus1+1; |
3b8eec1cfdaa
Make av_fill_image_max_pixsteps() non static non inline.
stefano
parents:
19
diff
changeset
|
39 if (max_pixstep_comps) |
3b8eec1cfdaa
Make av_fill_image_max_pixsteps() non static non inline.
stefano
parents:
19
diff
changeset
|
40 max_pixstep_comps[comp->plane] = i; |
3b8eec1cfdaa
Make av_fill_image_max_pixsteps() non static non inline.
stefano
parents:
19
diff
changeset
|
41 } |
3b8eec1cfdaa
Make av_fill_image_max_pixsteps() non static non inline.
stefano
parents:
19
diff
changeset
|
42 } |
3b8eec1cfdaa
Make av_fill_image_max_pixsteps() non static non inline.
stefano
parents:
19
diff
changeset
|
43 } |
3b8eec1cfdaa
Make av_fill_image_max_pixsteps() non static non inline.
stefano
parents:
19
diff
changeset
|
44 |
22
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
45 int av_image_get_linesize(enum PixelFormat pix_fmt, int width, int plane) |
15 | 46 { |
47 const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; | |
48 int max_step [4]; /* max pixel step for each plane */ | |
49 int max_step_comp[4]; /* the component for each plane which has the max pixel step */ | |
16
1a1faa090ff1
Implement inline function av_fill_image_max_pixstep() and use it for
stefano
parents:
15
diff
changeset
|
50 int s; |
15 | 51 |
52 if (desc->flags & PIX_FMT_BITSTREAM) | |
53 return (width * (desc->comp[0].step_minus1+1) + 7) >> 3; | |
54 | |
22
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
55 av_image_fill_max_pixsteps(max_step, max_step_comp, desc); |
15 | 56 s = (max_step_comp[plane] == 1 || max_step_comp[plane] == 2) ? desc->log2_chroma_w : 0; |
57 return max_step[plane] * (((width + (1 << s) - 1)) >> s); | |
58 } | |
59 | |
22
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
60 int av_image_fill_linesizes(int linesizes[4], enum PixelFormat pix_fmt, int width) |
8
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
61 { |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
62 int i; |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
63 const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; |
9
4cecefd36670
Rename av_fill_image_linesizes() internal variables max_plane_step and
stefano
parents:
8
diff
changeset
|
64 int max_step [4]; /* max pixel step for each plane */ |
4cecefd36670
Rename av_fill_image_linesizes() internal variables max_plane_step and
stefano
parents:
8
diff
changeset
|
65 int max_step_comp[4]; /* the component for each plane which has the max pixel step */ |
8
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
66 |
12
c37229a98056
Rename the av_fill_image_linesize() formal parameter linesize to
stefano
parents:
11
diff
changeset
|
67 memset(linesizes, 0, 4*sizeof(linesizes[0])); |
8
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
68 |
26 | 69 if ((unsigned)pix_fmt >= PIX_FMT_NB || desc->flags & PIX_FMT_HWACCEL) |
10
356600e12af7
Make av_fill_image_linesizes() return a meaningful error core rather
stefano
parents:
9
diff
changeset
|
70 return AVERROR(EINVAL); |
8
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
71 |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
72 if (desc->flags & PIX_FMT_BITSTREAM) { |
12
c37229a98056
Rename the av_fill_image_linesize() formal parameter linesize to
stefano
parents:
11
diff
changeset
|
73 linesizes[0] = (width * (desc->comp[0].step_minus1+1) + 7) >> 3; |
8
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
74 return 0; |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
75 } |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
76 |
22
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
77 av_image_fill_max_pixsteps(max_step, max_step_comp, desc); |
8
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
78 for (i = 0; i < 4; i++) { |
9
4cecefd36670
Rename av_fill_image_linesizes() internal variables max_plane_step and
stefano
parents:
8
diff
changeset
|
79 int s = (max_step_comp[i] == 1 || max_step_comp[i] == 2) ? desc->log2_chroma_w : 0; |
12
c37229a98056
Rename the av_fill_image_linesize() formal parameter linesize to
stefano
parents:
11
diff
changeset
|
80 linesizes[i] = max_step[i] * (((width + (1 << s) - 1)) >> s); |
8
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
81 } |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
82 |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
83 return 0; |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
84 } |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
85 |
22
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
86 int av_image_fill_pointers(uint8_t *data[4], enum PixelFormat pix_fmt, int height, |
11
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
87 uint8_t *ptr, const int linesizes[4]) |
8
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
88 { |
11
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
89 int i, total_size, size[4], has_plane[4]; |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
90 |
8
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
91 const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; |
11
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
92 memset(data , 0, sizeof(data[0])*4); |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
93 memset(size , 0, sizeof(size)); |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
94 memset(has_plane, 0, sizeof(has_plane)); |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
95 |
26 | 96 if ((unsigned)pix_fmt >= PIX_FMT_NB || desc->flags & PIX_FMT_HWACCEL) |
11
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
97 return AVERROR(EINVAL); |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
98 |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
99 data[0] = ptr; |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
100 size[0] = linesizes[0] * height; |
8
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
101 |
11
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
102 if (desc->flags & PIX_FMT_PAL) { |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
103 size[0] = (size[0] + 3) & ~3; |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
104 data[1] = ptr + size[0]; /* palette is stored here as 256 32 bits words */ |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
105 return size[0] + 256 * 4; |
8
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
106 } |
11
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
107 |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
108 for (i = 0; i < 4; i++) |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
109 has_plane[desc->comp[i].plane] = 1; |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
110 |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
111 total_size = size[0]; |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
112 for (i = 1; has_plane[i] && i < 4; i++) { |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
113 int h, s = (i == 1 || i == 2) ? desc->log2_chroma_h : 0; |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
114 data[i] = data[i-1] + size[i-1]; |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
115 h = (height + (1 << s) - 1) >> s; |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
116 size[i] = h * linesizes[i]; |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
117 total_size += size[i]; |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
118 } |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
119 |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
120 return total_size; |
8
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
121 } |
13
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
122 |
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
123 typedef struct ImgUtils { |
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
124 const AVClass *class; |
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
125 int log_offset; |
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
126 void *log_ctx; |
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
127 } ImgUtils; |
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
128 |
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
129 static const AVClass imgutils_class = { "IMGUTILS", av_default_item_name, NULL, LIBAVUTIL_VERSION_INT, offsetof(ImgUtils, log_offset), offsetof(ImgUtils, log_ctx) }; |
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
130 |
22
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
131 int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx) |
13
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
132 { |
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
133 ImgUtils imgutils = { &imgutils_class, log_offset, log_ctx }; |
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
134 |
19 | 135 if ((int)w>0 && (int)h>0 && (w+128)*(uint64_t)(h+128) < INT_MAX/8) |
13
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
136 return 0; |
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
137 |
14 | 138 av_log(&imgutils, AV_LOG_ERROR, "Picture size %ux%u is invalid\n", w, h); |
13
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
139 return AVERROR(EINVAL); |
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
140 } |
22
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
141 |
23
478992775cf8
Reimplement ff_img_copy_plane() as av_image_copy_plane() in libavcore,
stefano
parents:
22
diff
changeset
|
142 void av_image_copy_plane(uint8_t *dst, int dst_linesize, |
478992775cf8
Reimplement ff_img_copy_plane() as av_image_copy_plane() in libavcore,
stefano
parents:
22
diff
changeset
|
143 const uint8_t *src, int src_linesize, |
478992775cf8
Reimplement ff_img_copy_plane() as av_image_copy_plane() in libavcore,
stefano
parents:
22
diff
changeset
|
144 int bytewidth, int height) |
478992775cf8
Reimplement ff_img_copy_plane() as av_image_copy_plane() in libavcore,
stefano
parents:
22
diff
changeset
|
145 { |
478992775cf8
Reimplement ff_img_copy_plane() as av_image_copy_plane() in libavcore,
stefano
parents:
22
diff
changeset
|
146 if (!dst || !src) |
478992775cf8
Reimplement ff_img_copy_plane() as av_image_copy_plane() in libavcore,
stefano
parents:
22
diff
changeset
|
147 return; |
478992775cf8
Reimplement ff_img_copy_plane() as av_image_copy_plane() in libavcore,
stefano
parents:
22
diff
changeset
|
148 for (;height > 0; height--) { |
478992775cf8
Reimplement ff_img_copy_plane() as av_image_copy_plane() in libavcore,
stefano
parents:
22
diff
changeset
|
149 memcpy(dst, src, bytewidth); |
478992775cf8
Reimplement ff_img_copy_plane() as av_image_copy_plane() in libavcore,
stefano
parents:
22
diff
changeset
|
150 dst += dst_linesize; |
478992775cf8
Reimplement ff_img_copy_plane() as av_image_copy_plane() in libavcore,
stefano
parents:
22
diff
changeset
|
151 src += src_linesize; |
478992775cf8
Reimplement ff_img_copy_plane() as av_image_copy_plane() in libavcore,
stefano
parents:
22
diff
changeset
|
152 } |
478992775cf8
Reimplement ff_img_copy_plane() as av_image_copy_plane() in libavcore,
stefano
parents:
22
diff
changeset
|
153 } |
478992775cf8
Reimplement ff_img_copy_plane() as av_image_copy_plane() in libavcore,
stefano
parents:
22
diff
changeset
|
154 |
25
63d8168fa16a
Cosmetics: use plural form for *linesizes arguments of
stefano
parents:
24
diff
changeset
|
155 void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], |
63d8168fa16a
Cosmetics: use plural form for *linesizes arguments of
stefano
parents:
24
diff
changeset
|
156 const uint8_t *src_data[4], const int src_linesizes[4], |
24
c063c88b1309
Move av_picture_data_copy() to libavcore, and rename it
stefano
parents:
23
diff
changeset
|
157 enum PixelFormat pix_fmt, int width, int height) |
c063c88b1309
Move av_picture_data_copy() to libavcore, and rename it
stefano
parents:
23
diff
changeset
|
158 { |
c063c88b1309
Move av_picture_data_copy() to libavcore, and rename it
stefano
parents:
23
diff
changeset
|
159 const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; |
c063c88b1309
Move av_picture_data_copy() to libavcore, and rename it
stefano
parents:
23
diff
changeset
|
160 |
c063c88b1309
Move av_picture_data_copy() to libavcore, and rename it
stefano
parents:
23
diff
changeset
|
161 if (desc->flags & PIX_FMT_HWACCEL) |
c063c88b1309
Move av_picture_data_copy() to libavcore, and rename it
stefano
parents:
23
diff
changeset
|
162 return; |
c063c88b1309
Move av_picture_data_copy() to libavcore, and rename it
stefano
parents:
23
diff
changeset
|
163 |
c063c88b1309
Move av_picture_data_copy() to libavcore, and rename it
stefano
parents:
23
diff
changeset
|
164 if (desc->flags & PIX_FMT_PAL) { |
25
63d8168fa16a
Cosmetics: use plural form for *linesizes arguments of
stefano
parents:
24
diff
changeset
|
165 av_image_copy_plane(dst_data[0], dst_linesizes[0], |
63d8168fa16a
Cosmetics: use plural form for *linesizes arguments of
stefano
parents:
24
diff
changeset
|
166 src_data[0], src_linesizes[0], |
24
c063c88b1309
Move av_picture_data_copy() to libavcore, and rename it
stefano
parents:
23
diff
changeset
|
167 width, height); |
c063c88b1309
Move av_picture_data_copy() to libavcore, and rename it
stefano
parents:
23
diff
changeset
|
168 /* copy the palette */ |
c063c88b1309
Move av_picture_data_copy() to libavcore, and rename it
stefano
parents:
23
diff
changeset
|
169 memcpy(dst_data[1], src_data[1], 4*256); |
c063c88b1309
Move av_picture_data_copy() to libavcore, and rename it
stefano
parents:
23
diff
changeset
|
170 } else { |
c063c88b1309
Move av_picture_data_copy() to libavcore, and rename it
stefano
parents:
23
diff
changeset
|
171 int i, planes_nb = 0; |
c063c88b1309
Move av_picture_data_copy() to libavcore, and rename it
stefano
parents:
23
diff
changeset
|
172 |
c063c88b1309
Move av_picture_data_copy() to libavcore, and rename it
stefano
parents:
23
diff
changeset
|
173 for (i = 0; i < desc->nb_components; i++) |
c063c88b1309
Move av_picture_data_copy() to libavcore, and rename it
stefano
parents:
23
diff
changeset
|
174 planes_nb = FFMAX(planes_nb, desc->comp[i].plane + 1); |
c063c88b1309
Move av_picture_data_copy() to libavcore, and rename it
stefano
parents:
23
diff
changeset
|
175 |
c063c88b1309
Move av_picture_data_copy() to libavcore, and rename it
stefano
parents:
23
diff
changeset
|
176 for (i = 0; i < planes_nb; i++) { |
c063c88b1309
Move av_picture_data_copy() to libavcore, and rename it
stefano
parents:
23
diff
changeset
|
177 int h = height; |
c063c88b1309
Move av_picture_data_copy() to libavcore, and rename it
stefano
parents:
23
diff
changeset
|
178 int bwidth = av_image_get_linesize(pix_fmt, width, i); |
c063c88b1309
Move av_picture_data_copy() to libavcore, and rename it
stefano
parents:
23
diff
changeset
|
179 if (i == 1 || i == 2) { |
c063c88b1309
Move av_picture_data_copy() to libavcore, and rename it
stefano
parents:
23
diff
changeset
|
180 h= -((-height)>>desc->log2_chroma_h); |
c063c88b1309
Move av_picture_data_copy() to libavcore, and rename it
stefano
parents:
23
diff
changeset
|
181 } |
25
63d8168fa16a
Cosmetics: use plural form for *linesizes arguments of
stefano
parents:
24
diff
changeset
|
182 av_image_copy_plane(dst_data[i], dst_linesizes[i], |
63d8168fa16a
Cosmetics: use plural form for *linesizes arguments of
stefano
parents:
24
diff
changeset
|
183 src_data[i], src_linesizes[i], |
24
c063c88b1309
Move av_picture_data_copy() to libavcore, and rename it
stefano
parents:
23
diff
changeset
|
184 bwidth, h); |
c063c88b1309
Move av_picture_data_copy() to libavcore, and rename it
stefano
parents:
23
diff
changeset
|
185 } |
c063c88b1309
Move av_picture_data_copy() to libavcore, and rename it
stefano
parents:
23
diff
changeset
|
186 } |
c063c88b1309
Move av_picture_data_copy() to libavcore, and rename it
stefano
parents:
23
diff
changeset
|
187 } |
c063c88b1309
Move av_picture_data_copy() to libavcore, and rename it
stefano
parents:
23
diff
changeset
|
188 |
22
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
189 #if FF_API_OLD_IMAGE_NAMES |
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
190 void av_fill_image_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4], |
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
191 const AVPixFmtDescriptor *pixdesc) |
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
192 { |
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
193 av_image_fill_max_pixsteps(max_pixsteps, max_pixstep_comps, pixdesc); |
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
194 } |
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
195 |
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
196 int av_get_image_linesize(enum PixelFormat pix_fmt, int width, int plane) |
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
197 { |
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
198 return av_image_get_linesize(pix_fmt, width, plane); |
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
199 } |
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
200 |
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
201 int av_fill_image_linesizes(int linesizes[4], enum PixelFormat pix_fmt, int width) |
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
202 { |
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
203 return av_image_fill_linesizes(linesizes, pix_fmt, width); |
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
204 } |
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
205 |
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
206 int av_fill_image_pointers(uint8_t *data[4], enum PixelFormat pix_fmt, int height, |
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
207 uint8_t *ptr, const int linesizes[4]) |
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
208 { |
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
209 return av_image_fill_pointers(data, pix_fmt, height, ptr, linesizes); |
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
210 } |
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
211 |
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
212 int av_check_image_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx) |
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
213 { |
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
214 return av_image_check_size(w, h, log_offset, log_ctx); |
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
215 } |
0899fc09d43c
Adopt a hierarchical name scheme for the imgutils.h API. Simplify
stefano
parents:
21
diff
changeset
|
216 #endif |