You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.9KB

  1. /*
  2. * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. *
  18. */
  19. #include <stdio.h>
  20. #include <inttypes.h>
  21. #define F 100
  22. #define SIZE 2048
  23. static uint64_t int_sqrt(uint64_t a)
  24. {
  25. uint64_t ret=0;
  26. int s;
  27. uint64_t ret_sq=0;
  28. for(s=31; s>=0; s--){
  29. uint64_t b= ret_sq + (1ULL<<(s*2)) + (ret<<s)*2;
  30. if(b<=a){
  31. ret_sq=b;
  32. ret+= 1ULL<<s;
  33. }
  34. }
  35. return ret;
  36. }
  37. int main(int argc,char* argv[]){
  38. int i, j;
  39. uint64_t sse=0;
  40. uint64_t dev;
  41. FILE *f[2];
  42. uint8_t buf[2][SIZE];
  43. if(argc!=3){
  44. printf("tiny_psnr <file1> <file2>\n");
  45. return -1;
  46. }
  47. f[0]= fopen(argv[1], "r");
  48. f[1]= fopen(argv[2], "r");
  49. for(i=0;;){
  50. if( fread(buf[0], SIZE, 1, f[0]) != 1) break;
  51. if( fread(buf[1], SIZE, 1, f[1]) != 1) break;
  52. for(j=0; j<SIZE; i++,j++){
  53. const int a= buf[0][j];
  54. const int b= buf[1][j];
  55. sse += (a-b) * (a-b);
  56. }
  57. }
  58. dev= int_sqrt((sse*F*F)/i);
  59. //FIXME someone should write a integer fixpoint log() function for bitexact PSNR scores ...
  60. printf("stddev:%3d.%02d bytes:%d\n", (int)(dev/F), (int)(dev%F), i);
  61. return 0;
  62. }