Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Side by Side Diff: source/libvpx/tools_common.c

Issue 168343002: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: libvpx: Pull from upstream Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/tools_common.h ('k') | source/libvpx/video_common.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "tools_common.h" 11 #include "tools_common.h"
12 12
13 #include <stdarg.h> 13 #include <stdarg.h>
14 #include <stdio.h> 14 #include <stdio.h>
15 #include <stdlib.h> 15 #include <stdlib.h>
16 #include <string.h> 16 #include <string.h>
17 17
18 #if CONFIG_VP8_ENCODER || CONFIG_VP9_ENCODER
19 #include "vpx/vp8cx.h"
20 #endif
21
18 #if CONFIG_VP8_DECODER || CONFIG_VP9_DECODER 22 #if CONFIG_VP8_DECODER || CONFIG_VP9_DECODER
19 #include "vpx/vp8dx.h" 23 #include "vpx/vp8dx.h"
20 #endif 24 #endif
21 25
22 #if defined(_WIN32) || defined(__OS2__) 26 #if defined(_WIN32) || defined(__OS2__)
23 #include <io.h> 27 #include <io.h>
24 #include <fcntl.h> 28 #include <fcntl.h>
25 29
26 #ifdef __OS2__ 30 #ifdef __OS2__
27 #define _setmode setmode 31 #define _setmode setmode
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 shortread |= (fread(ptr + buf_position, 1, needed, f) < needed); 141 shortread |= (fread(ptr + buf_position, 1, needed, f) < needed);
138 } 142 }
139 143
140 ptr += yuv_frame->stride[plane]; 144 ptr += yuv_frame->stride[plane];
141 } 145 }
142 } 146 }
143 147
144 return shortread; 148 return shortread;
145 } 149 }
146 150
147 vpx_codec_iface_t *get_codec_interface(unsigned int fourcc) { 151 static const VpxInterface vpx_encoders[] = {
148 switch (fourcc) { 152 #if CONFIG_VP8_ENCODER
149 #if CONFIG_VP8_DECODER 153 {"vp8", VP8_FOURCC, &vpx_codec_vp8_cx},
150 case VP8_FOURCC:
151 return vpx_codec_vp8_dx();
152 #endif 154 #endif
153 #if CONFIG_VP9_DECODER 155
154 case VP9_FOURCC: 156 #if CONFIG_VP9_ENCODER
155 return vpx_codec_vp9_dx(); 157 {"vp9", VP9_FOURCC, &vpx_codec_vp9_cx},
156 #endif 158 #endif
157 default: 159 };
158 return NULL; 160
161 int get_vpx_encoder_count() {
162 return sizeof(vpx_encoders) / sizeof(vpx_encoders[0]);
163 }
164
165 const VpxInterface *get_vpx_encoder_by_index(int i) {
166 return &vpx_encoders[i];
167 }
168
169 const VpxInterface *get_vpx_encoder_by_name(const char *name) {
170 int i;
171
172 for (i = 0; i < get_vpx_encoder_count(); ++i) {
173 const VpxInterface *encoder = get_vpx_encoder_by_index(i);
174 if (strcmp(encoder->name, name) == 0)
175 return encoder;
159 } 176 }
177
160 return NULL; 178 return NULL;
161 } 179 }
162 180
181 static const VpxInterface vpx_decoders[] = {
182 #if CONFIG_VP8_DECODER
183 {"vp8", VP8_FOURCC, &vpx_codec_vp8_dx},
184 #endif
185
186 #if CONFIG_VP9_DECODER
187 {"vp9", VP9_FOURCC, &vpx_codec_vp9_dx},
188 #endif
189 };
190
191 int get_vpx_decoder_count() {
192 return sizeof(vpx_decoders) / sizeof(vpx_decoders[0]);
193 }
194
195 const VpxInterface *get_vpx_decoder_by_index(int i) {
196 return &vpx_decoders[i];
197 }
198
199 const VpxInterface *get_vpx_decoder_by_name(const char *name) {
200 int i;
201
202 for (i = 0; i < get_vpx_decoder_count(); ++i) {
203 const VpxInterface *const decoder = get_vpx_decoder_by_index(i);
204 if (strcmp(decoder->name, name) == 0)
205 return decoder;
206 }
207
208 return NULL;
209 }
210
211 const VpxInterface *get_vpx_decoder_by_fourcc(uint32_t fourcc) {
212 int i;
213
214 for (i = 0; i < get_vpx_decoder_count(); ++i) {
215 const VpxInterface *const decoder = get_vpx_decoder_by_index(i);
216 if (decoder->fourcc == fourcc)
217 return decoder;
218 }
219
220 return NULL;
221 }
222
223 // TODO(dkovalev): move this function to vpx_image.{c, h}, so it will be part
224 // of vpx_image_t support
225 int vpx_img_plane_width(const vpx_image_t *img, int plane) {
226 if (plane > 0 && img->x_chroma_shift > 0)
227 return (img->d_w + 1) >> img->x_chroma_shift;
228 else
229 return img->d_w;
230 }
231
232 int vpx_img_plane_height(const vpx_image_t *img, int plane) {
233 if (plane > 0 && img->y_chroma_shift > 0)
234 return (img->d_h + 1) >> img->y_chroma_shift;
235 else
236 return img->d_h;
237 }
238
163 void vpx_img_write(const vpx_image_t *img, FILE *file) { 239 void vpx_img_write(const vpx_image_t *img, FILE *file) {
164 int plane, y; 240 int plane;
165 241
166 for (plane = 0; plane < 3; ++plane) { 242 for (plane = 0; plane < 3; ++plane) {
167 const unsigned char *buf = img->planes[plane]; 243 const unsigned char *buf = img->planes[plane];
168 const int stride = img->stride[plane]; 244 const int stride = img->stride[plane];
169 const int w = plane ? (img->d_w + 1) >> 1 : img->d_w; 245 const int w = vpx_img_plane_width(img, plane);
170 const int h = plane ? (img->d_h + 1) >> 1 : img->d_h; 246 const int h = vpx_img_plane_height(img, plane);
247 int y;
248
171 for (y = 0; y < h; ++y) { 249 for (y = 0; y < h; ++y) {
172 fwrite(buf, 1, w, file); 250 fwrite(buf, 1, w, file);
173 buf += stride; 251 buf += stride;
174 } 252 }
175 } 253 }
176 } 254 }
255
256 int vpx_img_read(vpx_image_t *img, FILE *file) {
257 int plane;
258
259 for (plane = 0; plane < 3; ++plane) {
260 unsigned char *buf = img->planes[plane];
261 const int stride = img->stride[plane];
262 const int w = vpx_img_plane_width(img, plane);
263 const int h = vpx_img_plane_height(img, plane);
264 int y;
265
266 for (y = 0; y < h; ++y) {
267 if (fread(buf, 1, w, file) != w)
268 return 0;
269 buf += stride;
270 }
271 }
272
273 return 1;
274 }
275
OLDNEW
« no previous file with comments | « source/libvpx/tools_common.h ('k') | source/libvpx/video_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698