Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion firebase-vertexai/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.firebase.vertexai.type

import android.util.Base64
import com.google.firebase.vertexai.ImagenModel
import kotlinx.serialization.Serializable

Expand Down Expand Up @@ -53,7 +54,7 @@ internal constructor(public val images: List<T>, 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!!)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}