Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 055b82aa authored by Matt Sarett's avatar Matt Sarett Committed by Android (Google) Code Review
Browse files

Merge "Allow ninepatches to be encoded using non-RGBA modes"

parents d20aebb3 3b1b68d6
Loading
Loading
Loading
Loading
+10 −9
Original line number Diff line number Diff line
@@ -260,6 +260,15 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding
        return nullObjectReturn("SkAndroidCodec::NewFromStream returned null");
    }

    // Do not allow ninepatch decodes to 565.  In the past, decodes to 565
    // would dither, and we do not want to pre-dither ninepatches, since we
    // know that they will be stretched.  We no longer dither 565 decodes,
    // but we continue to prevent ninepatches from decoding to 565, in order
    // to maintain the old behavior.
    if (peeker.mPatch && kRGB_565_SkColorType == prefColorType) {
        prefColorType = kN32_SkColorType;
    }

    // Determine the output size and return if the client only wants the size.
    SkISize size = codec->getSampledDimensions(sampleSize);
    if (options != NULL) {
@@ -369,15 +378,7 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding
        case SkCodec::kIncompleteInput:
            break;
        default:
            return nullObjectReturn("codec->getAndoridPixels() failed.");
    }

    // Some images may initially report that they have alpha due to the format
    // of the encoded data, but then never use any colors which have alpha
    // less than 100%.  Here we check if the image really had alpha, and
    // mark it as opaque if it is actually opaque.
    if (kOpaque_SkAlphaType != alphaType && !codec->reallyHasAlpha()) {
        decodingBitmap.setAlphaType(kOpaque_SkAlphaType);
            return nullObjectReturn("codec->getAndroidPixels() failed.");
    }

    int scaledWidth = size.width();
+1 −15
Original line number Diff line number Diff line
@@ -1095,13 +1095,6 @@ static void write_png(const char* imageName,
    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;
    }

    if (kIsDebug) {
        switch (color_type) {
        case PNG_COLOR_TYPE_PALETTE:
@@ -1180,18 +1173,11 @@ static void write_png(const char* imageName,
        }

        for (int i = 0; i < chunk_count; i++) {
            unknowns[i].location = PNG_HAVE_PLTE;
            unknowns[i].location = PNG_HAVE_IHDR;
        }
        png_set_keep_unknown_chunks(write_ptr, PNG_HANDLE_CHUNK_ALWAYS,
                                    chunk_names, chunk_count);
        png_set_unknown_chunks(write_ptr, write_info, unknowns, chunk_count);
#if PNG_LIBPNG_VER < 10600
        /* Deal with unknown chunk location bug in 1.5.x and earlier */
        png_set_unknown_chunk_location(write_ptr, write_info, 0, PNG_HAVE_PLTE);
        if (imageInfo.haveLayoutBounds) {
            png_set_unknown_chunk_location(write_ptr, write_info, 1, PNG_HAVE_PLTE);
        }
#endif
    }