diff --git a/firebase-vertexai/CHANGELOG.md b/firebase-vertexai/CHANGELOG.md index 62db530d71f..e922c2d9f65 100644 --- a/firebase-vertexai/CHANGELOG.md +++ b/firebase-vertexai/CHANGELOG.md @@ -1,7 +1,12 @@ # Unreleased * [changed] Added new exception type for quota exceeded scenarios. * [feature] `CountTokenRequest` now includes `GenerationConfig` from the model. - +* [changed] **Breaking Change**: `ImagenInlineImage.data` now returns the raw + image bytes (in JPEG or PNG format, as specified in + `ImagenInlineImage.mimeType`) instead of Base64-encoded data. (#6800) + * **Action Required:** Remove any Base64 decoding from your + `ImagenInlineImage.data` usage. + * The `asBitmap()` helper method is unaffected and requires no code changes. # 16.2.0 * [fixed] Added support for new values sent by the server for `FinishReason` and `BlockReason`. diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationResponse.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationResponse.kt index dfc011b58f9..454f526bbee 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationResponse.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationResponse.kt @@ -16,6 +16,7 @@ package com.google.firebase.vertexai.type +import android.util.Base64 import com.google.firebase.vertexai.ImagenModel import kotlinx.serialization.Serializable @@ -53,7 +54,7 @@ internal constructor(public val images: List, public val filteredReason: Stri val raiFilteredReason: String? = null, ) { internal fun toPublicInline() = - ImagenInlineImage(bytesBase64Encoded!!.toByteArray(), mimeType!!) + ImagenInlineImage(Base64.decode(bytesBase64Encoded!!, Base64.NO_WRAP), mimeType!!) internal fun toPublicGCS() = ImagenGCSImage(gcsUri!!, mimeType!!) } diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenInlineImage.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenInlineImage.kt index 03e93abf8e7..1004f0a57ac 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenInlineImage.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenInlineImage.kt @@ -18,13 +18,13 @@ package com.google.firebase.vertexai.type import android.graphics.Bitmap import android.graphics.BitmapFactory -import android.util.Base64 /** - * Represents an Imagen-generated image that is contained inline + * Represents an Imagen-generated image that is returned as inline data. * - * @param data Contains the raw bytes of the image - * @param mimeType Contains the MIME type of the image (for example, `"image/png"`) + * @property data The raw image bytes in JPEG or PNG format, as specified by [mimeType]. + * @property mimeType The IANA standard MIME type of the image data; either `"image/png"` or + * `"image/jpeg"`; to request a different format, see [ImagenGenerationConfig.imageFormat]. */ @PublicPreviewAPI public class ImagenInlineImage @@ -34,7 +34,6 @@ internal constructor(public val data: ByteArray, public val mimeType: String) { * Returns the image as an Android OS native [Bitmap] so that it can be saved or sent to the UI. */ public fun asBitmap(): Bitmap { - val data = Base64.decode(data, Base64.NO_WRAP) return BitmapFactory.decodeByteArray(data, 0, data.size) } }