rescaler.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. // Rescaling functions
  11. //
  12. // Author: Skal (pascal.massimino@gmail.com)
  13. #ifndef WEBP_UTILS_RESCALER_H_
  14. #define WEBP_UTILS_RESCALER_H_
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include "../webp/types.h"
  19. // Structure used for on-the-fly rescaling
  20. typedef struct {
  21. int x_expand; // true if we're expanding in the x direction
  22. int num_channels; // bytes to jump between pixels
  23. int fy_scale, fx_scale; // fixed-point scaling factor
  24. int64_t fxy_scale; // ''
  25. // we need hpel-precise add/sub increments, for the downsampled U/V planes.
  26. int y_accum; // vertical accumulator
  27. int y_add, y_sub; // vertical increments (add ~= src, sub ~= dst)
  28. int x_add, x_sub; // horizontal increments (add ~= src, sub ~= dst)
  29. int src_width, src_height; // source dimensions
  30. int dst_width, dst_height; // destination dimensions
  31. uint8_t* dst;
  32. int dst_stride;
  33. int32_t* irow, *frow; // work buffer
  34. } WebPRescaler;
  35. // Initialize a rescaler given scratch area 'work' and dimensions of src & dst.
  36. void WebPRescalerInit(WebPRescaler* const rescaler,
  37. int src_width, int src_height,
  38. uint8_t* const dst,
  39. int dst_width, int dst_height, int dst_stride,
  40. int num_channels,
  41. int x_add, int x_sub,
  42. int y_add, int y_sub,
  43. int32_t* const work);
  44. // Returns the number of input lines needed next to produce one output line,
  45. // considering that the maximum available input lines are 'max_num_lines'.
  46. int WebPRescaleNeededLines(const WebPRescaler* const rescaler,
  47. int max_num_lines);
  48. // Import multiple rows over all channels, until at least one row is ready to
  49. // be exported. Returns the actual number of lines that were imported.
  50. int WebPRescalerImport(WebPRescaler* const rescaler, int num_rows,
  51. const uint8_t* src, int src_stride);
  52. // Import a row of data and save its contribution in the rescaler.
  53. // 'channel' denotes the channel number to be imported.
  54. extern void (*WebPRescalerImportRow)(WebPRescaler* const wrk,
  55. const uint8_t* const src, int channel);
  56. // Export one row (starting at x_out position) from rescaler.
  57. extern void (*WebPRescalerExportRow)(WebPRescaler* const wrk, int x_out);
  58. // Return true if there is pending output rows ready.
  59. static WEBP_INLINE
  60. int WebPRescalerHasPendingOutput(const WebPRescaler* const rescaler) {
  61. return (rescaler->y_accum <= 0);
  62. }
  63. // Export as many rows as possible. Return the numbers of rows written.
  64. int WebPRescalerExport(WebPRescaler* const rescaler);
  65. //------------------------------------------------------------------------------
  66. #ifdef __cplusplus
  67. } // extern "C"
  68. #endif
  69. #endif /* WEBP_UTILS_RESCALER_H_ */