huffyuvdsp.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (c) 2016 Alexandra Hájková
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. */
  20. #include <string.h>
  21. #include "libavutil/common.h"
  22. #include "libavutil/intreadwrite.h"
  23. #include "libavutil/mem.h"
  24. #include "libavcodec/huffyuvdsp.h"
  25. #include "checkasm.h"
  26. #define randomize_buffers(buf, size) \
  27. do { \
  28. int j; \
  29. for (j = 0; j < size; j++) \
  30. buf[j] = rnd() & 0xFFFF; \
  31. } while (0)
  32. static void check_add_int16(HuffYUVDSPContext *c, unsigned mask, int width, const char * name)
  33. {
  34. uint16_t *src0 = av_mallocz(width * sizeof(uint16_t));
  35. uint16_t *src1 = av_mallocz(width * sizeof(uint16_t));
  36. uint16_t *dst0 = av_mallocz(width * sizeof(uint16_t));
  37. uint16_t *dst1 = av_mallocz(width * sizeof(uint16_t));
  38. declare_func(void, uint16_t *dst, const uint16_t *src, unsigned mask, int w);
  39. if (!src0 || !src1 || !dst0 || !dst1)
  40. fail();
  41. randomize_buffers(src0, width);
  42. memcpy(src1, src0, width * sizeof(uint16_t));
  43. if (check_func(c->add_int16, "%s", name)) {
  44. call_ref(dst0, src0, mask, width);
  45. call_new(dst1, src1, mask, width);
  46. if (memcmp(dst0, dst1, width * sizeof(uint16_t)))
  47. fail();
  48. bench_new(dst1, src1, mask, width);
  49. }
  50. av_free(src0);
  51. av_free(src1);
  52. av_free(dst0);
  53. av_free(dst1);
  54. }
  55. static void check_add_hfyu_left_pred_bgr32(HuffYUVDSPContext *c)
  56. {
  57. #define BUF_SIZE 1080
  58. uint8_t src[4 * BUF_SIZE], dst0[4 * BUF_SIZE], dst1[4 * BUF_SIZE];
  59. uint8_t left[4], left0[4], left1[4];
  60. declare_func(void, uint8_t *d, const uint8_t *s, intptr_t w, uint8_t *l);
  61. randomize_buffers(src, sizeof (src));
  62. randomize_buffers(left, sizeof (left));
  63. memcpy(left0, left, sizeof (left));
  64. memcpy(left1, left, sizeof (left));
  65. if (check_func(c->add_hfyu_left_pred_bgr32, "add_hfyu_left_pred_bgr32")) {
  66. call_ref(dst0, src, BUF_SIZE, left0);
  67. call_new(dst1, src, BUF_SIZE, left1);
  68. if (memcmp(dst0, dst1, sizeof (dst0)) != 0 ||
  69. memcmp(left0, left1, sizeof (left0)) != 0) {
  70. fail();
  71. }
  72. bench_new(dst1, src, BUF_SIZE, left);
  73. }
  74. report("add_hfyu_left_pred_bgr32");
  75. }
  76. void checkasm_check_huffyuvdsp(void)
  77. {
  78. HuffYUVDSPContext c;
  79. int width = 16 * av_clip(rnd(), 16, 128);
  80. ff_huffyuvdsp_init(&c, AV_PIX_FMT_YUV422P);
  81. /*! test width not multiple of mmsize */
  82. check_add_int16(&c, 65535, width, "add_int16_rnd_width");
  83. report("add_int16_rnd_width");
  84. /*! test always with the same size (for perf test) */
  85. check_add_int16(&c, 65535, 16*128, "add_int16_128");
  86. report("add_int16_128");
  87. check_add_hfyu_left_pred_bgr32(&c);
  88. }