Coverage Report

Created: 2026-02-14 06:26

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libwebp/src/utils/rescaler_utils.h
Line
Count
Source
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
14
#ifndef WEBP_UTILS_RESCALER_UTILS_H_
15
#define WEBP_UTILS_RESCALER_UTILS_H_
16
17
#ifdef __cplusplus
18
extern "C" {
19
#endif
20
21
#include "src/utils/bounds_safety.h"
22
#include "src/webp/types.h"
23
24
WEBP_ASSUME_UNSAFE_INDEXABLE_ABI
25
26
0
#define WEBP_RESCALER_RFIX 32  // fixed-point precision for multiplies
27
0
#define WEBP_RESCALER_ONE (1ull << WEBP_RESCALER_RFIX)
28
#define WEBP_RESCALER_FRAC(x, y) \
29
0
  ((uint32_t)(((uint64_t)(x) << WEBP_RESCALER_RFIX) / (y)))
30
31
// Structure used for on-the-fly rescaling
32
typedef uint32_t rescaler_t;  // type for side-buffer
33
typedef struct WebPRescaler WebPRescaler;
34
struct WebPRescaler {
35
  int x_expand;               // true if we're expanding in the x direction
36
  int y_expand;               // true if we're expanding in the y direction
37
  int num_channels;           // bytes to jump between pixels
38
  uint32_t fx_scale;          // fixed-point scaling factors
39
  uint32_t fy_scale;          // ''
40
  uint32_t fxy_scale;         // ''
41
  int y_accum;                // vertical accumulator
42
  int y_add, y_sub;           // vertical increments
43
  int x_add, x_sub;           // horizontal increments
44
  int src_width, src_height;  // source dimensions
45
  int dst_width, dst_height;  // destination dimensions
46
  int src_y, dst_y;           // row counters for input and output
47
  uint8_t* dst;
48
  int dst_stride;
49
  // work buffer
50
  rescaler_t* WEBP_COUNTED_BY(dst_width* num_channels) irow;
51
  rescaler_t* WEBP_COUNTED_BY(dst_width* num_channels) frow;
52
};
53
54
// Initialize a rescaler given scratch area 'work' and dimensions of src & dst.
55
// Returns false in case of error.
56
int WebPRescalerInit(WebPRescaler* const rescaler, int src_width,
57
                     int src_height, uint8_t* const dst, int dst_width,
58
                     int dst_height, int dst_stride, int num_channels,
59
                     rescaler_t* const WEBP_COUNTED_BY(2ULL * dst_width *
60
                                                       num_channels) work);
61
62
// If either 'scaled_width' or 'scaled_height' (but not both) is 0 the value
63
// will be calculated preserving the aspect ratio, otherwise the values are
64
// left unmodified. Returns true on success, false if either value is 0 after
65
// performing the scaling calculation.
66
int WebPRescalerGetScaledDimensions(int src_width, int src_height,
67
                                    int* const scaled_width,
68
                                    int* const scaled_height);
69
70
// Returns the number of input lines needed next to produce one output line,
71
// considering that the maximum available input lines are 'max_num_lines'.
72
int WebPRescaleNeededLines(const WebPRescaler* const rescaler,
73
                           int max_num_lines);
74
75
// Import multiple rows over all channels, until at least one row is ready to
76
// be exported. Returns the actual number of lines that were imported.
77
int WebPRescalerImport(WebPRescaler* const rescaler, int num_rows,
78
                       const uint8_t* src, int src_stride);
79
80
// Export as many rows as possible. Return the numbers of rows written.
81
int WebPRescalerExport(WebPRescaler* const rescaler);
82
83
// Return true if input is finished
84
static WEBP_INLINE int WebPRescalerInputDone(
85
0
    const WebPRescaler* const rescaler) {
86
0
  return (rescaler->src_y >= rescaler->src_height);
87
0
}
Unexecuted instantiation: webp_dec.c:WebPRescalerInputDone
Unexecuted instantiation: rescaler_utils.c:WebPRescalerInputDone
Unexecuted instantiation: buffer_dec.c:WebPRescalerInputDone
Unexecuted instantiation: frame_dec.c:WebPRescalerInputDone
Unexecuted instantiation: io_dec.c:WebPRescalerInputDone
Unexecuted instantiation: vp8_dec.c:WebPRescalerInputDone
Unexecuted instantiation: vp8l_dec.c:WebPRescalerInputDone
Unexecuted instantiation: dec.c:WebPRescalerInputDone
Unexecuted instantiation: lossless.c:WebPRescalerInputDone
Unexecuted instantiation: rescaler.c:WebPRescalerInputDone
Unexecuted instantiation: dec_sse2.c:WebPRescalerInputDone
Unexecuted instantiation: rescaler_sse2.c:WebPRescalerInputDone
Unexecuted instantiation: dec_sse41.c:WebPRescalerInputDone
Unexecuted instantiation: alpha_dec.c:WebPRescalerInputDone
Unexecuted instantiation: quant_dec.c:WebPRescalerInputDone
Unexecuted instantiation: tree_dec.c:WebPRescalerInputDone
Unexecuted instantiation: picture_rescale_enc.c:WebPRescalerInputDone
88
// Return true if output is finished
89
static WEBP_INLINE int WebPRescalerOutputDone(
90
0
    const WebPRescaler* const rescaler) {
91
0
  return (rescaler->dst_y >= rescaler->dst_height);
92
0
}
Unexecuted instantiation: webp_dec.c:WebPRescalerOutputDone
Unexecuted instantiation: rescaler_utils.c:WebPRescalerOutputDone
Unexecuted instantiation: buffer_dec.c:WebPRescalerOutputDone
Unexecuted instantiation: frame_dec.c:WebPRescalerOutputDone
Unexecuted instantiation: io_dec.c:WebPRescalerOutputDone
Unexecuted instantiation: vp8_dec.c:WebPRescalerOutputDone
Unexecuted instantiation: vp8l_dec.c:WebPRescalerOutputDone
Unexecuted instantiation: dec.c:WebPRescalerOutputDone
Unexecuted instantiation: lossless.c:WebPRescalerOutputDone
Unexecuted instantiation: rescaler.c:WebPRescalerOutputDone
Unexecuted instantiation: dec_sse2.c:WebPRescalerOutputDone
Unexecuted instantiation: rescaler_sse2.c:WebPRescalerOutputDone
Unexecuted instantiation: dec_sse41.c:WebPRescalerOutputDone
Unexecuted instantiation: alpha_dec.c:WebPRescalerOutputDone
Unexecuted instantiation: quant_dec.c:WebPRescalerOutputDone
Unexecuted instantiation: tree_dec.c:WebPRescalerOutputDone
Unexecuted instantiation: picture_rescale_enc.c:WebPRescalerOutputDone
93
94
// Return true if there are pending output rows ready.
95
static WEBP_INLINE int WebPRescalerHasPendingOutput(
96
0
    const WebPRescaler* const rescaler) {
97
0
  return !WebPRescalerOutputDone(rescaler) && (rescaler->y_accum <= 0);
98
0
}
Unexecuted instantiation: webp_dec.c:WebPRescalerHasPendingOutput
Unexecuted instantiation: rescaler_utils.c:WebPRescalerHasPendingOutput
Unexecuted instantiation: buffer_dec.c:WebPRescalerHasPendingOutput
Unexecuted instantiation: frame_dec.c:WebPRescalerHasPendingOutput
Unexecuted instantiation: io_dec.c:WebPRescalerHasPendingOutput
Unexecuted instantiation: vp8_dec.c:WebPRescalerHasPendingOutput
Unexecuted instantiation: vp8l_dec.c:WebPRescalerHasPendingOutput
Unexecuted instantiation: dec.c:WebPRescalerHasPendingOutput
Unexecuted instantiation: lossless.c:WebPRescalerHasPendingOutput
Unexecuted instantiation: rescaler.c:WebPRescalerHasPendingOutput
Unexecuted instantiation: dec_sse2.c:WebPRescalerHasPendingOutput
Unexecuted instantiation: rescaler_sse2.c:WebPRescalerHasPendingOutput
Unexecuted instantiation: dec_sse41.c:WebPRescalerHasPendingOutput
Unexecuted instantiation: alpha_dec.c:WebPRescalerHasPendingOutput
Unexecuted instantiation: quant_dec.c:WebPRescalerHasPendingOutput
Unexecuted instantiation: tree_dec.c:WebPRescalerHasPendingOutput
Unexecuted instantiation: picture_rescale_enc.c:WebPRescalerHasPendingOutput
99
100
//------------------------------------------------------------------------------
101
102
#ifdef __cplusplus
103
}  // extern "C"
104
#endif
105
106
#endif  // WEBP_UTILS_RESCALER_UTILS_H_