MCPcopy Create free account
hub / github.com/CyanogenMod/android_frameworks_base / do_9patch

Function do_9patch

tools/aapt/Images.cpp:455–702  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

453}
454
455static status_t do_9patch(const char* imageName, image_info* image)
456{
457 image->is9Patch = true;
458
459 int W = image->width;
460 int H = image->height;
461 int i, j;
462
463 int maxSizeXDivs = W * sizeof(int32_t);
464 int maxSizeYDivs = H * sizeof(int32_t);
465 int32_t* xDivs = image->info9Patch.xDivs = (int32_t*) malloc(maxSizeXDivs);
466 int32_t* yDivs = image->info9Patch.yDivs = (int32_t*) malloc(maxSizeYDivs);
467 uint8_t numXDivs = 0;
468 uint8_t numYDivs = 0;
469
470 int8_t numColors;
471 int numRows;
472 int numCols;
473 int top;
474 int left;
475 int right;
476 int bottom;
477 memset(xDivs, -1, maxSizeXDivs);
478 memset(yDivs, -1, maxSizeYDivs);
479 image->info9Patch.paddingLeft = image->info9Patch.paddingRight =
480 image->info9Patch.paddingTop = image->info9Patch.paddingBottom = -1;
481
482 image->layoutBoundsLeft = image->layoutBoundsRight =
483 image->layoutBoundsTop = image->layoutBoundsBottom = 0;
484
485 png_bytep p = image->rows[0];
486 bool transparent = p[3] == 0;
487 bool hasColor = false;
488
489 const char* errorMsg = NULL;
490 int errorPixel = -1;
491 const char* errorEdge = NULL;
492
493 int colorIndex = 0;
494
495 // Validate size...
496 if (W < 3 || H < 3) {
497 errorMsg = "Image must be at least 3x3 (1x1 without frame) pixels";
498 goto getout;
499 }
500
501 // Validate frame...
502 if (!transparent &&
503 (p[0] != 0xFF || p[1] != 0xFF || p[2] != 0xFF || p[3] != 0xFF)) {
504 errorMsg = "Must have one-pixel frame that is either transparent or white";
505 goto getout;
506 }
507
508 // Find left and right of sizing areas...
509 if (get_horizontal_ticks(p, W, transparent, true, &xDivs[0],
510 &xDivs[1], &errorMsg, &numXDivs, true) != NO_ERROR) {
511 errorPixel = xDivs[0];
512 errorEdge = "top";

Callers 2

preProcessImageFunction · 0.85
preProcessImageToCacheFunction · 0.85

Calls 6

get_horizontal_ticksFunction · 0.85
get_vertical_ticksFunction · 0.85
get_colorFunction · 0.85
deviceToFileMethod · 0.80

Tested by

no test coverage detected