Skip to content

Commit a48f7ac

Browse files
author
David Motsonashvili
committed
fixing refdocs for comments, and adding error for incorrect call to outpainting
1 parent 7ed0bd7 commit a48f7ac

File tree

6 files changed

+41
-48
lines changed

6 files changed

+41
-48
lines changed

firebase-ai/src/main/kotlin/com/google/firebase/ai/ImagenModel.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ internal constructor(
9393
* Generates an image from a single or set of base images, returning the result directly to the
9494
* caller.
9595
*
96-
* @param prompt the text input given to the model as a prompt
9796
* @param referenceImages the image inputs given to the model as a prompt
97+
* @param prompt the text input given to the model as a prompt
9898
* @param config the editing configuration settings
9999
*/
100100
public suspend fun editImage(
@@ -112,12 +112,14 @@ internal constructor(
112112
}
113113

114114
/**
115-
* Generates an image by inpainting a masked off part of a base image.
115+
* Generates an image by inpainting a masked off part of a base image. Inpainting is the process
116+
* of filling in missing or masked off parts of the image using context from the original image
117+
* and prompt.
116118
*
117119
* @param image the base image
118120
* @param prompt the text input given to the model as a prompt
119-
* @param mask the mask which defines where in the image can be painted by imagen.
120-
* @param config the editing configuration settings, its important to include an [ImagenEditMode]
121+
* @param mask the mask which defines where in the image can be painted by Imagen.
122+
* @param config the editing configuration settings, it should include an [ImagenEditMode]
121123
*/
122124
public suspend fun inpaintImage(
123125
image: ImagenInlineImage,
@@ -129,15 +131,16 @@ internal constructor(
129131
}
130132

131133
/**
132-
* Generates an image by outpainting the image, extending its borders
134+
* Generates an image by outpainting the given image, extending its content beyond the original
135+
* borders using context from the original image, and optionally, the prompt.
133136
*
134137
* @param image the base image
135138
* @param newDimensions the new dimensions for the image, *must* be larger than the original
136139
* image.
137140
* @param newPosition the placement of the base image within the new image. This can either be
138141
* coordinates (0,0 is the top left corner) or an alignment (ex:
139142
* [ImagenImagePlacement.BOTTOM_CENTER])
140-
* @param prompt optional, but can be used to specify the background generated if context is
143+
* @param prompt optional, can be used to specify the background generated if context is
141144
* insufficient
142145
* @param config the editing configuration settings
143146
* @see [ImagenMaskReference.generateMaskAndPadForOutpainting]

firebase-ai/src/main/kotlin/com/google/firebase/ai/java/ImagenModelFutures.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public abstract class ImagenModelFutures internal constructor() {
6565
* @param image the base image
6666
* @param prompt the text input given to the model as a prompt
6767
* @param mask the mask which defines where in the image can be painted by imagen.
68-
* @param config the editing configuration settings, its important to include an [ImagenEditMode]
68+
* @param config the editing configuration settings, it should include an [ImagenEditMode]
6969
*/
7070
public abstract fun inpaintImage(
7171
image: ImagenInlineImage,

firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenControlType.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@ package com.google.firebase.ai.type
1818
/** Represents a control type for controlled Imagen generation/editing */
1919
public class ImagenControlType internal constructor(internal val value: String) {
2020
public companion object {
21-
/** Canny Control uses edge detection to ensure the new image follow the same outlines */
21+
/** Use edge detection to ensure the new image follow the same outlines */
2222
public val CANNY: ImagenControlType = ImagenControlType("CONTROL_TYPE_CANNY")
23-
/**
24-
* Scribble Control uses enhanced edge detection to ensure the new image follow similar outlines
25-
*/
23+
/** Use enhanced edge detection to ensure the new image follow similar outlines */
2624
public val SCRIBBLE: ImagenControlType = ImagenControlType("CONTROL_TYPE_SCRIBBLE")
27-
/** Face mesh control is used to ensure that the new image has the same facial expressions */
25+
/** Use face mesh control to ensure that the new image has the same facial expressions */
2826
public val FACE_MESH: ImagenControlType = ImagenControlType("CONTROL_TYPE_FACE_MESH")
2927
/**
30-
* Color superpixels are a control mechanism used to ensure that the new image looks similar in
31-
* shape and color to the original
28+
* Use color superpixels to ensure that the new image is similar in shape and color to the
29+
* original
3230
*/
3331
public val COLOR_SUPERPIXEL: ImagenControlType =
3432
ImagenControlType("CONTROL_TYPE_COLOR_SUPERPIXEL")

firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenEditMode.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,11 @@ package com.google.firebase.ai.type
1919
public class ImagenEditMode private constructor(internal val value: String) {
2020

2121
public companion object {
22-
/** Inpainting insertion is used when inserting a new element into an image */
22+
/** Inserts a new element into an image */
2323
public val INPAINT_INSERTION: ImagenEditMode = ImagenEditMode("EDIT_MODE_INPAINT_INSERTION")
24-
/**
25-
* Inpainting removal is used when removing an element from an image, and replacing it with
26-
* background
27-
*/
24+
/** Removes an element from an image */
2825
public val INPAINT_REMOVAL: ImagenEditMode = ImagenEditMode("EDIT_MODE_INPAINT_REMOVAL")
29-
/** Outpainting is used to extend the borders of an image outwards */
26+
/** Extend the borders of an image outwards */
3027
public val OUTPAINT: ImagenEditMode = ImagenEditMode("EDIT_MODE_OUTPAINT")
3128
}
3229
}

firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenImagePlacement.kt

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
package com.google.firebase.ai.type
1717

1818
/**
19-
* Represents where the placement of an image within a new, larger image, usually in the context of
20-
* an outpainting request.
19+
* Represents where the placement of an image is within a new, larger image, usually in the context
20+
* of an outpainting request.
2121
*/
2222
public class ImagenImagePlacement
2323
private constructor(public val x: Int? = null, public val y: Int? = null) {
@@ -67,7 +67,7 @@ private constructor(public val x: Int? = null, public val y: Int? = null) {
6767

6868
public companion object {
6969
/**
70-
* Creates an [ImagenImagePlacement] that represents a placement in the described by two
70+
* Creates an [ImagenImagePlacement] that represents a placement in an image described by two
7171
* coordinates. The coordinate system has 0,0 in the top left corner, and the x and y
7272
* coordinates represent the location of the top left corner of the original image.
7373
* @param x the x coordinate of the top left corner of the original image
@@ -77,37 +77,23 @@ private constructor(public val x: Int? = null, public val y: Int? = null) {
7777
return ImagenImagePlacement(x, y)
7878
}
7979

80-
/**
81-
* This [ImagenImagePlacement] is centered horizontally and vertically within the larger image
82-
*/
80+
/** Center the image horizontally and vertically within the larger image */
8381
public val CENTER: ImagenImagePlacement = ImagenImagePlacement()
84-
/**
85-
* This [ImagenImagePlacement] is centered horizontally and aligned with the top edge of the
86-
* larger image
87-
*/
82+
/** Center the image horizontally and aligned with the top edge of the larger image */
8883
public val TOP_CENTER: ImagenImagePlacement = ImagenImagePlacement()
89-
/**
90-
* This [ImagenImagePlacement] is centered horizontally and aligned with the bottom edge of the
91-
* larger image
92-
*/
84+
/** Center the image horizontally and aligned with the bottom edge of the larger image */
9385
public val BOTTOM_CENTER: ImagenImagePlacement = ImagenImagePlacement()
94-
/**
95-
* This [ImagenImagePlacement] is centered vertically and aligned with the left edge of the
96-
* larger image
97-
*/
86+
/** Center the image vertically and aligned with the left edge of the larger image */
9887
public val LEFT_CENTER: ImagenImagePlacement = ImagenImagePlacement()
99-
/**
100-
* This [ImagenImagePlacement] is centered vertically and aligned with the right edge of the
101-
* larger image
102-
*/
88+
/** Center the image vertically and aligned with the right edge of the larger image */
10389
public val RIGHT_CENTER: ImagenImagePlacement = ImagenImagePlacement()
104-
/** This [ImagenImagePlacement] is aligned with the top left corner of the larger image */
90+
/** Align the image with the top left corner of the larger image */
10591
public val TOP_LEFT: ImagenImagePlacement = ImagenImagePlacement(0, 0)
106-
/** This [ImagenImagePlacement] is aligned with the top right corner of the larger image */
92+
/** Align the image with the top right corner of the larger image */
10793
public val TOP_RIGHT: ImagenImagePlacement = ImagenImagePlacement()
108-
/** This [ImagenImagePlacement] is aligned with the bottom left corner of the larger image */
94+
/** Align the image with the bottom left corner of the larger image */
10995
public val BOTTOM_LEFT: ImagenImagePlacement = ImagenImagePlacement()
110-
/** This [ImagenImagePlacement] is caligned with the bottom right corner of the larger image */
96+
/** Align the image with the bottom right corner of the larger image */
11197
public val BOTTOM_RIGHT: ImagenImagePlacement = ImagenImagePlacement()
11298
}
11399
}

firebase-ai/src/main/kotlin/com/google/firebase/ai/type/ImagenReferenceImage.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ internal constructor(
7373
}
7474

7575
/**
76-
* Represents a refrence image (provided or generated) to bound the created image via ControlNet
76+
* Represents a reference image (provided or generated) to bound the created image via ControlNet
7777
* @param image the image provided, required if enableComputation is false
7878
* @param type the type of ControlNet reference image
7979
* @param referenceId the reference ID for this image, to be referenced in the prompt
@@ -112,7 +112,7 @@ internal constructor(maskConfig: ImagenMaskConfig, image: ImagenInlineImage? = n
112112

113113
public companion object {
114114
/**
115-
* Generates two reference images:
115+
* Generates these two reference images in order:
116116
* * One [ImagenRawImage] containing the original image, padded out to the new dimensions with
117117
* black pixels, with the original image placed at the given placement
118118
* * One [ImagenRawMask] of the same dimensions containing white everywhere except at the
@@ -131,6 +131,15 @@ internal constructor(maskConfig: ImagenMaskConfig, image: ImagenInlineImage? = n
131131
newPosition: ImagenImagePlacement = ImagenImagePlacement.CENTER,
132132
): List<ImagenReferenceImage> {
133133
val originalBitmap = image.asBitmap()
134+
if (
135+
originalBitmap.width > newDimensions.width || originalBitmap.height > newDimensions.height
136+
) {
137+
throw IllegalArgumentException(
138+
"New Dimensions must be strictly larger than original image dimensions. Original image " +
139+
"is:${originalBitmap.width}x${originalBitmap.height}, new dimensions are " +
140+
"${newDimensions.width}x${newDimensions.height}"
141+
)
142+
}
134143
val normalizedPosition =
135144
newPosition.normalizeToDimensions(
136145
Dimensions(originalBitmap.width, originalBitmap.height),

0 commit comments

Comments
 (0)