blocktest.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (c) 2025 Michael Niedermayer
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (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 GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "libavutil/frame.h"
  21. #include "libavutil/adler32.h"
  22. #include "libpostproc/postprocess.h"
  23. #include "test_utils.h"
  24. typedef const uint8_t *cuint8;
  25. static void blocks(AVFrame *frame, int blocksize, int mul)
  26. {
  27. for(int y=0; y<frame->height; y++) {
  28. for(int x=0; x<frame->width; x++) {
  29. frame->data[0][x + y*frame->linesize[0]] = x/blocksize*mul + y/blocksize*mul;
  30. }
  31. }
  32. for(int y=0; y<(frame->height+1)/2; y++) {
  33. for(int x=0; x<(frame->width+1)/2; x++) {
  34. frame->data[1][x + y*frame->linesize[1]] = x/blocksize*mul + y/blocksize*mul;
  35. frame->data[2][x + y*frame->linesize[2]] = x/blocksize * (y/blocksize)*mul;
  36. }
  37. }
  38. }
  39. static int64_t test(int width, int height, const char * filter_string, int blocksize, int flags, int pict_type, int quality) {
  40. AVFrame *in = av_frame_alloc();
  41. AVFrame *out = av_frame_alloc();
  42. pp_context *context = pp_get_context(width, height, flags);
  43. pp_mode *mode = pp_get_mode_by_name_and_quality(filter_string, quality);
  44. int64_t ret;
  45. #define QP_STRIDE (352/16)
  46. int8_t qp[QP_STRIDE * 352/16];
  47. if (!in || !out || !context || !mode) {
  48. ret = AVERROR(ENOMEM);
  49. goto end;
  50. }
  51. in-> width = out->width = width;
  52. in->height = out->height = height;
  53. in->format = out->format = AV_PIX_FMT_YUV420P;
  54. ret = av_frame_get_buffer(in, 0);
  55. if (ret < 0)
  56. goto end;
  57. ret = av_frame_get_buffer(out, 0);
  58. if (ret < 0)
  59. goto end;
  60. blocks(in, blocksize, 11);
  61. for(int i= 0; i<sizeof(qp); i++)
  62. qp[i] = i % 31;
  63. pp_postprocess( (cuint8[]){in->data[0], in->data[1], in->data[2]}, in->linesize,
  64. out->data, out->linesize,
  65. width, height, qp, QP_STRIDE,
  66. mode, context, pict_type);
  67. ret = ff_chksum(out);
  68. end:
  69. av_frame_free(&in);
  70. av_frame_free(&out);
  71. pp_free_context(context);
  72. pp_free_mode(mode);
  73. return ret;
  74. }
  75. int main(int argc, char **argv) {
  76. const char *teststrings[] = {
  77. "be,de",
  78. "be,h1,v1",
  79. "be,ha,va",
  80. "be,al,de",
  81. "be,vi,de",
  82. "be,vi,ha,va",
  83. };
  84. for (int w=16; w< 352; w=w*3-16) {
  85. for (int h=16; h< 352; h=h*5-16) {
  86. for (int b=1; b<17; b*=2) {
  87. for (int c=0; c<6; c++) {
  88. for (int q=0; q<17; q = 2*q+1) {
  89. int64_t ret = test(w, h, teststrings[c], b, PP_FORMAT_420, 0, q);
  90. printf("blocktest %dx%d %s b:%d q:%d result %"PRIX64"\n", w, h, teststrings[c], b, q, ret);
  91. }
  92. }
  93. }
  94. }
  95. }
  96. return 0;
  97. }