vp8li_enc.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // Copyright 2012 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. // Lossless encoder: internal header.
  11. //
  12. // Author: Vikas Arora (vikaas.arora@gmail.com)
  13. #ifndef WEBP_ENC_VP8LI_ENC_H_
  14. #define WEBP_ENC_VP8LI_ENC_H_
  15. #ifdef HAVE_CONFIG_H
  16. #include "../webp/config.h"
  17. #endif
  18. // Either WEBP_NEAR_LOSSLESS is defined as 0 in config.h when compiling to
  19. // disable near-lossless, or it is enabled by default.
  20. #ifndef WEBP_NEAR_LOSSLESS
  21. #define WEBP_NEAR_LOSSLESS 1
  22. #endif
  23. #include "./backward_references_enc.h"
  24. #include "./histogram_enc.h"
  25. #include "../utils/bit_writer_utils.h"
  26. #include "../webp/encode.h"
  27. #include "../webp/format_constants.h"
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. // maximum value of transform_bits_ in VP8LEncoder.
  32. #define MAX_TRANSFORM_BITS 6
  33. typedef enum {
  34. kEncoderNone = 0,
  35. kEncoderARGB,
  36. kEncoderNearLossless,
  37. kEncoderPalette
  38. } VP8LEncoderARGBContent;
  39. typedef struct {
  40. const WebPConfig* config_; // user configuration and parameters
  41. const WebPPicture* pic_; // input picture.
  42. uint32_t* argb_; // Transformed argb image data.
  43. VP8LEncoderARGBContent argb_content_; // Content type of the argb buffer.
  44. uint32_t* argb_scratch_; // Scratch memory for argb rows
  45. // (used for prediction).
  46. uint32_t* transform_data_; // Scratch memory for transform data.
  47. uint32_t* transform_mem_; // Currently allocated memory.
  48. size_t transform_mem_size_; // Currently allocated memory size.
  49. int current_width_; // Corresponds to packed image width.
  50. // Encoding parameters derived from quality parameter.
  51. int histo_bits_;
  52. int transform_bits_; // <= MAX_TRANSFORM_BITS.
  53. int cache_bits_; // If equal to 0, don't use color cache.
  54. // Encoding parameters derived from image characteristics.
  55. int use_cross_color_;
  56. int use_subtract_green_;
  57. int use_predict_;
  58. int use_palette_;
  59. int palette_size_;
  60. uint32_t palette_[MAX_PALETTE_SIZE];
  61. // Sorted version of palette_ for cache purposes.
  62. uint32_t palette_sorted_[MAX_PALETTE_SIZE];
  63. // Some 'scratch' (potentially large) objects.
  64. struct VP8LBackwardRefs refs_[4]; // Backward Refs array for temporaries.
  65. VP8LHashChain hash_chain_; // HashChain data for constructing
  66. // backward references.
  67. } VP8LEncoder;
  68. //------------------------------------------------------------------------------
  69. // internal functions. Not public.
  70. // Encodes the picture.
  71. // Returns 0 if config or picture is NULL or picture doesn't have valid argb
  72. // input.
  73. int VP8LEncodeImage(const WebPConfig* const config,
  74. const WebPPicture* const picture);
  75. // Encodes the main image stream using the supplied bit writer.
  76. // If 'use_cache' is false, disables the use of color cache.
  77. WebPEncodingError VP8LEncodeStream(const WebPConfig* const config,
  78. const WebPPicture* const picture,
  79. VP8LBitWriter* const bw, int use_cache);
  80. #if (WEBP_NEAR_LOSSLESS == 1)
  81. // in near_lossless.c
  82. // Near lossless preprocessing in RGB color-space.
  83. int VP8ApplyNearLossless(const WebPPicture* const picture, int quality,
  84. uint32_t* const argb_dst);
  85. #endif
  86. //------------------------------------------------------------------------------
  87. // Image transforms in predictor.c.
  88. void VP8LResidualImage(int width, int height, int bits, int low_effort,
  89. uint32_t* const argb, uint32_t* const argb_scratch,
  90. uint32_t* const image, int near_lossless, int exact,
  91. int used_subtract_green);
  92. void VP8LColorSpaceTransform(int width, int height, int bits, int quality,
  93. uint32_t* const argb, uint32_t* image);
  94. //------------------------------------------------------------------------------
  95. #ifdef __cplusplus
  96. } // extern "C"
  97. #endif
  98. #endif // WEBP_ENC_VP8LI_ENC_H_