stripetest.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 strips(AVFrame *frame, int mul)
  26. {
  27. for(int y=0; y<frame->height; y++) {
  28. for(int x=0; x<frame->width; x++) {
  29. if (y&1) {
  30. frame->data[0][x + y*frame->linesize[0]] = x*x + y*mul;
  31. } else {
  32. frame->data[0][x + y*frame->linesize[0]] = (y-x)*(y-x);
  33. }
  34. }
  35. }
  36. for(int y=0; y<(frame->height+1)/2; y++) {
  37. for(int x=0; x<(frame->width+1)/2; x++) {
  38. if (y&1) {
  39. frame->data[1][x + y*frame->linesize[1]] = x + y + mul;
  40. frame->data[2][x + y*frame->linesize[2]] = mul*x - y*x;
  41. } else {
  42. frame->data[1][x + y*frame->linesize[1]] = (x - y)/(mul+1);
  43. frame->data[2][x + y*frame->linesize[2]] = (y + x)/(mul+1);
  44. }
  45. }
  46. }
  47. }
  48. static int64_t test(int width, int height, const char *testname, int mul, int flags, int pict_type, int quality) {
  49. AVFrame *in = av_frame_alloc();
  50. AVFrame *out = av_frame_alloc();
  51. pp_context *context = pp_get_context(width, height, flags);
  52. pp_mode *mode = pp_get_mode_by_name_and_quality(testname, quality);
  53. int64_t ret;
  54. if (!in || !out || !context || !mode) {
  55. ret = AVERROR(ENOMEM);
  56. goto end;
  57. }
  58. in-> width = out->width = width;
  59. in->height = out->height = height;
  60. in->format = out->format = AV_PIX_FMT_YUV420P;
  61. ret = av_frame_get_buffer(in, 0);
  62. if (ret < 0)
  63. goto end;
  64. ret = av_frame_get_buffer(out, 0);
  65. if (ret < 0)
  66. goto end;
  67. strips(in, mul);
  68. pp_postprocess( (cuint8[]){in->data[0], in->data[1], in->data[2]}, in->linesize,
  69. out->data, out->linesize,
  70. width, height, NULL, 0,
  71. mode, context, pict_type);
  72. ret = ff_chksum(out);
  73. end:
  74. av_frame_free(&in);
  75. av_frame_free(&out);
  76. pp_free_context(context);
  77. pp_free_mode(mode);
  78. return ret;
  79. }
  80. int main(int argc, char **argv) {
  81. const char *teststrings[] = {
  82. "be,lb",
  83. "be,li",
  84. "be,ci",
  85. "be,md",
  86. "be,fd",
  87. "be,l5",
  88. };
  89. for (int w=16; w< 352; w=w*3-16) {
  90. for (int h=16; h< 352; h=h*5-16) {
  91. for (int b=0; b<6; b++) {
  92. for (int m=0; m<17; m = 2*m+1) {
  93. int64_t ret = test(w, h, teststrings[b], m, PP_FORMAT_420, 0, 11);
  94. printf("striptest %dx%d T:%s m:%d result %"PRIX64"\n", w, h, teststrings[b], m, ret);
  95. }
  96. }
  97. }
  98. }
  99. return 0;
  100. }