diff --git a/firebase-ai/CHANGELOG.md b/firebase-ai/CHANGELOG.md index eb1c9503ac8..f566974f52e 100644 --- a/firebase-ai/CHANGELOG.md +++ b/firebase-ai/CHANGELOG.md @@ -1,6 +1,8 @@ # Unreleased * [changed] Added better description for requests which fail due to the Gemini API not being configured. +* [changed] Added a `dilation` parameter to `ImagenMaskReference.generateMaskAndPadForOutpainting` + (#7260) # 17.1.0 ======= 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/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 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..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 @@ -131,6 +131,29 @@ internal constructor(maskConfig: ImagenMaskConfig, image: ImagenInlineImage? = n 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: + * * 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. + * @param dilation the dilation for the outpainting mask. See: [ImagenRawMask]. + */ + @JvmStatic + public fun generateMaskAndPadForOutpainting( + image: ImagenInlineImage, + newDimensions: Dimensions, + newPosition: ImagenImagePlacement = ImagenImagePlacement.CENTER, + dilation: Double = 0.01 ): List { val originalBitmap = image.asBitmap() if ( @@ -180,7 +203,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), ) } }