@@ -11,8 +11,11 @@ import com.google.firebase.ai.type.GenerativeBackend
11
11
import com.google.firebase.ai.type.ImagenBackgroundMask
12
12
import com.google.firebase.ai.type.ImagenEditMode
13
13
import com.google.firebase.ai.type.ImagenEditingConfig
14
+ import com.google.firebase.ai.type.ImagenForegroundMask
15
+ import com.google.firebase.ai.type.ImagenImagePlacement
14
16
import com.google.firebase.ai.type.ImagenMaskReference
15
17
import com.google.firebase.ai.type.ImagenRawImage
18
+ import com.google.firebase.ai.type.ImagenRawMask
16
19
import com.google.firebase.ai.type.ImagenStyleReference
17
20
import com.google.firebase.ai.type.ImagenSubjectReference
18
21
import com.google.firebase.ai.type.ImagenSubjectReferenceType
@@ -150,7 +153,7 @@ val FIREBASE_AI_SAMPLES = listOf(
150
153
)
151
154
},
152
155
allowEmptyPrompt = false ,
153
- generateImages = { model: ImagenModel , inputText: String , _: Bitmap ? ->
156
+ generateImages = { model: ImagenModel , inputText: String , _: Bitmap ? , _ ->
154
157
model.generateImages(
155
158
inputText
156
159
)
@@ -166,9 +169,14 @@ val FIREBASE_AI_SAMPLES = listOf(
166
169
initialPrompt = content { text(" A sunny beach" ) },
167
170
includeAttach = true ,
168
171
allowEmptyPrompt = true ,
169
- generateImages = { model: ImagenModel , inputText: String , bitmap: Bitmap ? ->
172
+ radioOptions = listOf (" Background" , " Foreground" ),
173
+ generateImages = { model: ImagenModel , inputText: String , bitmap: Bitmap ? , selectedRadioOption: String? ->
174
+ val mask = when (selectedRadioOption) {
175
+ " Foreground" -> ImagenForegroundMask ()
176
+ else -> ImagenBackgroundMask ()
177
+ }
170
178
model.editImage(
171
- listOf (ImagenRawImage (bitmap!! .toImagenInlineImage()), ImagenBackgroundMask () ),
179
+ listOfNotNull (ImagenRawImage (bitmap!! .toImagenInlineImage()), mask ),
172
180
inputText,
173
181
ImagenEditingConfig (ImagenEditMode .INPAINT_INSERTION )
174
182
)
@@ -184,10 +192,23 @@ val FIREBASE_AI_SAMPLES = listOf(
184
192
initialPrompt = content { text(" " ) },
185
193
includeAttach = true ,
186
194
allowEmptyPrompt = true ,
187
- generateImages = { model: ImagenModel , inputText: String , bitmap: Bitmap ? ->
195
+ radioOptions = listOf (" Center" , " Top" , " Bottom" , " Left" , " Right" ),
196
+ generateImages = { model: ImagenModel , inputText: String , bitmap: Bitmap ? , selectedRadioOption: String? ->
197
+ val position = when (selectedRadioOption) {
198
+ " Top" -> ImagenImagePlacement .TOP_CENTER
199
+ " Bottom" -> ImagenImagePlacement .BOTTOM_CENTER
200
+ " Left" -> ImagenImagePlacement .LEFT_CENTER
201
+ " Right" -> ImagenImagePlacement .RIGHT_CENTER
202
+ else -> ImagenImagePlacement .CENTER
203
+ }
188
204
val dimensions = Dimensions (bitmap!! .width * 2 , bitmap.height * 2 )
205
+ val (sourceImage, mask) = ImagenMaskReference .generateMaskAndPadForOutpainting(
206
+ bitmap.toImagenInlineImage(),
207
+ dimensions,
208
+ position
209
+ )
189
210
model.editImage(
190
- ImagenMaskReference .generateMaskAndPadForOutpainting(bitmap.toImagenInlineImage(), dimensions ),
211
+ listOf (sourceImage, ImagenRawMask (mask.image !! , 0.05 ) ),
191
212
inputText,
192
213
ImagenEditingConfig (ImagenEditMode .OUTPAINT )
193
214
)
@@ -203,7 +224,7 @@ val FIREBASE_AI_SAMPLES = listOf(
203
224
initialPrompt = content { text(" <subject> flying through space" ) },
204
225
includeAttach = true ,
205
226
allowEmptyPrompt = false ,
206
- generateImages = { model: ImagenModel , inputText: String , bitmap: Bitmap ? ->
227
+ generateImages = { model: ImagenModel , inputText: String , bitmap: Bitmap ? , _ ->
207
228
model.editImage(
208
229
listOf (
209
230
ImagenSubjectReference (
@@ -228,7 +249,7 @@ val FIREBASE_AI_SAMPLES = listOf(
228
249
initialPrompt = content { text(" A picture of a cat" ) },
229
250
includeAttach = true ,
230
251
allowEmptyPrompt = true ,
231
- generateImages = { model: ImagenModel , inputText: String , bitmap: Bitmap ? ->
252
+ generateImages = { model: ImagenModel , inputText: String , bitmap: Bitmap ? , _ ->
232
253
model.editImage(
233
254
listOf (
234
255
ImagenRawImage (MainActivity .catImage.toImagenInlineImage()),
0 commit comments