58 if (
source.getFormat() !=
"RGBA8") {
59 if (
error) *
error =
".9.png source must decode as RGBA8";
63 if (
error) *
error =
".9.png must include a one-pixel frame around content";
69 for (
const auto &[
x,
y] : {std::pair{0, 0}, std::pair{
source.getWidth() - 1, 0},
70 std::pair{0,
source.getHeight() - 1},
71 std::pair{
source.getWidth() - 1,
72 source.getHeight() - 1}}) {
73 if (!transparent(
source.getPixel(
x,
y))) {
74 if (
error) *
error =
".9.png corner marker pixels must be transparent";
83 if (!scanRun(
width, [&](
int i) {
return source.getPixel(i + 1, 0); },
true,
84 "top edge", stretchX,
error) ||
85 !scanRun(
height, [&](
int i) {
return source.getPixel(0, i + 1); },
true,
86 "left edge", stretchY,
error) ||
88 [&](
int i) {
return source.getPixel(i + 1,
source.getHeight() - 1); },
89 false,
"bottom edge", contentX,
error) ||
91 [&](
int i) {
return source.getPixel(
source.getWidth() - 1, i + 1); },
92 false,
"right edge", contentY,
error))
97 out.borderLeft = stretchX.first;
98 out.borderRight =
width - stretchX.last - 1;
99 out.borderTop = stretchY.first;
100 out.borderBottom =
height - stretchY.last - 1;
101 out.paddingLeft = contentX.first >= 0 ? contentX.first :
out.borderLeft;
102 out.paddingRight = contentX.first >= 0 ?
width - contentX.last - 1 :
out.borderRight;
103 out.paddingTop = contentY.first >= 0 ? contentY.first :
out.borderTop;
104 out.paddingBottom = contentY.first >= 0 ?
height - contentY.last - 1
bool parseNinePatch(const image::ImageData &source, NinePatchInfo &out, std::string *error)
Parse a raw, uncompiled Android .9.png image.