Skip to content

Commit 6ffe650

Browse files
fix: code cleanup. prevent further execution if bitmap is null
1 parent b55bb9a commit 6ffe650

File tree

1 file changed

+8
-6
lines changed
  • library/src/main/kotlin/dev/jahir/kuper/data/models

1 file changed

+8
-6
lines changed

library/src/main/kotlin/dev/jahir/kuper/data/models/Component.kt

+8-6
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,19 @@ data class Component(
9393

9494
val width = bitmap.width
9595
val height = bitmap.height
96-
val pixels = IntArray(width * height)
97-
bitmap.getPixels(pixels, 0, width, 0, 0, width, height)
96+
97+
val newBitmap = bitmap.config?.let { Bitmap.createBitmap(width, height, it) }
98+
newBitmap ?: return bitmap
9899

99100
var minX = width
100101
var minY = height
101102
var maxX = -1
102103
var maxY = -1
103104

104-
val newBitmap = bitmap.config?.let { Bitmap.createBitmap(width, height, it) }
105-
var pixel: Int
105+
val pixels = IntArray(width * height)
106+
bitmap.getPixels(pixels, 0, width, 0, 0, width, height)
106107

108+
var pixel: Int
107109
for (y in 0 until height) {
108110
for (x in 0 until width) {
109111
val index = y * width + x
@@ -120,8 +122,8 @@ data class Component(
120122
}
121123
}
122124

123-
newBitmap?.setPixels(pixels, 0, width, 0, 0, width, height)
124-
return newBitmap?.let { Bitmap.createBitmap(it, minX, minY, maxX - minX + 1, maxY - minY + 1) } ?: bitmap
125+
newBitmap.setPixels(pixels, 0, width, 0, 0, width, height)
126+
return Bitmap.createBitmap(newBitmap, minX, minY, maxX - minX + 1, maxY - minY + 1)
125127
}
126128
}
127129
}

0 commit comments

Comments
 (0)