Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

histogram.c 1.0 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "config.h"
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <pipi.h>
  6. int main(int argc, char *argv[])
  7. {
  8. char *srcname = NULL, *dstname = NULL;
  9. pipi_image_t *img, *newimg, *tmp;
  10. pipi_histogram_t* histogram = NULL;
  11. int ret = 0;
  12. if(argc < 2)
  13. {
  14. fprintf(stderr, "%s: too few arguments\n", argv[0]);
  15. fprintf(stderr, "Usage: %s <src> <dest>\n", argv[0]);
  16. return EXIT_FAILURE;
  17. }
  18. srcname = argv[1];
  19. dstname = argv[2];
  20. img = pipi_load(srcname);
  21. if(!img) {
  22. fprintf(stderr, "Can't open %s for reading\n", srcname);
  23. }
  24. newimg = pipi_copy(img);
  25. pipi_free(img);
  26. tmp = pipi_copy(newimg);
  27. histogram = pipi_new_histogram();
  28. pipi_get_image_histogram(tmp, histogram, PIPI_COLOR_R|PIPI_COLOR_G|PIPI_COLOR_B);
  29. pipi_render_histogram(tmp, histogram, PIPI_COLOR_R|PIPI_COLOR_G|PIPI_COLOR_B);
  30. pipi_free_histogram(histogram);
  31. pipi_save(tmp, dstname);
  32. pipi_free(newimg);
  33. pipi_free(tmp);
  34. return ret;
  35. }