summaryrefslogtreecommitdiffstats
path: root/tools/aapt
diff options
context:
space:
mode:
Diffstat (limited to 'tools/aapt')
-rw-r--r--tools/aapt/Images.cpp37
-rw-r--r--tools/aapt/Main.cpp6
-rw-r--r--tools/aapt/ResourceTable.cpp5
-rw-r--r--tools/aapt/XMLNode.cpp4
4 files changed, 30 insertions, 22 deletions
diff --git a/tools/aapt/Images.cpp b/tools/aapt/Images.cpp
index a516a5a..4c776fb 100644
--- a/tools/aapt/Images.cpp
+++ b/tools/aapt/Images.cpp
@@ -600,10 +600,22 @@ static bool patch_equals(Res_png_9patch& patch1, Res_png_9patch& patch2) {
return true;
}
-static void dump_image(int w, int h, png_bytepp rows, int bpp)
+static void dump_image(int w, int h, png_bytepp rows, int color_type)
{
int i, j, rr, gg, bb, aa;
+ int bpp;
+ if (color_type == PNG_COLOR_TYPE_PALETTE || color_type == PNG_COLOR_TYPE_GRAY) {
+ bpp = 1;
+ } else if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
+ bpp = 2;
+ } else if (color_type == PNG_COLOR_TYPE_RGB || color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
+ // We use a padding byte even when there is no alpha
+ bpp = 4;
+ } else {
+ printf("Unknown color type %d.\n", color_type);
+ }
+
for (j = 0; j < h; j++) {
png_bytep row = rows[j];
for (i = 0; i < w; i++) {
@@ -640,7 +652,7 @@ static void dump_image(int w, int h, png_bytepp rows, int bpp)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define ABS(a) ((a)<0?-(a):(a))
-static void analyze_image(image_info &imageInfo, int grayscaleTolerance,
+static void analyze_image(const char *imageName, image_info &imageInfo, int grayscaleTolerance,
png_colorp rgbPalette, png_bytep alphaPalette,
int *paletteEntries, bool *hasTransparency, int *colorType,
png_bytepp outRows)
@@ -662,7 +674,7 @@ static void analyze_image(image_info &imageInfo, int grayscaleTolerance,
// 3. There are no more than 256 distinct RGBA colors
// NOISY(printf("Initial image data:\n"));
- // dump_image(w, h, imageInfo.rows, 4);
+ // dump_image(w, h, imageInfo.rows, PNG_COLOR_TYPE_RGB_ALPHA);
for (j = 0; j < h; j++) {
png_bytep row = imageInfo.rows[j];
@@ -763,7 +775,7 @@ static void analyze_image(image_info &imageInfo, int grayscaleTolerance,
*colorType = PNG_COLOR_TYPE_PALETTE;
} else {
if (maxGrayDeviation <= grayscaleTolerance) {
- NOISY(printf("Forcing image to gray (max deviation = %d)\n", maxGrayDeviation));
+ printf("%s: forcing image to gray (max deviation = %d)\n", imageName, maxGrayDeviation);
*colorType = isOpaque ? PNG_COLOR_TYPE_GRAY : PNG_COLOR_TYPE_GRAY_ALPHA;
} else {
*colorType = isOpaque ? PNG_COLOR_TYPE_RGB : PNG_COLOR_TYPE_RGB_ALPHA;
@@ -845,7 +857,7 @@ static void write_png(const char* imageName,
bool hasTransparency;
int paletteEntries;
- analyze_image(imageInfo, grayscaleTolerance, rgbPalette, alphaPalette,
+ analyze_image(imageName, imageInfo, grayscaleTolerance, rgbPalette, alphaPalette,
&paletteEntries, &hasTransparency, &color_type, outRows);
switch (color_type) {
case PNG_COLOR_TYPE_PALETTE:
@@ -910,21 +922,8 @@ static void write_png(const char* imageName,
}
png_write_image(write_ptr, rows);
-// int bpp;
-// if (color_type == PNG_COLOR_TYPE_PALETTE || color_type == PNG_COLOR_TYPE_GRAY) {
-// bpp = 1;
-// } else if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
-// bpp = 2;
-// } else if (color_type == PNG_COLOR_TYPE_RGB) {
-// bpp = 4;
-// } else if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
-// bpp = 4;
-// } else {
-// printf("Uknknown color type %d, exiting.\n", color_type);
-// exit(1);
-// }
// NOISY(printf("Final image data:\n"));
-// dump_image(imageInfo.width, imageInfo.height, rows, bpp);
+// dump_image(imageInfo.width, imageInfo.height, rows, color_type);
png_write_end(write_ptr, write_info);
diff --git a/tools/aapt/Main.cpp b/tools/aapt/Main.cpp
index ee0dbad..71b1a3c 100644
--- a/tools/aapt/Main.cpp
+++ b/tools/aapt/Main.cpp
@@ -146,9 +146,11 @@ int handleCommand(Bundle* bundle)
*/
int main(int argc, char* const argv[])
{
+ char *prog = argv[0];
Bundle bundle;
bool wantUsage = false;
int result = 1; // pessimistically assume an error.
+ int tolerance = 0;
/* default to compression */
bundle.setCompressionMethod(ZipEntry::kCompressDeflated);
@@ -214,7 +216,9 @@ int main(int argc, char* const argv[])
wantUsage = true;
goto bail;
}
- bundle.setGrayscaleTolerance(atoi(argv[0]));
+ tolerance = atoi(argv[0]);
+ bundle.setGrayscaleTolerance(tolerance);
+ printf("%s: Images with deviation <= %d will be forced to grayscale.\n", prog, tolerance);
break;
case 'm':
bundle.setMakePackageDirs(true);
diff --git a/tools/aapt/ResourceTable.cpp b/tools/aapt/ResourceTable.cpp
index c438366..6f71a1e 100644
--- a/tools/aapt/ResourceTable.cpp
+++ b/tools/aapt/ResourceTable.cpp
@@ -644,6 +644,7 @@ status_t compileResourceFile(Bundle* bundle,
const String16 bool16("bool");
const String16 integer16("integer");
const String16 dimen16("dimen");
+ const String16 fraction16("fraction");
const String16 style16("style");
const String16 plurals16("plurals");
const String16 array16("array");
@@ -1022,6 +1023,10 @@ status_t compileResourceFile(Bundle* bundle,
curTag = &dimen16;
curType = dimen16;
curFormat = ResTable_map::TYPE_REFERENCE|ResTable_map::TYPE_DIMENSION;
+ } else if (strcmp16(block.getElementName(&len), fraction16.string()) == 0) {
+ curTag = &fraction16;
+ curType = fraction16;
+ curFormat = ResTable_map::TYPE_REFERENCE|ResTable_map::TYPE_FRACTION;
} else if (strcmp16(block.getElementName(&len), bag16.string()) == 0) {
curTag = &bag16;
curIsBag = true;
diff --git a/tools/aapt/XMLNode.cpp b/tools/aapt/XMLNode.cpp
index 2ea453c..d476567 100644
--- a/tools/aapt/XMLNode.cpp
+++ b/tools/aapt/XMLNode.cpp
@@ -220,9 +220,9 @@ moveon:
spanStack.pop();
if (empty) {
- fprintf(stderr, "%s:%d: WARNING: empty '%s' span found for at text '%s'\n",
+ fprintf(stderr, "%s:%d: WARNING: empty '%s' span found in text '%s'\n",
fileName, inXml->getLineNumber(),
- String8(*outString).string(), String8(spanTag).string());
+ String8(spanTag).string(), String8(*outString).string());
}
} else if (code == ResXMLTree::START_NAMESPACE) {