Added border frame filter by #2380

This commit is contained in:
T8RIN 2025-12-26 18:46:05 +03:00
parent 7f9c21fb3d
commit ee8b700a7c
5 changed files with 106 additions and 1 deletions

View File

@ -361,6 +361,7 @@ interface Filter<Value : Any> : VisibilityOwner {
interface PulseGridPixelation : FloatFilter
interface NucleusPixelation : FloatFilter
interface RadialWeavePixelation : FloatFilter
interface BorderFrame : FloatColorModelFilter
}
interface SimpleFilter : Filter<Unit>

View File

@ -0,0 +1,43 @@
/*
* ImageToolbox is an image editor for android
* Copyright (c) 2025 T8RIN (Malik Mukhametzyanov)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* You should have received a copy of the Apache License
* along with this program. If not, see <http://www.apache.org/licenses/LICENSE-2.0>.
*/
package com.t8rin.imagetoolbox.core.filters.presentation.model
import androidx.compose.ui.graphics.Color
import com.t8rin.imagetoolbox.core.domain.model.ColorModel
import com.t8rin.imagetoolbox.core.filters.domain.model.Filter
import com.t8rin.imagetoolbox.core.filters.domain.model.FilterParam
import com.t8rin.imagetoolbox.core.resources.R
import com.t8rin.imagetoolbox.core.ui.utils.helper.toModel
class UiBorderFrameFilter(
override val value: Pair<Float, ColorModel> = 20f to Color.White.toModel()
) : UiFilter<Pair<Float, ColorModel>>(
title = R.string.border_frame,
value = value,
paramsInfo = listOf(
FilterParam(
title = R.string.border_thickness,
valueRange = 0f..500f,
roundTo = 0
),
FilterParam(
title = R.string.border_color,
valueRange = 0f..0f
)
)
), Filter.BorderFrame

View File

@ -274,7 +274,8 @@ sealed class UiFilter<T : Any>(
UiThresholdFilter(),
UiDoGFilter(),
UiErrorLevelAnalysisFilter(),
UiCopyMoveDetectionFilter()
UiCopyMoveDetectionFilter(),
UiBorderFrameFilter()
),
//Blur
listOf(

View File

@ -1894,4 +1894,5 @@
<string name="cannot_open_uri">Cannot open uri \"%s\"</string>
<string name="snowfall_mode">Snowfall Mode</string>
<string name="enabled">Enabled</string>
<string name="border_frame">Border Frame</string>
</resources>

View File

@ -0,0 +1,59 @@
/*
* ImageToolbox is an image editor for android
* Copyright (c) 2025 T8RIN (Malik Mukhametzyanov)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* You should have received a copy of the Apache License
* along with this program. If not, see <http://www.apache.org/licenses/LICENSE-2.0>.
*/
package com.t8rin.imagetoolbox.feature.filters.data.model
import android.graphics.Bitmap
import androidx.compose.ui.graphics.Color
import androidx.core.graphics.applyCanvas
import androidx.core.graphics.createBitmap
import com.t8rin.imagetoolbox.core.data.image.utils.ColorUtils.toModel
import com.t8rin.imagetoolbox.core.data.image.utils.drawBitmap
import com.t8rin.imagetoolbox.core.domain.model.ColorModel
import com.t8rin.imagetoolbox.core.domain.model.IntegerSize
import com.t8rin.imagetoolbox.core.domain.model.Position
import com.t8rin.imagetoolbox.core.domain.transformation.Transformation
import com.t8rin.imagetoolbox.core.filters.domain.model.Filter
import com.t8rin.imagetoolbox.core.ksp.annotations.FilterInject
import kotlin.math.roundToInt
@FilterInject
internal class BorderFrameFilter(
override val value: Pair<Float, ColorModel> = 20f to Color.White.toModel()
) : Transformation<Bitmap>, Filter.BorderFrame {
override val cacheKey: String
get() = value.hashCode().toString()
override suspend fun transform(
input: Bitmap,
size: IntegerSize
): Bitmap {
val size = value.first.roundToInt()
return createBitmap(
width = input.width + size * 2,
height = input.height + size * 2
).applyCanvas {
drawColor(value.second.colorInt)
drawBitmap(
bitmap = input,
position = Position.Center
)
}
}
}