OLD | NEW |
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 <math.h> | 11 #include <math.h> |
12 #include <stdarg.h> | 12 #include <stdarg.h> |
13 #include <stdio.h> | 13 #include <stdio.h> |
14 #include <stdlib.h> | 14 #include <stdlib.h> |
15 #include <string.h> | 15 #include <string.h> |
16 | 16 |
17 #include "./tools_common.h" | 17 #include "./tools_common.h" |
18 | 18 |
19 #if CONFIG_VP8_ENCODER || CONFIG_VP9_ENCODER | 19 #if CONFIG_VP8_ENCODER || CONFIG_VP9_ENCODER || CONFIG_VP10_ENCODER |
20 #include "vpx/vp8cx.h" | 20 #include "vpx/vp8cx.h" |
21 #endif | 21 #endif |
22 | 22 |
23 #if CONFIG_VP8_DECODER || CONFIG_VP9_DECODER | 23 #if CONFIG_VP8_DECODER || CONFIG_VP9_DECODER || CONFIG_VP10_DECODER |
24 #include "vpx/vp8dx.h" | 24 #include "vpx/vp8dx.h" |
25 #endif | 25 #endif |
26 | 26 |
27 #if defined(_WIN32) || defined(__OS2__) | 27 #if defined(_WIN32) || defined(__OS2__) |
28 #include <io.h> | 28 #include <io.h> |
29 #include <fcntl.h> | 29 #include <fcntl.h> |
30 | 30 |
31 #ifdef __OS2__ | 31 #ifdef __OS2__ |
32 #define _setmode setmode | 32 #define _setmode setmode |
33 #define _fileno fileno | 33 #define _fileno fileno |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 shortread |= (fread(ptr + buf_position, 1, needed, f) < needed); | 123 shortread |= (fread(ptr + buf_position, 1, needed, f) < needed); |
124 } | 124 } |
125 | 125 |
126 ptr += yuv_frame->stride[plane]; | 126 ptr += yuv_frame->stride[plane]; |
127 } | 127 } |
128 } | 128 } |
129 | 129 |
130 return shortread; | 130 return shortread; |
131 } | 131 } |
132 | 132 |
| 133 #if CONFIG_ENCODERS |
| 134 |
133 static const VpxInterface vpx_encoders[] = { | 135 static const VpxInterface vpx_encoders[] = { |
| 136 #if CONFIG_VP10_ENCODER |
| 137 {"vp10", VP10_FOURCC, &vpx_codec_vp10_cx}, |
| 138 #endif |
| 139 |
134 #if CONFIG_VP8_ENCODER | 140 #if CONFIG_VP8_ENCODER |
135 {"vp8", VP8_FOURCC, &vpx_codec_vp8_cx}, | 141 {"vp8", VP8_FOURCC, &vpx_codec_vp8_cx}, |
136 #endif | 142 #endif |
137 | 143 |
138 #if CONFIG_VP9_ENCODER | 144 #if CONFIG_VP9_ENCODER |
139 {"vp9", VP9_FOURCC, &vpx_codec_vp9_cx}, | 145 {"vp9", VP9_FOURCC, &vpx_codec_vp9_cx}, |
140 #endif | 146 #endif |
141 }; | 147 }; |
142 | 148 |
143 int get_vpx_encoder_count(void) { | 149 int get_vpx_encoder_count(void) { |
144 return sizeof(vpx_encoders) / sizeof(vpx_encoders[0]); | 150 return sizeof(vpx_encoders) / sizeof(vpx_encoders[0]); |
145 } | 151 } |
146 | 152 |
147 const VpxInterface *get_vpx_encoder_by_index(int i) { | 153 const VpxInterface *get_vpx_encoder_by_index(int i) { |
148 return &vpx_encoders[i]; | 154 return &vpx_encoders[i]; |
149 } | 155 } |
150 | 156 |
151 const VpxInterface *get_vpx_encoder_by_name(const char *name) { | 157 const VpxInterface *get_vpx_encoder_by_name(const char *name) { |
152 int i; | 158 int i; |
153 | 159 |
154 for (i = 0; i < get_vpx_encoder_count(); ++i) { | 160 for (i = 0; i < get_vpx_encoder_count(); ++i) { |
155 const VpxInterface *encoder = get_vpx_encoder_by_index(i); | 161 const VpxInterface *encoder = get_vpx_encoder_by_index(i); |
156 if (strcmp(encoder->name, name) == 0) | 162 if (strcmp(encoder->name, name) == 0) |
157 return encoder; | 163 return encoder; |
158 } | 164 } |
159 | 165 |
160 return NULL; | 166 return NULL; |
161 } | 167 } |
162 | 168 |
| 169 #endif // CONFIG_ENCODERS |
| 170 |
| 171 #if CONFIG_DECODERS |
| 172 |
163 static const VpxInterface vpx_decoders[] = { | 173 static const VpxInterface vpx_decoders[] = { |
164 #if CONFIG_VP8_DECODER | 174 #if CONFIG_VP8_DECODER |
165 {"vp8", VP8_FOURCC, &vpx_codec_vp8_dx}, | 175 {"vp8", VP8_FOURCC, &vpx_codec_vp8_dx}, |
166 #endif | 176 #endif |
167 | 177 |
168 #if CONFIG_VP9_DECODER | 178 #if CONFIG_VP9_DECODER |
169 {"vp9", VP9_FOURCC, &vpx_codec_vp9_dx}, | 179 {"vp9", VP9_FOURCC, &vpx_codec_vp9_dx}, |
170 #endif | 180 #endif |
| 181 |
| 182 #if CONFIG_VP10_DECODER |
| 183 {"vp10", VP10_FOURCC, &vpx_codec_vp10_dx}, |
| 184 #endif |
171 }; | 185 }; |
172 | 186 |
173 int get_vpx_decoder_count(void) { | 187 int get_vpx_decoder_count(void) { |
174 return sizeof(vpx_decoders) / sizeof(vpx_decoders[0]); | 188 return sizeof(vpx_decoders) / sizeof(vpx_decoders[0]); |
175 } | 189 } |
176 | 190 |
177 const VpxInterface *get_vpx_decoder_by_index(int i) { | 191 const VpxInterface *get_vpx_decoder_by_index(int i) { |
178 return &vpx_decoders[i]; | 192 return &vpx_decoders[i]; |
179 } | 193 } |
180 | 194 |
(...skipping 14 matching lines...) Expand all Loading... |
195 | 209 |
196 for (i = 0; i < get_vpx_decoder_count(); ++i) { | 210 for (i = 0; i < get_vpx_decoder_count(); ++i) { |
197 const VpxInterface *const decoder = get_vpx_decoder_by_index(i); | 211 const VpxInterface *const decoder = get_vpx_decoder_by_index(i); |
198 if (decoder->fourcc == fourcc) | 212 if (decoder->fourcc == fourcc) |
199 return decoder; | 213 return decoder; |
200 } | 214 } |
201 | 215 |
202 return NULL; | 216 return NULL; |
203 } | 217 } |
204 | 218 |
| 219 #endif // CONFIG_DECODERS |
| 220 |
205 // TODO(dkovalev): move this function to vpx_image.{c, h}, so it will be part | 221 // TODO(dkovalev): move this function to vpx_image.{c, h}, so it will be part |
206 // of vpx_image_t support | 222 // of vpx_image_t support |
207 int vpx_img_plane_width(const vpx_image_t *img, int plane) { | 223 int vpx_img_plane_width(const vpx_image_t *img, int plane) { |
208 if (plane > 0 && img->x_chroma_shift > 0) | 224 if (plane > 0 && img->x_chroma_shift > 0) |
209 return (img->d_w + 1) >> img->x_chroma_shift; | 225 return (img->d_w + 1) >> img->x_chroma_shift; |
210 else | 226 else |
211 return img->d_w; | 227 return img->d_w; |
212 } | 228 } |
213 | 229 |
214 int vpx_img_plane_height(const vpx_image_t *img, int plane) { | 230 int vpx_img_plane_height(const vpx_image_t *img, int plane) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 | 279 |
264 if (sse > 0.0) { | 280 if (sse > 0.0) { |
265 const double psnr = 10.0 * log10(samples * peak * peak / sse); | 281 const double psnr = 10.0 * log10(samples * peak * peak / sse); |
266 return psnr > kMaxPSNR ? kMaxPSNR : psnr; | 282 return psnr > kMaxPSNR ? kMaxPSNR : psnr; |
267 } else { | 283 } else { |
268 return kMaxPSNR; | 284 return kMaxPSNR; |
269 } | 285 } |
270 } | 286 } |
271 | 287 |
272 // TODO(debargha): Consolidate the functions below into a separate file. | 288 // TODO(debargha): Consolidate the functions below into a separate file. |
273 #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH | 289 #if CONFIG_VP9_HIGHBITDEPTH |
274 static void highbd_img_upshift(vpx_image_t *dst, vpx_image_t *src, | 290 static void highbd_img_upshift(vpx_image_t *dst, vpx_image_t *src, |
275 int input_shift) { | 291 int input_shift) { |
276 // Note the offset is 1 less than half. | 292 // Note the offset is 1 less than half. |
277 const int offset = input_shift > 0 ? (1 << (input_shift - 1)) - 1 : 0; | 293 const int offset = input_shift > 0 ? (1 << (input_shift - 1)) - 1 : 0; |
278 int plane; | 294 int plane; |
279 if (dst->d_w != src->d_w || dst->d_h != src->d_h || | 295 if (dst->d_w != src->d_w || dst->d_h != src->d_h || |
280 dst->x_chroma_shift != src->x_chroma_shift || | 296 dst->x_chroma_shift != src->x_chroma_shift || |
281 dst->y_chroma_shift != src->y_chroma_shift || | 297 dst->y_chroma_shift != src->y_chroma_shift || |
282 dst->fmt != src->fmt || input_shift < 0) { | 298 dst->fmt != src->fmt || input_shift < 0) { |
283 fatal("Unsupported image conversion"); | 299 fatal("Unsupported image conversion"); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 } | 492 } |
477 | 493 |
478 void vpx_img_downshift(vpx_image_t *dst, vpx_image_t *src, | 494 void vpx_img_downshift(vpx_image_t *dst, vpx_image_t *src, |
479 int down_shift) { | 495 int down_shift) { |
480 if (dst->fmt & VPX_IMG_FMT_HIGHBITDEPTH) { | 496 if (dst->fmt & VPX_IMG_FMT_HIGHBITDEPTH) { |
481 highbd_img_downshift(dst, src, down_shift); | 497 highbd_img_downshift(dst, src, down_shift); |
482 } else { | 498 } else { |
483 lowbd_img_downshift(dst, src, down_shift); | 499 lowbd_img_downshift(dst, src, down_shift); |
484 } | 500 } |
485 } | 501 } |
486 #endif // CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH | 502 #endif // CONFIG_VP9_HIGHBITDEPTH |
OLD | NEW |