25template <
typename PixelAt>
27 MarkerRun &
run, std::string *
error) {
29 for (
int i = 0; i <
count; ++i) {
33 if (
error) *
error = std::string(
edge) +
" has multiple stretch runs";
36 if (
run.first < 0)
run.first = i;
39 if (!transparent(
color)) {
40 if (
error) *
error = std::string(
edge) +
" contains a non-marker pixel";
47 if (
error) *
error = std::string(
edge) +
" is missing a stretch marker";
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))
111 if (
source.getWidth() < 3 ||
source.getHeight() < 3)
return nullptr;
112 auto result = std::make_unique<image::ImageData>(
source.getWidth() - 2,
const UnitySourceAsset & source
Represents raw pixel data.
medialoader::Colorf Colorf
bool parseNinePatch(const image::ImageData &source, NinePatchInfo &out, std::string *error)
Parse a raw, uncompiled Android .9.png image.
std::unique_ptr< image::ImageData > stripNinePatchBorder(const image::ImageData &source)
Copy the drawable interior of a parsed .9.png without marker pixels.
Parsed Android-style .9.png stretch and content metadata.