Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package com.google.jetpackcamera.model

import com.google.jetpackcamera.model.proto.AspectRatio as AspectRatioProto

enum class AspectRatio(val numerator: Int, val denominator: Int) {
THREE_FOUR(3, 4),
NINE_SIXTEEN(9, 16),
Expand All @@ -31,21 +29,4 @@ enum class AspectRatio(val numerator: Int, val denominator: Int) {
* Returns the landscape aspect ratio as a [Float].
*/
fun toLandscapeFloat(): Float = denominator.toFloat() / numerator

companion object {

/** returns the AspectRatio enum equivalent of a provided AspectRatioProto */
fun fromProto(aspectRatioProto: AspectRatioProto): AspectRatio {
return when (aspectRatioProto) {
AspectRatioProto.ASPECT_RATIO_NINE_SIXTEEN -> NINE_SIXTEEN
AspectRatioProto.ASPECT_RATIO_ONE_ONE -> ONE_ONE

// defaults to 3:4 aspect ratio
AspectRatioProto.ASPECT_RATIO_THREE_FOUR,
AspectRatioProto.ASPECT_RATIO_UNDEFINED,
AspectRatioProto.UNRECOGNIZED
-> THREE_FOUR
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
*/
package com.google.jetpackcamera.model

import android.util.Base64
import com.google.jetpackcamera.model.LensFacing.Companion.toProto
import com.google.jetpackcamera.model.TestPattern.Companion.toProto
import com.google.jetpackcamera.model.proto.DebugSettings as DebugSettingsProto
import com.google.jetpackcamera.model.proto.debugSettings as debugSettingsProto

/**
* Data class for defining settings used in debug flows within the app.
*
Expand All @@ -35,67 +29,4 @@ data class DebugSettings(
val isDebugModeEnabled: Boolean = false,
val singleLensMode: LensFacing? = null,
val testPattern: TestPattern = TestPattern.Off
) {
companion object {
/**
* Creates a [DebugSettings] domain model from its protobuf representation.
*
* @param proto The [DebugSettingsProto] instance.
* @return The corresponding [DebugSettings] instance.
*/
fun fromProto(proto: DebugSettingsProto): DebugSettings {
return DebugSettings(
isDebugModeEnabled = proto.isDebugModeEnabled,
singleLensMode = if (proto.hasSingleLensMode()) {
LensFacing.fromProto(proto.singleLensMode)
} else {
null
},
testPattern = TestPattern.fromProto(proto.testPattern)
)
}

/**
* Converts a [DebugSettings] domain model to its protobuf representation.
*
* @receiver The [DebugSettings] instance to convert.
* @return The corresponding [DebugSettingsProto] instance.
*/
fun DebugSettings.toProto(): DebugSettingsProto = debugSettingsProto {
isDebugModeEnabled = this@toProto.isDebugModeEnabled
this@toProto.singleLensMode?.let { lensFacing ->
singleLensMode = lensFacing.toProto()
}
testPattern = this@toProto.testPattern.toProto()
}

/**
* Parses the encoded byte array into a [DebugSettings] instance.
*/
fun parseFromByteArray(value: ByteArray): DebugSettings {
val protoValue = DebugSettingsProto.parseFrom(value)
return fromProto(protoValue)
}

/**
* Parses the Base64 encoded string into a [DebugSettings] instance.
*/
fun parseFromString(value: String): DebugSettings {
val decodedBytes = Base64.decode(value, Base64.NO_WRAP)
return parseFromByteArray(decodedBytes)
}

/**
* Encodes the [DebugSettings] data class into a byte array.
*/
fun DebugSettings.encodeAsByteArray(): ByteArray = this.toProto().toByteArray()

/**
* Encodes the [DebugSettings] data class to a Base64 string.
*/
fun DebugSettings.encodeAsString(): String {
val protoValue = this.toProto() // Data class -> Proto
return Base64.encodeToString(protoValue.toByteArray(), Base64.NO_WRAP)
}
}
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,10 @@
* limitations under the License.
*/
package com.google.jetpackcamera.model
import com.google.jetpackcamera.model.proto.DynamicRange as DynamicRangeProto

val DEFAULT_HDR_DYNAMIC_RANGE = DynamicRange.HLG10

enum class DynamicRange {
SDR,
HLG10;

companion object {

/** returns the DynamicRangeType enum equivalent of a provided DynamicRangeTypeProto */
fun fromProto(dynamicRangeProto: DynamicRangeProto): DynamicRange {
return when (dynamicRangeProto) {
DynamicRangeProto.DYNAMIC_RANGE_HLG10 -> HLG10

// Treat unrecognized and unspecified as SDR as a fallback
DynamicRangeProto.DYNAMIC_RANGE_SDR,
DynamicRangeProto.DYNAMIC_RANGE_UNSPECIFIED,
DynamicRangeProto.UNRECOGNIZED -> SDR
}
}

fun DynamicRange.toProto(): DynamicRangeProto {
return when (this) {
SDR -> DynamicRangeProto.DYNAMIC_RANGE_SDR
HLG10 -> DynamicRangeProto.DYNAMIC_RANGE_HLG10
}
}
}
HLG10
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,9 @@
*/
package com.google.jetpackcamera.model

import com.google.jetpackcamera.model.proto.ImageOutputFormat as ImageOutputFormatProto

val DEFAULT_HDR_IMAGE_OUTPUT = ImageOutputFormat.JPEG_ULTRA_HDR

enum class ImageOutputFormat {
JPEG,
JPEG_ULTRA_HDR;

companion object {

/** returns the DynamicRangeType enum equivalent of a provided DynamicRangeTypeProto */
fun fromProto(imageOutputFormatProto: ImageOutputFormatProto): ImageOutputFormat {
return when (imageOutputFormatProto) {
ImageOutputFormatProto.IMAGE_OUTPUT_FORMAT_JPEG_ULTRA_HDR -> JPEG_ULTRA_HDR

// Treat unrecognized as JPEG as a fallback
ImageOutputFormatProto.IMAGE_OUTPUT_FORMAT_JPEG,
ImageOutputFormatProto.UNRECOGNIZED -> JPEG
}
}

fun ImageOutputFormat.toProto(): ImageOutputFormatProto {
return when (this) {
JPEG -> ImageOutputFormatProto.IMAGE_OUTPUT_FORMAT_JPEG
JPEG_ULTRA_HDR -> ImageOutputFormatProto.IMAGE_OUTPUT_FORMAT_JPEG_ULTRA_HDR
}
}
}
JPEG_ULTRA_HDR
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package com.google.jetpackcamera.model

import com.google.jetpackcamera.model.proto.LensFacing as LensFacingProto

enum class LensFacing {
BACK,
FRONT;
Expand All @@ -27,25 +25,4 @@ enum class LensFacing {
BACK -> FRONT
}
}

companion object {

/** returns the LensFacing enum equivalent of a provided LensFacingProto */
fun fromProto(lensFacingProto: LensFacingProto): LensFacing {
return when (lensFacingProto) {
LensFacingProto.LENS_FACING_BACK -> BACK

// Treat unrecognized as front as a fallback
LensFacingProto.LENS_FACING_FRONT,
LensFacingProto.UNRECOGNIZED -> FRONT
}
}

fun LensFacing.toProto(): LensFacingProto {
return when (this) {
BACK -> LensFacingProto.LENS_FACING_BACK
FRONT -> LensFacingProto.LENS_FACING_FRONT
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,7 @@
*/
package com.google.jetpackcamera.model

import com.google.jetpackcamera.model.proto.LowLightBoostPriority as LowLightBoostPriorityProto

enum class LowLightBoostPriority {
PRIORITIZE_AE_MODE,
PRIORITIZE_GOOGLE_PLAY_SERVICES;

companion object {
/**
* Returns the [LowLightBoostPriority] enum equivalent of a provided [LowLightBoostPriorityProto].
*
* @param lowLightBoostPriorityProto The proto to convert from.
* @return The converted [LowLightBoostPriority].
*/
fun fromProto(
lowLightBoostPriorityProto: LowLightBoostPriorityProto
): LowLightBoostPriority {
return when (lowLightBoostPriorityProto) {
LowLightBoostPriorityProto.LOW_LIGHT_BOOST_PRIORITY_AE_MODE -> PRIORITIZE_AE_MODE
LowLightBoostPriorityProto.LOW_LIGHT_BOOST_PRIORITY_GOOGLE_PLAY_SERVICES ->
PRIORITIZE_GOOGLE_PLAY_SERVICES
LowLightBoostPriorityProto.UNRECOGNIZED -> PRIORITIZE_AE_MODE // Default to AE mode
}
}

fun LowLightBoostPriority.toProto(): LowLightBoostPriorityProto {
return when (this) {
PRIORITIZE_AE_MODE -> LowLightBoostPriorityProto.LOW_LIGHT_BOOST_PRIORITY_AE_MODE
PRIORITIZE_GOOGLE_PLAY_SERVICES ->
LowLightBoostPriorityProto.LOW_LIGHT_BOOST_PRIORITY_GOOGLE_PLAY_SERVICES
}
}
}
PRIORITIZE_GOOGLE_PLAY_SERVICES
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package com.google.jetpackcamera.model

import com.google.jetpackcamera.model.proto.StabilizationMode as StabilizationModeProto

/** Enum class representing the device's supported stabilization configurations. */
enum class StabilizationMode {
/** Stabilization off */
Expand All @@ -36,22 +34,5 @@ enum class StabilizationMode {
HIGH_QUALITY,

/** Optical Stabilization (OIS) */
OPTICAL;

companion object {
/** returns the AspectRatio enum equivalent of a provided AspectRatioProto */
fun fromProto(stabilizationModeProto: StabilizationModeProto): StabilizationMode =
when (stabilizationModeProto) {
StabilizationModeProto.STABILIZATION_MODE_OFF -> OFF
StabilizationModeProto.STABILIZATION_MODE_ON -> ON
StabilizationModeProto.STABILIZATION_MODE_HIGH_QUALITY -> HIGH_QUALITY
StabilizationModeProto.STABILIZATION_MODE_OPTICAL -> OPTICAL

// Default to AUTO
StabilizationModeProto.STABILIZATION_MODE_UNDEFINED,
StabilizationModeProto.UNRECOGNIZED,
StabilizationModeProto.STABILIZATION_MODE_AUTO
-> AUTO
}
}
OPTICAL
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@
*/
package com.google.jetpackcamera.model

import com.google.jetpackcamera.model.proto.TestPattern as ProtoTestPattern
import com.google.jetpackcamera.model.proto.TestPattern.PatternCase
import com.google.jetpackcamera.model.proto.testPattern as protoTestPattern
import com.google.jetpackcamera.model.proto.testPatternColorBars
import com.google.jetpackcamera.model.proto.testPatternColorBarsFadeToGray
import com.google.jetpackcamera.model.proto.testPatternCustom1
import com.google.jetpackcamera.model.proto.testPatternOff
import com.google.jetpackcamera.model.proto.testPatternPN9
import com.google.jetpackcamera.model.proto.testPatternSolidColor

/**
* Represents a test pattern to replace sensor pixel data.
*
Expand Down Expand Up @@ -179,56 +169,4 @@ sealed interface TestPattern {
)
}
}

companion object {
/**
* Converts a [TestPattern] sealed interface instance to its Protocol Buffer representation
* ([ProtoTestPattern]).
*/
fun TestPattern.toProto(): ProtoTestPattern {
return protoTestPattern {
when (val pattern = this@toProto) {
is Off -> off = testPatternOff {}
is ColorBars -> colorBars = testPatternColorBars {}
is ColorBarsFadeToGray ->
colorBarsFadeToGray = testPatternColorBarsFadeToGray {}
is PN9 -> pn9 = testPatternPN9 {}
is Custom1 -> custom1 = testPatternCustom1 {}
is SolidColor -> solidColor = testPatternSolidColor {
red = pattern.red.toInt()
greenEven = pattern.greenEven.toInt()
greenOdd = pattern.greenOdd.toInt()
blue = pattern.blue.toInt()
}
}
}
}

/**
* Converts a [ProtoTestPattern] Protocol Buffer message to its Kotlin [TestPattern] sealed
* interface representation.
*/
fun fromProto(proto: ProtoTestPattern): TestPattern {
return when (proto.patternCase) {
PatternCase.OFF,
PatternCase.PATTERN_NOT_SET -> {
// Default to Off if the oneof is not set
Off
}
PatternCase.COLOR_BARS -> ColorBars
PatternCase.COLOR_BARS_FADE_TO_GRAY -> ColorBarsFadeToGray
PatternCase.PN9 -> PN9
PatternCase.CUSTOM1 -> Custom1
PatternCase.SOLID_COLOR -> {
val protoSolidColor = proto.solidColor
SolidColor(
red = protoSolidColor.red.toUInt(),
greenEven = protoSolidColor.greenEven.toUInt(),
greenOdd = protoSolidColor.greenOdd.toUInt(),
blue = protoSolidColor.blue.toUInt()
)
}
}
}
}
}
Loading
Loading