image_enc.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright 2016 Google Inc. All Rights Reserved.
  2. //
  3. // Use of this source code is governed by a BSD-style license
  4. // that can be found in the COPYING file in the root of the source
  5. // tree. An additional intellectual property rights grant can be found
  6. // in the file PATENTS. All contributing project authors may
  7. // be found in the AUTHORS file in the root of the source tree.
  8. // -----------------------------------------------------------------------------
  9. //
  10. // All-in-one library to save PNG/JPEG/WebP/TIFF/WIC images.
  11. //
  12. // Author: Skal (pascal.massimino@gmail.com)
  13. #ifndef WEBP_IMAGEIO_IMAGE_ENC_H_
  14. #define WEBP_IMAGEIO_IMAGE_ENC_H_
  15. #include <stdio.h>
  16. #ifdef HAVE_CONFIG_H
  17. #include "webp/config.h"
  18. #endif
  19. #include "webp/types.h"
  20. #include "webp/decode.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. // Output types
  25. typedef enum {
  26. PNG = 0,
  27. PAM,
  28. PPM,
  29. PGM,
  30. BMP,
  31. TIFF,
  32. RAW_YUV,
  33. ALPHA_PLANE_ONLY, // this is for experimenting only
  34. // forced colorspace output (for testing, mostly)
  35. RGB, RGBA, BGR, BGRA, ARGB,
  36. RGBA_4444, RGB_565,
  37. rgbA, bgrA, Argb, rgbA_4444,
  38. YUV, YUVA
  39. } WebPOutputFileFormat;
  40. // General all-purpose call.
  41. // Most formats expect a 'buffer' containing RGBA-like samples, except
  42. // RAW_YUV, YUV and YUVA formats.
  43. // If 'out_file_name' is "-", data is saved to stdout.
  44. // Returns false if an error occurred, true otherwise.
  45. int WebPSaveImage(const WebPDecBuffer* const buffer,
  46. WebPOutputFileFormat format, const char* const out_file_name);
  47. // Save to PNG.
  48. #ifdef HAVE_WINCODEC_H
  49. int WebPWritePNG(const char* out_file_name, int use_stdout,
  50. const struct WebPDecBuffer* const buffer);
  51. #else
  52. int WebPWritePNG(FILE* out_file, const WebPDecBuffer* const buffer);
  53. #endif
  54. // Save to PPM format (RGB, no alpha)
  55. int WebPWritePPM(FILE* fout, const struct WebPDecBuffer* const buffer);
  56. // Save to PAM format (= PPM + alpha)
  57. int WebPWritePAM(FILE* fout, const struct WebPDecBuffer* const buffer);
  58. // Save 16b mode (RGBA4444, RGB565, ...) for debugging purposes.
  59. int WebPWrite16bAsPGM(FILE* fout, const struct WebPDecBuffer* const buffer);
  60. // Save as BMP
  61. int WebPWriteBMP(FILE* fout, const struct WebPDecBuffer* const buffer);
  62. // Save as TIFF
  63. int WebPWriteTIFF(FILE* fout, const struct WebPDecBuffer* const buffer);
  64. // Save the ALPHA plane (only) as a PGM
  65. int WebPWriteAlphaPlane(FILE* fout, const struct WebPDecBuffer* const buffer);
  66. // Save as YUV samples as PGM format (using IMC4 layout).
  67. // See: http://www.fourcc.org/yuv.php#IMC4.
  68. // (very convenient format for viewing the samples, esp. for odd dimensions).
  69. int WebPWritePGM(FILE* fout, const struct WebPDecBuffer* const buffer);
  70. // Save YUV(A) planes sequentially (raw dump)
  71. int WebPWriteYUV(FILE* fout, const struct WebPDecBuffer* const buffer);
  72. // Save 16b mode (RGBA4444, RGB565, ...) as PGM format, for debugging purposes.
  73. int WebPWrite16bAsPGM(FILE* fout, const struct WebPDecBuffer* const buffer);
  74. #ifdef __cplusplus
  75. } // extern "C"
  76. #endif
  77. #endif // WEBP_IMAGEIO_IMAGE_ENC_H_