Flutter Engine
The Flutter Engine
SkReadPixelsRec.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
8
10
11bool SkReadPixelsRec::trim(int srcWidth, int srcHeight) {
12 if (nullptr == fPixels || fRowBytes < fInfo.minRowBytes()) {
13 return false;
14 }
15 if (0 >= fInfo.width() || 0 >= fInfo.height()) {
16 return false;
17 }
18
19 int x = fX;
20 int y = fY;
22 if (!srcR.intersect({0, 0, srcWidth, srcHeight})) {
23 return false;
24 }
25
26 // if x or y are negative, then we have to adjust pixels
27 if (x > 0) {
28 x = 0;
29 }
30 if (y > 0) {
31 y = 0;
32 }
33 // here x,y are either 0 or negative
34 // we negate and add them so UBSAN (pointer-overflow) doesn't get confused.
35 fPixels = ((char*)fPixels + -y*fRowBytes + -x*fInfo.bytesPerPixel());
36 // the intersect may have shrunk info's logical size
38 fX = srcR.x();
39 fY = srcR.y();
40
41 return true;
42}
double y
double x
Definition: SkRect.h:32
constexpr int32_t x() const
Definition: SkRect.h:141
constexpr int32_t y() const
Definition: SkRect.h:148
bool intersect(const SkIRect &r)
Definition: SkRect.h:513
constexpr SkISize size() const
Definition: SkRect.h:172
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: SkRect.h:104
size_t minRowBytes() const
Definition: SkImageInfo.h:517
SkImageInfo makeDimensions(SkISize newSize) const
Definition: SkImageInfo.h:454
int bytesPerPixel() const
Definition: SkImageInfo.h:492
int width() const
Definition: SkImageInfo.h:365
int height() const
Definition: SkImageInfo.h:371
SkImageInfo fInfo
bool trim(int srcWidth, int srcHeight)