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

Commit 6fd900a3 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "HEIF: Re-decode the image when changing color type"

parents a9ae62a3 7ca678b4
Loading
Loading
Loading
Loading
+25 −8
Original line number Diff line number Diff line
@@ -334,6 +334,13 @@ bool HeifDecoderImpl::init(HeifStream* stream, HeifFrameInfo* frameInfo) {
    }
    mDataSource = dataSource;

    return reinit(frameInfo);
}

bool HeifDecoderImpl::reinit(HeifFrameInfo* frameInfo) {
    mFrameDecoded = false;
    mFrameMemory.clear();

    mRetriever = new MediaMetadataRetriever();
    status_t err = mRetriever->setDataSource(mDataSource, "image/heif");
    if (err != OK) {
@@ -457,29 +464,37 @@ bool HeifDecoderImpl::getEncodedColor(HeifEncodedColor* /*outColor*/) const {
}

bool HeifDecoderImpl::setOutputColor(HeifColorFormat heifColor) {
    if (heifColor == mOutputColor) {
        return true;
    }

    switch(heifColor) {
        case kHeifColorFormat_RGB565:
        {
            mOutputColor = HAL_PIXEL_FORMAT_RGB_565;
            return true;
            break;
        }
        case kHeifColorFormat_RGBA_8888:
        {
            mOutputColor = HAL_PIXEL_FORMAT_RGBA_8888;
            return true;
            break;
        }
        case kHeifColorFormat_BGRA_8888:
        {
            mOutputColor = HAL_PIXEL_FORMAT_BGRA_8888;
            return true;
        }
        default:
            break;
        }
        default:
            ALOGE("Unsupported output color format %d", heifColor);
            return false;
    }

    if (mFrameDecoded) {
        return reinit(nullptr);
    }
    return true;
}

bool HeifDecoderImpl::decodeAsync() {
    for (size_t i = 1; i < mNumSlices; i++) {
        ALOGV("decodeAsync(): decoding slice %zu", i);
@@ -506,7 +521,8 @@ bool HeifDecoderImpl::decodeAsync() {
    }
    // Aggressive clear to avoid holding on to resources
    mRetriever.clear();
    mDataSource.clear();

    // Hold on to mDataSource in case the client wants to redecode.
    return false;
}

@@ -606,7 +622,8 @@ bool HeifDecoderImpl::decode(HeifFrameInfo* frameInfo) {

    // Aggressively clear to avoid holding on to resources
    mRetriever.clear();
    mDataSource.clear();

    // Hold on to mDataSource in case the client wants to redecode.
    return true;
}

+1 −0
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ private:

    bool decodeAsync();
    bool getScanlineInner(uint8_t* dst);
    bool reinit(HeifFrameInfo* frameInfo);
};

} // namespace android