OLD | NEW |
1 /* | 1 /* |
2 * pixel format descriptor | 2 * pixel format descriptor |
3 * Copyright (c) 2009 Michael Niedermayer <michaelni@gmx.at> | 3 * Copyright (c) 2009 Michael Niedermayer <michaelni@gmx.at> |
4 * | 4 * |
5 * This file is part of FFmpeg. | 5 * This file is part of FFmpeg. |
6 * | 6 * |
7 * FFmpeg is free software; you can redistribute it and/or | 7 * FFmpeg is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Lesser General Public | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2.1 of the License, or (at your option) any later version. | 10 * version 2.1 of the License, or (at your option) any later version. |
11 * | 11 * |
12 * FFmpeg is distributed in the hope that it will be useful, | 12 * FFmpeg is distributed in the hope that it will be useful, |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Lesser General Public License for more details. | 15 * Lesser General Public License for more details. |
16 * | 16 * |
17 * You should have received a copy of the GNU Lesser General Public | 17 * You should have received a copy of the GNU Lesser General Public |
18 * License along with FFmpeg; if not, write to the Free Software | 18 * License along with FFmpeg; if not, write to the Free Software |
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 */ | 20 */ |
21 | 21 |
22 #ifndef AVUTIL_PIXDESC_H | 22 #ifndef AVUTIL_PIXDESC_H |
23 #define AVUTIL_PIXDESC_H | 23 #define AVUTIL_PIXDESC_H |
24 | 24 |
25 #include <inttypes.h> | 25 #include <inttypes.h> |
26 | 26 |
27 #include "intreadwrite.h" | |
28 | |
29 typedef struct AVComponentDescriptor{ | 27 typedef struct AVComponentDescriptor{ |
30 uint16_t plane :2; ///< which of the 4 planes contains the
component | 28 uint16_t plane :2; ///< which of the 4 planes contains the
component |
31 | 29 |
32 /** | 30 /** |
33 * Number of elements between 2 horizontally consecutive pixels minus 1. | 31 * Number of elements between 2 horizontally consecutive pixels minus 1. |
34 * Elements are bits for bitstream formats, bytes otherwise. | 32 * Elements are bits for bitstream formats, bytes otherwise. |
35 */ | 33 */ |
36 uint16_t step_minus1 :3; | 34 uint16_t step_minus1 :3; |
37 | 35 |
38 /** | 36 /** |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 * @param desc the pixel format descriptor for the image | 101 * @param desc the pixel format descriptor for the image |
104 * @param x the horizontal coordinate of the first pixel to read | 102 * @param x the horizontal coordinate of the first pixel to read |
105 * @param y the vertical coordinate of the first pixel to read | 103 * @param y the vertical coordinate of the first pixel to read |
106 * @param w the width of the line to read, that is the number of | 104 * @param w the width of the line to read, that is the number of |
107 * values to write to dst | 105 * values to write to dst |
108 * @param read_pal_component if not zero and the format is a paletted | 106 * @param read_pal_component if not zero and the format is a paletted |
109 * format writes the values corresponding to the palette | 107 * format writes the values corresponding to the palette |
110 * component c in data[1] to dst, rather than the palette indexes in | 108 * component c in data[1] to dst, rather than the palette indexes in |
111 * data[0]. The behavior is undefined if the format is not paletted. | 109 * data[0]. The behavior is undefined if the format is not paletted. |
112 */ | 110 */ |
113 static inline void read_line(uint16_t *dst, const uint8_t *data[4], const int li
nesize[4], | 111 void read_line(uint16_t *dst, const uint8_t *data[4], const int linesize[4], |
114 const AVPixFmtDescriptor *desc, int x, int y, int c
, int w, int read_pal_component) | 112 const AVPixFmtDescriptor *desc, int x, int y, int c, int w, int r
ead_pal_component); |
115 { | |
116 AVComponentDescriptor comp= desc->comp[c]; | |
117 int plane= comp.plane; | |
118 int depth= comp.depth_minus1+1; | |
119 int mask = (1<<depth)-1; | |
120 int shift= comp.shift; | |
121 int step = comp.step_minus1+1; | |
122 int flags= desc->flags; | |
123 | |
124 if (flags & PIX_FMT_BITSTREAM){ | |
125 int skip = x*step + comp.offset_plus1-1; | |
126 const uint8_t *p = data[plane] + y*linesize[plane] + (skip>>3); | |
127 int shift = 8 - depth - (skip&7); | |
128 | |
129 while(w--){ | |
130 int val = (*p >> shift) & mask; | |
131 if(read_pal_component) | |
132 val= data[1][4*val + c]; | |
133 shift -= step; | |
134 p -= shift>>3; | |
135 shift &= 7; | |
136 *dst++= val; | |
137 } | |
138 } else { | |
139 const uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset
_plus1-1; | |
140 | |
141 while(w--){ | |
142 int val; | |
143 if(flags & PIX_FMT_BE) val= AV_RB16(p); | |
144 else val= AV_RL16(p); | |
145 val = (val>>shift) & mask; | |
146 if(read_pal_component) | |
147 val= data[1][4*val + c]; | |
148 p+= step; | |
149 *dst++= val; | |
150 } | |
151 } | |
152 } | |
153 | 113 |
154 /** | 114 /** |
155 * Writes the values from src to the pixel format component c of an | 115 * Writes the values from src to the pixel format component c of an |
156 * image line. | 116 * image line. |
157 * | 117 * |
158 * @param src array containing the values to write | 118 * @param src array containing the values to write |
159 * @param data the array containing the pointers to the planes of the | 119 * @param data the array containing the pointers to the planes of the |
160 * image to write into. It is supposed to be zeroed. | 120 * image to write into. It is supposed to be zeroed. |
161 * @param linesizes the array containing the linesizes of the image | 121 * @param linesizes the array containing the linesizes of the image |
162 * @param desc the pixel format descriptor for the image | 122 * @param desc the pixel format descriptor for the image |
163 * @param x the horizontal coordinate of the first pixel to write | 123 * @param x the horizontal coordinate of the first pixel to write |
164 * @param y the vertical coordinate of the first pixel to write | 124 * @param y the vertical coordinate of the first pixel to write |
165 * @param w the width of the line to write, that is the number of | 125 * @param w the width of the line to write, that is the number of |
166 * values to write to the image line | 126 * values to write to the image line |
167 */ | 127 */ |
168 static inline void write_line(const uint16_t *src, uint8_t *data[4], const int l
inesize[4], | 128 void write_line(const uint16_t *src, uint8_t *data[4], const int linesize[4], |
169 const AVPixFmtDescriptor *desc, int x, int y, int
c, int w) | 129 const AVPixFmtDescriptor *desc, int x, int y, int c, int w); |
170 { | |
171 AVComponentDescriptor comp = desc->comp[c]; | |
172 int plane = comp.plane; | |
173 int depth = comp.depth_minus1+1; | |
174 int step = comp.step_minus1+1; | |
175 int flags = desc->flags; | |
176 | |
177 if (flags & PIX_FMT_BITSTREAM) { | |
178 int skip = x*step + comp.offset_plus1-1; | |
179 uint8_t *p = data[plane] + y*linesize[plane] + (skip>>3); | |
180 int shift = 8 - depth - (skip&7); | |
181 | |
182 while (w--) { | |
183 *p |= *src++ << shift; | |
184 shift -= step; | |
185 p -= shift>>3; | |
186 shift &= 7; | |
187 } | |
188 } else { | |
189 int shift = comp.shift; | |
190 uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1
-1; | |
191 | |
192 while (w--) { | |
193 if (flags & PIX_FMT_BE) { | |
194 uint16_t val = AV_RB16(p) | (*src++<<shift); | |
195 AV_WB16(p, val); | |
196 } else { | |
197 uint16_t val = AV_RL16(p) | (*src++<<shift); | |
198 AV_WL16(p, val); | |
199 } | |
200 p+= step; | |
201 } | |
202 } | |
203 } | |
204 | 130 |
205 /** | 131 /** |
206 * Returns the pixel format corresponding to name. | 132 * Returns the pixel format corresponding to name. |
207 * | 133 * |
208 * If there is no pixel format with name name, then looks for a | 134 * If there is no pixel format with name name, then looks for a |
209 * pixel format with the name corresponding to the native endian | 135 * pixel format with the name corresponding to the native endian |
210 * format of name. | 136 * format of name. |
211 * For example in a little-endian system, first looks for "gray16", | 137 * For example in a little-endian system, first looks for "gray16", |
212 * then for "gray16le". | 138 * then for "gray16le". |
213 * | 139 * |
214 * Finally if no pixel format has been found, returns PIX_FMT_NONE. | 140 * Finally if no pixel format has been found, returns PIX_FMT_NONE. |
215 */ | 141 */ |
216 enum PixelFormat av_get_pix_fmt(const char *name); | 142 enum PixelFormat av_get_pix_fmt(const char *name); |
217 | 143 |
218 /** | 144 /** |
219 * Returns the number of bits per pixel used by the pixel format | 145 * Returns the number of bits per pixel used by the pixel format |
220 * described by pixdesc. | 146 * described by pixdesc. |
221 * | 147 * |
222 * The returned number of bits refers to the number of bits actually | 148 * The returned number of bits refers to the number of bits actually |
223 * used for storing the pixel information, that is padding bits are | 149 * used for storing the pixel information, that is padding bits are |
224 * not counted. | 150 * not counted. |
225 */ | 151 */ |
226 int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc); | 152 int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc); |
227 | 153 |
228 #endif /* AVUTIL_PIXDESC_H */ | 154 #endif /* AVUTIL_PIXDESC_H */ |
OLD | NEW |