image_save.c 708 B

123456789101112131415161718192021222324252627282930313233
  1. #include "fitz-internal.h"
  2. void fz_write_pixmap(fz_context *ctx, fz_pixmap *img, char *file, int rgb)
  3. {
  4. char name[1024];
  5. fz_pixmap *converted = NULL;
  6. if (!img)
  7. return;
  8. if (rgb && img->colorspace && img->colorspace != fz_device_rgb)
  9. {
  10. fz_irect bbox;
  11. converted = fz_new_pixmap_with_bbox(ctx, fz_device_rgb, fz_pixmap_bbox(ctx, img, &bbox));
  12. fz_convert_pixmap(ctx, converted, img);
  13. img = converted;
  14. }
  15. if (img->n <= 4)
  16. {
  17. sprintf(name, "%s.png", file);
  18. printf("extracting image %s\n", name);
  19. fz_write_png(ctx, img, name, 0);
  20. }
  21. else
  22. {
  23. sprintf(name, "%s.pam", file);
  24. printf("extracting image %s\n", name);
  25. fz_write_pam(ctx, img, name, 0);
  26. }
  27. fz_drop_pixmap(ctx, converted);
  28. }