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

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

Issue 668403002: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 1 month 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/vp8/common/arm/neon/loopfilter_neon.c » ('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
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 else 217 else
218 return img->d_h; 218 return img->d_h;
219 } 219 }
220 220
221 void vpx_img_write(const vpx_image_t *img, FILE *file) { 221 void vpx_img_write(const vpx_image_t *img, FILE *file) {
222 int plane; 222 int plane;
223 223
224 for (plane = 0; plane < 3; ++plane) { 224 for (plane = 0; plane < 3; ++plane) {
225 const unsigned char *buf = img->planes[plane]; 225 const unsigned char *buf = img->planes[plane];
226 const int stride = img->stride[plane]; 226 const int stride = img->stride[plane];
227 const int w = vpx_img_plane_width(img, plane); 227 const int w = vpx_img_plane_width(img, plane) *
228 ((img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 2 : 1);
228 const int h = vpx_img_plane_height(img, plane); 229 const int h = vpx_img_plane_height(img, plane);
229 int y; 230 int y;
230 231
231 for (y = 0; y < h; ++y) { 232 for (y = 0; y < h; ++y) {
232 fwrite(buf, 1, w, file); 233 fwrite(buf, 1, w, file);
233 buf += stride; 234 buf += stride;
234 } 235 }
235 } 236 }
236 } 237 }
237 238
(...skipping 22 matching lines...) Expand all
260 double sse_to_psnr(double samples, double peak, double sse) { 261 double sse_to_psnr(double samples, double peak, double sse) {
261 static const double kMaxPSNR = 100.0; 262 static const double kMaxPSNR = 100.0;
262 263
263 if (sse > 0.0) { 264 if (sse > 0.0) {
264 const double psnr = 10.0 * log10(samples * peak * peak / sse); 265 const double psnr = 10.0 * log10(samples * peak * peak / sse);
265 return psnr > kMaxPSNR ? kMaxPSNR : psnr; 266 return psnr > kMaxPSNR ? kMaxPSNR : psnr;
266 } else { 267 } else {
267 return kMaxPSNR; 268 return kMaxPSNR;
268 } 269 }
269 } 270 }
271
272 // TODO(debargha): Consolidate the functions below into a separate file.
273 #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
274 static void highbd_img_upshift(vpx_image_t *dst, vpx_image_t *src,
275 int input_shift) {
276 // Note the offset is 1 less than half.
277 const int offset = input_shift > 0 ? (1 << (input_shift - 1)) - 1 : 0;
278 int plane;
279 if (dst->d_w != src->d_w || dst->d_h != src->d_h ||
280 dst->x_chroma_shift != src->x_chroma_shift ||
281 dst->y_chroma_shift != src->y_chroma_shift ||
282 dst->fmt != src->fmt || input_shift < 0) {
283 fatal("Unsupported image conversion");
284 }
285 switch (src->fmt) {
286 case VPX_IMG_FMT_I42016:
287 case VPX_IMG_FMT_I42216:
288 case VPX_IMG_FMT_I44416:
289 case VPX_IMG_FMT_I44016:
290 break;
291 default:
292 fatal("Unsupported image conversion");
293 break;
294 }
295 for (plane = 0; plane < 3; plane++) {
296 int w = src->d_w;
297 int h = src->d_h;
298 int x, y;
299 if (plane) {
300 w = (w + src->x_chroma_shift) >> src->x_chroma_shift;
301 h = (h + src->y_chroma_shift) >> src->y_chroma_shift;
302 }
303 for (y = 0; y < h; y++) {
304 uint16_t *p_src =
305 (uint16_t *)(src->planes[plane] + y * src->stride[plane]);
306 uint16_t *p_dst =
307 (uint16_t *)(dst->planes[plane] + y * dst->stride[plane]);
308 for (x = 0; x < w; x++)
309 *p_dst++ = (*p_src++ << input_shift) + offset;
310 }
311 }
312 }
313
314 static void lowbd_img_upshift(vpx_image_t *dst, vpx_image_t *src,
315 int input_shift) {
316 // Note the offset is 1 less than half.
317 const int offset = input_shift > 0 ? (1 << (input_shift - 1)) - 1 : 0;
318 int plane;
319 if (dst->d_w != src->d_w || dst->d_h != src->d_h ||
320 dst->x_chroma_shift != src->x_chroma_shift ||
321 dst->y_chroma_shift != src->y_chroma_shift ||
322 dst->fmt != src->fmt + VPX_IMG_FMT_HIGHBITDEPTH ||
323 input_shift < 0) {
324 fatal("Unsupported image conversion");
325 }
326 switch (src->fmt) {
327 case VPX_IMG_FMT_I420:
328 case VPX_IMG_FMT_I422:
329 case VPX_IMG_FMT_I444:
330 case VPX_IMG_FMT_I440:
331 break;
332 default:
333 fatal("Unsupported image conversion");
334 break;
335 }
336 for (plane = 0; plane < 3; plane++) {
337 int w = src->d_w;
338 int h = src->d_h;
339 int x, y;
340 if (plane) {
341 w = (w + src->x_chroma_shift) >> src->x_chroma_shift;
342 h = (h + src->y_chroma_shift) >> src->y_chroma_shift;
343 }
344 for (y = 0; y < h; y++) {
345 uint8_t *p_src = src->planes[plane] + y * src->stride[plane];
346 uint16_t *p_dst =
347 (uint16_t *)(dst->planes[plane] + y * dst->stride[plane]);
348 for (x = 0; x < w; x++) {
349 *p_dst++ = (*p_src++ << input_shift) + offset;
350 }
351 }
352 }
353 }
354
355 void vpx_img_upshift(vpx_image_t *dst, vpx_image_t *src,
356 int input_shift) {
357 if (src->fmt & VPX_IMG_FMT_HIGHBITDEPTH) {
358 highbd_img_upshift(dst, src, input_shift);
359 } else {
360 lowbd_img_upshift(dst, src, input_shift);
361 }
362 }
363
364 void vpx_img_truncate_16_to_8(vpx_image_t *dst, vpx_image_t *src) {
365 int plane;
366 if (dst->fmt + VPX_IMG_FMT_HIGHBITDEPTH != src->fmt ||
367 dst->d_w != src->d_w || dst->d_h != src->d_h ||
368 dst->x_chroma_shift != src->x_chroma_shift ||
369 dst->y_chroma_shift != src->y_chroma_shift) {
370 fatal("Unsupported image conversion");
371 }
372 switch (dst->fmt) {
373 case VPX_IMG_FMT_I420:
374 case VPX_IMG_FMT_I422:
375 case VPX_IMG_FMT_I444:
376 case VPX_IMG_FMT_I440:
377 break;
378 default:
379 fatal("Unsupported image conversion");
380 break;
381 }
382 for (plane = 0; plane < 3; plane++) {
383 int w = src->d_w;
384 int h = src->d_h;
385 int x, y;
386 if (plane) {
387 w = (w + src->x_chroma_shift) >> src->x_chroma_shift;
388 h = (h + src->y_chroma_shift) >> src->y_chroma_shift;
389 }
390 for (y = 0; y < h; y++) {
391 uint16_t *p_src =
392 (uint16_t *)(src->planes[plane] + y * src->stride[plane]);
393 uint8_t *p_dst = dst->planes[plane] + y * dst->stride[plane];
394 for (x = 0; x < w; x++) {
395 *p_dst++ = *p_src++;
396 }
397 }
398 }
399 }
400
401 static void highbd_img_downshift(vpx_image_t *dst, vpx_image_t *src,
402 int down_shift) {
403 int plane;
404 if (dst->d_w != src->d_w || dst->d_h != src->d_h ||
405 dst->x_chroma_shift != src->x_chroma_shift ||
406 dst->y_chroma_shift != src->y_chroma_shift ||
407 dst->fmt != src->fmt || down_shift < 0) {
408 fatal("Unsupported image conversion");
409 }
410 switch (src->fmt) {
411 case VPX_IMG_FMT_I42016:
412 case VPX_IMG_FMT_I42216:
413 case VPX_IMG_FMT_I44416:
414 case VPX_IMG_FMT_I44016:
415 break;
416 default:
417 fatal("Unsupported image conversion");
418 break;
419 }
420 for (plane = 0; plane < 3; plane++) {
421 int w = src->d_w;
422 int h = src->d_h;
423 int x, y;
424 if (plane) {
425 w = (w + src->x_chroma_shift) >> src->x_chroma_shift;
426 h = (h + src->y_chroma_shift) >> src->y_chroma_shift;
427 }
428 for (y = 0; y < h; y++) {
429 uint16_t *p_src =
430 (uint16_t *)(src->planes[plane] + y * src->stride[plane]);
431 uint16_t *p_dst =
432 (uint16_t *)(dst->planes[plane] + y * dst->stride[plane]);
433 for (x = 0; x < w; x++)
434 *p_dst++ = *p_src++ >> down_shift;
435 }
436 }
437 }
438
439 static void lowbd_img_downshift(vpx_image_t *dst, vpx_image_t *src,
440 int down_shift) {
441 int plane;
442 if (dst->d_w != src->d_w || dst->d_h != src->d_h ||
443 dst->x_chroma_shift != src->x_chroma_shift ||
444 dst->y_chroma_shift != src->y_chroma_shift ||
445 src->fmt != dst->fmt + VPX_IMG_FMT_HIGHBITDEPTH ||
446 down_shift < 0) {
447 fatal("Unsupported image conversion");
448 }
449 switch (dst->fmt) {
450 case VPX_IMG_FMT_I420:
451 case VPX_IMG_FMT_I422:
452 case VPX_IMG_FMT_I444:
453 case VPX_IMG_FMT_I440:
454 break;
455 default:
456 fatal("Unsupported image conversion");
457 break;
458 }
459 for (plane = 0; plane < 3; plane++) {
460 int w = src->d_w;
461 int h = src->d_h;
462 int x, y;
463 if (plane) {
464 w = (w + src->x_chroma_shift) >> src->x_chroma_shift;
465 h = (h + src->y_chroma_shift) >> src->y_chroma_shift;
466 }
467 for (y = 0; y < h; y++) {
468 uint16_t *p_src =
469 (uint16_t *)(src->planes[plane] + y * src->stride[plane]);
470 uint8_t *p_dst = dst->planes[plane] + y * dst->stride[plane];
471 for (x = 0; x < w; x++) {
472 *p_dst++ = *p_src++ >> down_shift;
473 }
474 }
475 }
476 }
477
478 void vpx_img_downshift(vpx_image_t *dst, vpx_image_t *src,
479 int down_shift) {
480 if (dst->fmt & VPX_IMG_FMT_HIGHBITDEPTH) {
481 highbd_img_downshift(dst, src, down_shift);
482 } else {
483 lowbd_img_downshift(dst, src, down_shift);
484 }
485 }
486 #endif // CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
OLDNEW
« no previous file with comments | « source/libvpx/tools_common.h ('k') | source/libvpx/vp8/common/arm/neon/loopfilter_neon.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698