From a3476c44370f11d49397f011d9a20489ac52da8d Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Thu, 14 Aug 2025 15:45:57 -0700 Subject: [PATCH 1/7] Added dilation parameter to generateMaskAndPadForOutpainting --- firebase-ai/CHANGELOG.md | 2 ++ firebase-ai/api.txt | 2 ++ .../com/google/firebase/ai/type/ImagenReferenceImage.kt | 4 +++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/firebase-ai/CHANGELOG.md b/firebase-ai/CHANGELOG.md index 2ca8ddcc1a6..e4c5c4550f4 100644 --- a/firebase-ai/CHANGELOG.md +++ b/firebase-ai/CHANGELOG.md @@ -3,6 +3,8 @@ configured. * [feature] added support for Imagen Editing, including inpainting, outpainting, control, style transfer, and subject references (#7075) +* [changed] Added a `dilation` parameter to `ImagenMaskReference.generateMaskAndPadForOutpainting` +* (#9999) # 17.0.0 * [feature] Added support for configuring the "thinking" budget when using Gemini diff --git a/firebase-ai/api.txt b/firebase-ai/api.txt index 43ee5243d6a..bba60f3c9bc 100644 --- a/firebase-ai/api.txt +++ b/firebase-ai/api.txt @@ -698,12 +698,14 @@ package com.google.firebase.ai.type { @com.google.firebase.ai.type.PublicPreviewAPI public abstract class ImagenMaskReference extends com.google.firebase.ai.type.ImagenReferenceImage { method public static final java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions); method public static final java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions, com.google.firebase.ai.type.ImagenImagePlacement newPosition = com.google.firebase.ai.type.ImagenImagePlacement.CENTER); + method public static final java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions, com.google.firebase.ai.type.ImagenImagePlacement newPosition = com.google.firebase.ai.type.ImagenImagePlacement.CENTER, double dilation = 0.01); field public static final com.google.firebase.ai.type.ImagenMaskReference.Companion Companion; } public static final class ImagenMaskReference.Companion { method public java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions); method public java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions, com.google.firebase.ai.type.ImagenImagePlacement newPosition = com.google.firebase.ai.type.ImagenImagePlacement.CENTER); + method public java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions, com.google.firebase.ai.type.ImagenImagePlacement newPosition = com.google.firebase.ai.type.ImagenImagePlacement.CENTER, double dilation = 0.01); } @com.google.firebase.ai.type.PublicPreviewAPI public final class ImagenPersonFilterLevel { diff --git a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenReferenceImage.kt b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenReferenceImage.kt index 7456acaf46c..a2ca9a70846 100644 --- a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenReferenceImage.kt +++ b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenReferenceImage.kt @@ -124,6 +124,7 @@ internal constructor(maskConfig: ImagenMaskConfig, image: ImagenInlineImage? = n * @param newDimensions the new dimensions for outpainting. These new dimensions *must* be more * than the original image. * @param newPosition the placement of the original image within the new outpainted image. + * @param dilation the dilation for the outpainting mask. See: [ImagenRawMask]. */ @JvmOverloads @JvmStatic @@ -131,6 +132,7 @@ internal constructor(maskConfig: ImagenMaskConfig, image: ImagenInlineImage? = n image: ImagenInlineImage, newDimensions: Dimensions, newPosition: ImagenImagePlacement = ImagenImagePlacement.CENTER, + dilation: Double = 0.01 ): List { val originalBitmap = image.asBitmap() if ( @@ -180,7 +182,7 @@ internal constructor(maskConfig: ImagenMaskConfig, image: ImagenInlineImage? = n newImageCanvas.drawBitmap(originalBitmap, null, normalizedImageRectangle, null) return listOf( ImagenRawImage(newImageBitmap.toImagenInlineImage()), - ImagenRawMask(maskBitmap.toImagenInlineImage()), + ImagenRawMask(maskBitmap.toImagenInlineImage(), dilation), ) } } From 126bc2fc27cbcf220aaf5231792b872abde7496d Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Thu, 14 Aug 2025 15:46:31 -0700 Subject: [PATCH 2/7] update PR number --- firebase-ai/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-ai/CHANGELOG.md b/firebase-ai/CHANGELOG.md index e4c5c4550f4..eb5cd2c6e80 100644 --- a/firebase-ai/CHANGELOG.md +++ b/firebase-ai/CHANGELOG.md @@ -4,7 +4,7 @@ * [feature] added support for Imagen Editing, including inpainting, outpainting, control, style transfer, and subject references (#7075) * [changed] Added a `dilation` parameter to `ImagenMaskReference.generateMaskAndPadForOutpainting` -* (#9999) +* (#7260) # 17.0.0 * [feature] Added support for configuring the "thinking" budget when using Gemini From 71fc86e20bc10b298510ab6357913efac113b67d Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Thu, 14 Aug 2025 15:48:25 -0700 Subject: [PATCH 3/7] fix changelog rendering --- firebase-ai/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-ai/CHANGELOG.md b/firebase-ai/CHANGELOG.md index eb5cd2c6e80..9e1a588eb7c 100644 --- a/firebase-ai/CHANGELOG.md +++ b/firebase-ai/CHANGELOG.md @@ -4,7 +4,7 @@ * [feature] added support for Imagen Editing, including inpainting, outpainting, control, style transfer, and subject references (#7075) * [changed] Added a `dilation` parameter to `ImagenMaskReference.generateMaskAndPadForOutpainting` -* (#7260) + (#7260) # 17.0.0 * [feature] Added support for configuring the "thinking" budget when using Gemini From 6ba17c5b8ac450da59252991cd927faa959c2ca5 Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Fri, 15 Aug 2025 11:42:52 -0700 Subject: [PATCH 4/7] manual overload until next breaking change --- firebase-ai/api.txt | 4 ++++ .../firebase/ai/type/ImagenReferenceImage.kt | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/firebase-ai/api.txt b/firebase-ai/api.txt index bba60f3c9bc..0ba6af9b634 100644 --- a/firebase-ai/api.txt +++ b/firebase-ai/api.txt @@ -697,6 +697,8 @@ package com.google.firebase.ai.type { @com.google.firebase.ai.type.PublicPreviewAPI public abstract class ImagenMaskReference extends com.google.firebase.ai.type.ImagenReferenceImage { method public static final java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions); + method public static final java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions); + method public static final java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions, com.google.firebase.ai.type.ImagenImagePlacement newPosition = com.google.firebase.ai.type.ImagenImagePlacement.CENTER); method public static final java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions, com.google.firebase.ai.type.ImagenImagePlacement newPosition = com.google.firebase.ai.type.ImagenImagePlacement.CENTER); method public static final java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions, com.google.firebase.ai.type.ImagenImagePlacement newPosition = com.google.firebase.ai.type.ImagenImagePlacement.CENTER, double dilation = 0.01); field public static final com.google.firebase.ai.type.ImagenMaskReference.Companion Companion; @@ -704,6 +706,8 @@ package com.google.firebase.ai.type { public static final class ImagenMaskReference.Companion { method public java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions); + method public java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions); + method public java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions, com.google.firebase.ai.type.ImagenImagePlacement newPosition = com.google.firebase.ai.type.ImagenImagePlacement.CENTER); method public java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions, com.google.firebase.ai.type.ImagenImagePlacement newPosition = com.google.firebase.ai.type.ImagenImagePlacement.CENTER); method public java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions, com.google.firebase.ai.type.ImagenImagePlacement newPosition = com.google.firebase.ai.type.ImagenImagePlacement.CENTER, double dilation = 0.01); } diff --git a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenReferenceImage.kt b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenReferenceImage.kt index a2ca9a70846..f3e82d901a3 100644 --- a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenReferenceImage.kt +++ b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenReferenceImage.kt @@ -112,6 +112,27 @@ internal constructor(maskConfig: ImagenMaskConfig, image: ImagenInlineImage? = n ImagenReferenceImage(maskConfig = maskConfig, image = image) { public companion object { + /** + * Generates two reference images of [ImagenRawImage] and [ImagenRawMask]. These images are + * generated in this order: + * * One [ImagenRawImage] containing the original image, padded out to the new dimensions with + * black pixels, with the original image placed at the given placement + * * One [ImagenRawMask] of the same dimensions containing white everywhere except at the + * placement original image. This is the format expected by Imagen for outpainting requests. + * + * @param image the original image + * @param newDimensions the new dimensions for outpainting. These new dimensions *must* be more + * than the original image. + * @param newPosition the placement of the original image within the new outpainted image. + */ + @JvmOverloads + @JvmStatic + public fun generateMaskAndPadForOutpainting( + image: ImagenInlineImage, + newDimensions: Dimensions, + newPosition: ImagenImagePlacement = ImagenImagePlacement.CENTER, + ): List = + generateMaskAndPadForOutpainting(image, newDimensions, newPosition, 0.01) /** * Generates two reference images of [ImagenRawImage] and [ImagenRawMask]. These images are * generated in this order: From b7e4cebeec11c9515cd2a3adf469529a47ec16d6 Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Fri, 15 Aug 2025 12:44:19 -0700 Subject: [PATCH 5/7] remove extraneous overloads --- firebase-ai/api.txt | 4 ---- .../com/google/firebase/ai/type/ImagenReferenceImage.kt | 1 - 2 files changed, 5 deletions(-) diff --git a/firebase-ai/api.txt b/firebase-ai/api.txt index 0ba6af9b634..bba60f3c9bc 100644 --- a/firebase-ai/api.txt +++ b/firebase-ai/api.txt @@ -697,8 +697,6 @@ package com.google.firebase.ai.type { @com.google.firebase.ai.type.PublicPreviewAPI public abstract class ImagenMaskReference extends com.google.firebase.ai.type.ImagenReferenceImage { method public static final java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions); - method public static final java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions); - method public static final java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions, com.google.firebase.ai.type.ImagenImagePlacement newPosition = com.google.firebase.ai.type.ImagenImagePlacement.CENTER); method public static final java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions, com.google.firebase.ai.type.ImagenImagePlacement newPosition = com.google.firebase.ai.type.ImagenImagePlacement.CENTER); method public static final java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions, com.google.firebase.ai.type.ImagenImagePlacement newPosition = com.google.firebase.ai.type.ImagenImagePlacement.CENTER, double dilation = 0.01); field public static final com.google.firebase.ai.type.ImagenMaskReference.Companion Companion; @@ -706,8 +704,6 @@ package com.google.firebase.ai.type { public static final class ImagenMaskReference.Companion { method public java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions); - method public java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions); - method public java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions, com.google.firebase.ai.type.ImagenImagePlacement newPosition = com.google.firebase.ai.type.ImagenImagePlacement.CENTER); method public java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions, com.google.firebase.ai.type.ImagenImagePlacement newPosition = com.google.firebase.ai.type.ImagenImagePlacement.CENTER); method public java.util.List generateMaskAndPadForOutpainting(com.google.firebase.ai.type.ImagenInlineImage image, com.google.firebase.ai.type.Dimensions newDimensions, com.google.firebase.ai.type.ImagenImagePlacement newPosition = com.google.firebase.ai.type.ImagenImagePlacement.CENTER, double dilation = 0.01); } diff --git a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenReferenceImage.kt b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenReferenceImage.kt index f3e82d901a3..586d6b503d2 100644 --- a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenReferenceImage.kt +++ b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenReferenceImage.kt @@ -147,7 +147,6 @@ internal constructor(maskConfig: ImagenMaskConfig, image: ImagenInlineImage? = n * @param newPosition the placement of the original image within the new outpainted image. * @param dilation the dilation for the outpainting mask. See: [ImagenRawMask]. */ - @JvmOverloads @JvmStatic public fun generateMaskAndPadForOutpainting( image: ImagenInlineImage, From bd26640322d994cec380db112c217b174a2d92df Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Mon, 18 Aug 2025 10:23:25 -0700 Subject: [PATCH 6/7] minor bump --- firebase-ai/gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-ai/gradle.properties b/firebase-ai/gradle.properties index 197e5e5ce37..7428e5097cb 100644 --- a/firebase-ai/gradle.properties +++ b/firebase-ai/gradle.properties @@ -12,5 +12,5 @@ # See the License for the specific language governing permissions and # limitations under the License. -version=17.1.1 +version=17.2.0 latestReleasedVersion=17.1.0 From 47304484b161bec152042de2af4c18b601f985c6 Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Mon, 18 Aug 2025 11:49:33 -0700 Subject: [PATCH 7/7] added newline between methods --- .../kotlin/com/google/firebase/ai/type/ImagenReferenceImage.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenReferenceImage.kt b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenReferenceImage.kt index 586d6b503d2..59eb927e687 100644 --- a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenReferenceImage.kt +++ b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenReferenceImage.kt @@ -133,6 +133,7 @@ internal constructor(maskConfig: ImagenMaskConfig, image: ImagenInlineImage? = n newPosition: ImagenImagePlacement = ImagenImagePlacement.CENTER, ): List = generateMaskAndPadForOutpainting(image, newDimensions, newPosition, 0.01) + /** * Generates two reference images of [ImagenRawImage] and [ImagenRawMask]. These images are * generated in this order: