/** * Divs must be in increasing order with no duplicates.
*/ staticbool valid_divs(constint* divs, int count, int start, int end) { int prev = start - 1; for (int i = 0; i < count; i++) { if (prev >= divs[i] || divs[i] > end) { returnfalse;
}
prev = divs[i];
}
/** * Count the number of pixels that are in "scalable" patches.
*/ staticint count_scalable_pixels(const int32_t* divs, int numDivs, bool firstIsScalable, int start, int end) { if (0 == numDivs) { return firstIsScalable ? end - start : 0;
}
int i; int count; if (firstIsScalable) {
count = divs[0] - start;
i = 1;
} else {
count = 0;
i = 0;
}
for (; i < numDivs; i += 2) { // Alternatively, we could use |top| and |bottom| as variable names, instead of // |left| and |right|. int left = divs[i]; int right = (i + 1 < numDivs) ? divs[i + 1] : end;
count += right - left;
}
return count;
}
/** * Set points for the src and dst rects on subsequent draw calls.
*/ staticvoid set_points(float* dst, int* src, constint* divs, int divCount, int srcFixed, int srcScalable, int srcStart, int srcEnd, float dstStart, float dstEnd, bool isScalable) { float dstLen = dstEnd - dstStart; float scale; if (srcFixed <= dstLen) { // This is the "normal" case, where we scale the "scalable" patches and leave // the other patches fixed.
scale = (dstLen - ((float) srcFixed)) / ((float) srcScalable);
} else { // In this case, we eliminate the "scalable" patches and scale the "fixed" patches.
scale = dstLen / ((float) srcFixed);
}
// In the x-dimension, the first rectangle always starts at x = 0 and is "scalable". // If xDiv[0] is 0, it indicates that the first rectangle is degenerate, so the // first real rectangle "scalable" in the x-direction. // // The same interpretation applies to the y-dimension. // // As we move left to right across the image, alternating patches will be "fixed" or // "scalable" in the x-direction. Similarly, as move top to bottom, alternating // patches will be "fixed" or "scalable" in the y-direction. int xCount = origXCount; int yCount = origYCount; bool xIsScalable = (xCount > 0 && src.fLeft == xDivs[0]); if (xIsScalable) { // Once we've decided that the first patch is "scalable", we don't need the // xDiv. It is always implied that we start at the edge of the bounds.
xDivs++;
xCount--;
} bool yIsScalable = (yCount > 0 && src.fTop == yDivs[0]); if (yIsScalable) { // Once we've decided that the first patch is "scalable", we don't need the // yDiv. It is always implied that we start at the edge of the bounds.
yDivs++;
yCount--;
}
// Count "scalable" and "fixed" pixels in each dimension. int xCountScalable = count_scalable_pixels(xDivs, xCount, xIsScalable, src.fLeft, src.fRight); int xCountFixed = src.width() - xCountScalable; int yCountScalable = count_scalable_pixels(yDivs, yCount, yIsScalable, src.fTop, src.fBottom); int yCountFixed = src.height() - yCountScalable;
bool hasPadRow = (yCount != origYCount); bool hasPadCol = (xCount != origXCount); if (hasPadRow) { // The first row of rects are all empty, skip the first row of flags.
flags += origXCount + 1;
colors += origXCount + 1;
}
int i = 0; for (int y = 0; y < yCount + 1; y++) { for (int x = 0; x < origXCount + 1; x++) { if (0 == x && hasPadCol) { // The first column of rects are all empty. Skip a rect.
flags++;
colors++; continue;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.