Skip to content

Commit 564734a

Browse files
andrewheardrlazo
andauthored
[Vertex AI] Return ImagenInlineImage.data as binary (#6800)
Co-authored-by: Rodrigo Lazo <[email protected]>
1 parent 1cf65b9 commit 564734a

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

firebase-vertexai/CHANGELOG.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
# Unreleased
22
* [changed] Added new exception type for quota exceeded scenarios.
33
* [feature] `CountTokenRequest` now includes `GenerationConfig` from the model.
4-
4+
* [changed] **Breaking Change**: `ImagenInlineImage.data` now returns the raw
5+
image bytes (in JPEG or PNG format, as specified in
6+
`ImagenInlineImage.mimeType`) instead of Base64-encoded data. (#6800)
7+
* **Action Required:** Remove any Base64 decoding from your
8+
`ImagenInlineImage.data` usage.
9+
* The `asBitmap()` helper method is unaffected and requires no code changes.
510

611
# 16.2.0
712
* [fixed] Added support for new values sent by the server for `FinishReason` and `BlockReason`.

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenGenerationResponse.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.google.firebase.vertexai.type
1818

19+
import android.util.Base64
1920
import com.google.firebase.vertexai.ImagenModel
2021
import kotlinx.serialization.Serializable
2122

@@ -53,7 +54,7 @@ internal constructor(public val images: List<T>, public val filteredReason: Stri
5354
val raiFilteredReason: String? = null,
5455
) {
5556
internal fun toPublicInline() =
56-
ImagenInlineImage(bytesBase64Encoded!!.toByteArray(), mimeType!!)
57+
ImagenInlineImage(Base64.decode(bytesBase64Encoded!!, Base64.NO_WRAP), mimeType!!)
5758

5859
internal fun toPublicGCS() = ImagenGCSImage(gcsUri!!, mimeType!!)
5960
}

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ImagenInlineImage.kt

+4-5
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ package com.google.firebase.vertexai.type
1818

1919
import android.graphics.Bitmap
2020
import android.graphics.BitmapFactory
21-
import android.util.Base64
2221

2322
/**
24-
* Represents an Imagen-generated image that is contained inline
23+
* Represents an Imagen-generated image that is returned as inline data.
2524
*
26-
* @param data Contains the raw bytes of the image
27-
* @param mimeType Contains the MIME type of the image (for example, `"image/png"`)
25+
* @property data The raw image bytes in JPEG or PNG format, as specified by [mimeType].
26+
* @property mimeType The IANA standard MIME type of the image data; either `"image/png"` or
27+
* `"image/jpeg"`; to request a different format, see [ImagenGenerationConfig.imageFormat].
2828
*/
2929
@PublicPreviewAPI
3030
public class ImagenInlineImage
@@ -34,7 +34,6 @@ internal constructor(public val data: ByteArray, public val mimeType: String) {
3434
* Returns the image as an Android OS native [Bitmap] so that it can be saved or sent to the UI.
3535
*/
3636
public fun asBitmap(): Bitmap {
37-
val data = Base64.decode(data, Base64.NO_WRAP)
3837
return BitmapFactory.decodeByteArray(data, 0, data.size)
3938
}
4039
}

0 commit comments

Comments
 (0)