Rebrand from Casera/MyCrib to honeyDue
Total rebrand across KMM project: - Kotlin package: com.example.casera -> com.tt.honeyDue (dirs + declarations) - Gradle: rootProject.name, namespace, applicationId - Android: manifest, strings.xml (all languages), widget resources - iOS: pbxproj bundle IDs, Info.plist, entitlements, xcconfig - iOS directories: Casera/ -> HoneyDue/, CaseraTests/ -> HoneyDueTests/, etc. - Swift source: all class/struct/enum renames - Deep links: casera:// -> honeydue://, .casera -> .honeydue - App icons replaced with honeyDue honeycomb icon - Domains: casera.treytartt.com -> honeyDue.treytartt.com - Bundle IDs: com.tt.casera -> com.tt.honeyDue - Database table names preserved Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package com.tt.honeyDue.util
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import com.tt.honeyDue.platform.ImageData
|
||||
import java.io.ByteArrayOutputStream
|
||||
|
||||
/**
|
||||
* Android implementation of image compression
|
||||
* Compresses images to JPEG format and ensures they don't exceed MAX_IMAGE_SIZE_BYTES
|
||||
*/
|
||||
actual object ImageCompressor {
|
||||
/**
|
||||
* Compress an ImageData to JPEG format with size limit
|
||||
* @param imageData The image to compress
|
||||
* @return Compressed image data as ByteArray
|
||||
*/
|
||||
actual fun compressImage(imageData: ImageData): ByteArray {
|
||||
// Decode the original image
|
||||
val originalBitmap = BitmapFactory.decodeByteArray(
|
||||
imageData.bytes,
|
||||
0,
|
||||
imageData.bytes.size
|
||||
)
|
||||
|
||||
// Compress with iterative quality reduction
|
||||
return compressBitmapToTarget(originalBitmap, ImageConfig.MAX_IMAGE_SIZE_BYTES)
|
||||
}
|
||||
|
||||
/**
|
||||
* Compress a bitmap to target size
|
||||
*/
|
||||
private fun compressBitmapToTarget(bitmap: Bitmap, targetSizeBytes: Int): ByteArray {
|
||||
var quality = ImageConfig.INITIAL_JPEG_QUALITY
|
||||
var compressedData: ByteArray
|
||||
|
||||
do {
|
||||
val outputStream = ByteArrayOutputStream()
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream)
|
||||
compressedData = outputStream.toByteArray()
|
||||
|
||||
// If size is acceptable or quality is too low, stop
|
||||
if (compressedData.size <= targetSizeBytes || quality <= ImageConfig.MIN_JPEG_QUALITY) {
|
||||
break
|
||||
}
|
||||
|
||||
// Reduce quality for next iteration
|
||||
quality -= 5
|
||||
} while (true)
|
||||
|
||||
return compressedData
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user