]> git.saurik.com Git - android/aapt.git/commitdiff
Merge commit 'remotes/korg/cupcake' into merge
authorJean-Baptiste Queru <jbq@google.com>
Wed, 18 Mar 2009 18:33:14 +0000 (11:33 -0700)
committerJean-Baptiste Queru <jbq@google.com>
Wed, 18 Mar 2009 18:33:14 +0000 (11:33 -0700)
Conflicts:
core/java/android/view/animation/TranslateAnimation.java
core/jni/Android.mk
core/res/res/values-en-rGB/strings.xml
libs/audioflinger/AudioFlinger.cpp
libs/surfaceflinger/LayerScreenshot.cpp
packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java

Images.cpp
Main.cpp
Package.cpp
ResourceTable.cpp
XMLNode.cpp

index a516a5a632984f96f1d00e63935c90f3e7c2ae50..0a4c68ba2e3296cd52595bddc00bd823a7fcaf0a 100644 (file)
@@ -332,8 +332,8 @@ static status_t do_9patch(const char* imageName, image_info* image)
     int H = image->height;
     int i, j;
 
-    int maxSizeXDivs = (W / 2 + 1) * sizeof(int32_t);
-    int maxSizeYDivs = (H / 2 + 1) * sizeof(int32_t);
+    int maxSizeXDivs = W * sizeof(int32_t);
+    int maxSizeYDivs = H * sizeof(int32_t);
     int32_t* xDivs = (int32_t*) malloc(maxSizeXDivs);
     int32_t* yDivs = (int32_t*) malloc(maxSizeYDivs);
     uint8_t  numXDivs = 0;
@@ -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,8 +857,16 @@ 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);
+
+    // If the image is a 9-patch, we need to preserve it as a ARGB file to make
+    // sure the pixels will not be pre-dithered/clamped until we decide they are
+    if (imageInfo.is9Patch && (color_type == PNG_COLOR_TYPE_RGB ||
+            color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_PALETTE)) {
+        color_type = PNG_COLOR_TYPE_RGB_ALPHA;
+    }
+
     switch (color_type) {
     case PNG_COLOR_TYPE_PALETTE:
         NOISY(printf("Image %s has %d colors%s, using PNG_COLOR_TYPE_PALETTE\n",
@@ -910,21 +930,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);
 
index ee0dbad49a6d5916e6262a3adcc3d7ad58594fb9..71b1a3c86317f6366f45e2dc8a071c029cbbbdfd 100644 (file)
--- a/Main.cpp
+++ b/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);
index 5d9e140d6614b388247528a9b08924876583d4b9..eb7d6f559ecb3d62dbaaeb0752a5f5b308052946 100644 (file)
@@ -5,6 +5,7 @@
 //
 #include "Main.h"
 #include "AaptAssets.h"
+#include "ResourceTable.h"
 
 #include <utils.h>
 #include <utils/ZipFile.h>
@@ -190,11 +191,20 @@ bail:
 ssize_t processAssets(Bundle* bundle, ZipFile* zip,
                       const sp<AaptAssets>& assets)
 {
+    ResourceFilter filter;
+    status_t status = filter.parse(bundle->getConfigurations());
+    if (status != NO_ERROR) {
+        return -1;
+    }
+
     ssize_t count = 0;
 
     const size_t N = assets->getGroupEntries().size();
     for (size_t i=0; i<N; i++) {
         const AaptGroupEntry& ge = assets->getGroupEntries()[i];
+        if (!filter.match(ge.toParams())) {
+            continue;
+        }
         ssize_t res = processAssets(bundle, zip, assets, ge);
         if (res < 0) {
             return res;
index c438366bdbc658b1708bc8127e497c6f69d6e50c..6f71a1ed0d46947cdaf21cf81da1fe85b7e2c531 100644 (file)
@@ -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;
index 2ea453cbebe52d0d42beb7faa66dc150429ebeec..d4765672274e90574a83ed554bf0039cb87b2a00 100644 (file)
@@ -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) {