h264chroma.c 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (c) Lynne
  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 <stdint.h>
  22. #include "checkasm.h"
  23. #include "libavcodec/h264chroma.h"
  24. #include "libavutil/mem_internal.h"
  25. #include "libavutil/intreadwrite.h"
  26. #define SIZEOF_PIXEL ((bit_depth + 7) / 8)
  27. #define randomize_buffers(bit_depth) \
  28. do { \
  29. if (bit_depth == 8) { \
  30. for (int i = 0; i < 16*18*2; i++) \
  31. src[i] = rnd() & 0x3; \
  32. } else { \
  33. for (int i = 0; i < 16*18; i += 2) \
  34. AV_WN16(&src[i], rnd() & 0xFF); \
  35. } \
  36. } while (0)
  37. static void check_chroma_mc(void)
  38. {
  39. H264ChromaContext h;
  40. LOCAL_ALIGNED_32(uint8_t, src, [16 * 18 * 2]);
  41. LOCAL_ALIGNED_32(uint8_t, dst0, [16 * 18 * 2]);
  42. LOCAL_ALIGNED_32(uint8_t, dst1, [16 * 18 * 2]);
  43. declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, const uint8_t *src,
  44. ptrdiff_t stride, int h, int x, int y);
  45. for (int bit_depth = 8; bit_depth <= 10; bit_depth++) {
  46. ff_h264chroma_init(&h, bit_depth);
  47. randomize_buffers(bit_depth);
  48. for (int size = 0; size < 4; size++) {
  49. #define CHECK_CHROMA_MC(name) \
  50. do { \
  51. if (check_func(h.name## _pixels_tab[size], #name "_mc%d_%d", 1 << (3-size), bit_depth)) { \
  52. for (int x = 0; x < 2; x++) { \
  53. for (int y = 0; y < 2; y++) { \
  54. memcpy(dst0, src, 16 * 18 * SIZEOF_PIXEL); \
  55. memcpy(dst1, src, 16 * 18 * SIZEOF_PIXEL); \
  56. call_ref(dst0, src, 16 * SIZEOF_PIXEL, 16, x, y); \
  57. call_new(dst1, src, 16 * SIZEOF_PIXEL, 16, x, y); \
  58. if (memcmp(dst0, dst1, 16 * 16 * SIZEOF_PIXEL)) { \
  59. fprintf(stderr, #name ": x:%i, y:%i\n", x, y); \
  60. fail(); \
  61. } \
  62. bench_new(dst1, src, 16 * SIZEOF_PIXEL, 16, x, y); \
  63. } \
  64. } \
  65. } \
  66. } while (0)
  67. CHECK_CHROMA_MC(put_h264_chroma);
  68. CHECK_CHROMA_MC(avg_h264_chroma);
  69. }
  70. }
  71. }
  72. void checkasm_check_h264chroma(void)
  73. {
  74. check_chroma_mc();
  75. report("chroma_mc");
  76. }