Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
calculate_pitch.cpp
Go to the documentation of this file.
1// Copyright 2022 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "core/fxge/calculate_pitch.h"
6
7#include "core/fxcrt/fx_safe_types.h"
8#include "core/fxge/dib/fx_dib.h"
9
10namespace fxge {
11namespace {
12
13FX_SAFE_UINT32 CalculatePitch8Safely(uint32_t bpc,
14 uint32_t components,
15 int width) {
16 FX_SAFE_UINT32 pitch = bpc;
17 pitch *= components;
18 pitch *= width;
19 pitch += 7;
20 pitch /= 8;
21 return pitch;
22}
23
24FX_SAFE_UINT32 CalculatePitch32Safely(int bpp, int width) {
25 FX_SAFE_UINT32 pitch = bpp;
26 pitch *= width;
27 pitch += 31;
28 pitch /= 32; // quantized to number of 32-bit words.
29 pitch *= 4; // and then back to bytes, (not just /8 in one step).
30 return pitch;
31}
32
33} // namespace
34
35uint32_t CalculatePitch8OrDie(uint32_t bpc, uint32_t components, int width) {
36 return CalculatePitch8Safely(bpc, components, width).ValueOrDie();
37}
38
39uint32_t CalculatePitch32OrDie(int bpp, int width) {
40 return CalculatePitch32Safely(bpp, width).ValueOrDie();
41}
42
44 uint32_t components,
45 int width) {
46 FX_SAFE_UINT32 pitch = CalculatePitch8Safely(bpc, components, width);
47 if (!pitch.IsValid())
48 return absl::nullopt;
49 return pitch.ValueOrDie();
50}
51
52absl::optional<uint32_t> CalculatePitch32(int bpp, int width) {
53 FX_SAFE_UINT32 pitch = CalculatePitch32Safely(bpp, width);
54 if (!pitch.IsValid())
55 return absl::nullopt;
56 return pitch.ValueOrDie();
57}
58
59} // namespace fxge
absl::optional< uint32_t > CalculatePitch8(uint32_t bpc, uint32_t components, int width)
absl::optional< uint32_t > CalculatePitch32(int bpp, int width)
uint32_t CalculatePitch32OrDie(int bpp, int width)
uint32_t CalculatePitch8OrDie(uint32_t bpc, uint32_t components, int width)