Mercurial > libavcore.hg
annotate imgutils.c @ 16:1a1faa090ff1 libavcore
Implement inline function av_fill_image_max_pixstep() and use it for
factorizing code.
author | stefano |
---|---|
date | Wed, 18 Aug 2010 21:02:38 +0000 |
parents | 665cb0c97133 |
children | ebe3b7ce4cca |
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 |
15 | 27 int av_get_image_linesize(enum PixelFormat pix_fmt, int width, int plane) |
28 { | |
29 const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; | |
30 int max_step [4]; /* max pixel step for each plane */ | |
31 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
|
32 int s; |
15 | 33 |
34 if (desc->flags & PIX_FMT_BITSTREAM) | |
35 return (width * (desc->comp[0].step_minus1+1) + 7) >> 3; | |
36 | |
16
1a1faa090ff1
Implement inline function av_fill_image_max_pixstep() and use it for
stefano
parents:
15
diff
changeset
|
37 av_fill_image_max_pixstep(max_step, max_step_comp, desc); |
15 | 38 s = (max_step_comp[plane] == 1 || max_step_comp[plane] == 2) ? desc->log2_chroma_w : 0; |
39 return max_step[plane] * (((width + (1 << s) - 1)) >> s); | |
40 } | |
41 | |
12
c37229a98056
Rename the av_fill_image_linesize() formal parameter linesize to
stefano
parents:
11
diff
changeset
|
42 int av_fill_image_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
|
43 { |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
44 int i; |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
45 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
|
46 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
|
47 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
|
48 |
12
c37229a98056
Rename the av_fill_image_linesize() formal parameter linesize to
stefano
parents:
11
diff
changeset
|
49 memset(linesizes, 0, 4*sizeof(linesizes[0])); |
8
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
50 |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
51 if (desc->flags & PIX_FMT_HWACCEL) |
10
356600e12af7
Make av_fill_image_linesizes() return a meaningful error core rather
stefano
parents:
9
diff
changeset
|
52 return AVERROR(EINVAL); |
8
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
53 |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
54 if (desc->flags & PIX_FMT_BITSTREAM) { |
12
c37229a98056
Rename the av_fill_image_linesize() formal parameter linesize to
stefano
parents:
11
diff
changeset
|
55 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
|
56 return 0; |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
57 } |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
58 |
16
1a1faa090ff1
Implement inline function av_fill_image_max_pixstep() and use it for
stefano
parents:
15
diff
changeset
|
59 av_fill_image_max_pixstep(max_step, max_step_comp, desc); |
8
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
60 for (i = 0; i < 4; i++) { |
9
4cecefd36670
Rename av_fill_image_linesizes() internal variables max_plane_step and
stefano
parents:
8
diff
changeset
|
61 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
|
62 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
|
63 } |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
64 |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
65 return 0; |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
66 } |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
67 |
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
68 int av_fill_image_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
|
69 uint8_t *ptr, const int linesizes[4]) |
8
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
70 { |
11
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
71 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
|
72 |
8
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
73 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
|
74 memset(data , 0, sizeof(data[0])*4); |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
75 memset(size , 0, sizeof(size)); |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
76 memset(has_plane, 0, sizeof(has_plane)); |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
77 |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
78 if (desc->flags & PIX_FMT_HWACCEL) |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
79 return AVERROR(EINVAL); |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
80 |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
81 data[0] = ptr; |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
82 size[0] = linesizes[0] * height; |
8
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
83 |
11
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
84 if (desc->flags & PIX_FMT_PAL) { |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
85 size[0] = (size[0] + 3) & ~3; |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
86 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
|
87 return size[0] + 256 * 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 |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
90 for (i = 0; i < 4; i++) |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
91 has_plane[desc->comp[i].plane] = 1; |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
92 |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
93 total_size = size[0]; |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
94 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
|
95 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
|
96 data[i] = data[i-1] + size[i-1]; |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
97 h = (height + (1 << s) - 1) >> s; |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
98 size[i] = h * linesizes[i]; |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
99 total_size += size[i]; |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
100 } |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
101 |
dabaa2056109
Reimplement av_fill_image_pointers() using the information stored in
stefano
parents:
10
diff
changeset
|
102 return total_size; |
8
f214f755f5de
Move fill_image_linesize() and fill_image_data_ptr() from
stefano
parents:
diff
changeset
|
103 } |
13
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
104 |
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
105 typedef struct ImgUtils { |
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
106 const AVClass *class; |
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
107 int log_offset; |
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
108 void *log_ctx; |
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
109 } ImgUtils; |
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
110 |
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
111 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
|
112 |
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
113 int av_check_image_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx) |
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
114 { |
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
115 ImgUtils imgutils = { &imgutils_class, log_offset, log_ctx }; |
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
116 |
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
117 if((int)w>0 && (int)h>0 && (w+128)*(uint64_t)(h+128) < INT_MAX/8) |
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
118 return 0; |
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
119 |
14 | 120 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
|
121 return AVERROR(EINVAL); |
97c3fe501477
Deprecate avcodec_check_dimensions() in favor of the new function
stefano
parents:
12
diff
changeset
|
122 } |