diff --git a/submodules/DrawingUI/Sources/DrawingScreen.swift b/submodules/DrawingUI/Sources/DrawingScreen.swift index f903998c0e..d9f7e95196 100644 --- a/submodules/DrawingUI/Sources/DrawingScreen.swift +++ b/submodules/DrawingUI/Sources/DrawingScreen.swift @@ -1200,6 +1200,11 @@ private final class DrawingScreenComponent: CombinedComponent { .opacity(controlsAreVisible ? 1.0 : 0.0) ) + var additionalBottomInset: CGFloat = 0.0 + if component.sourceHint == .storyEditor { + additionalBottomInset = max(0.0, previewBottomInset - environment.safeInsets.bottom - 49.0) + } + if let textEntity = state.selectedEntity as? DrawingTextEntity { let textSettings = textSettings.update( component: TextSettingsComponent( @@ -1277,7 +1282,7 @@ private final class DrawingScreenComponent: CombinedComponent { transition: context.transition ) context.add(textSettings - .position(CGPoint(x: context.availableSize.width / 2.0, y: context.availableSize.height - environment.safeInsets.bottom - textSettings.size.height / 2.0 - 89.0)) + .position(CGPoint(x: context.availableSize.width / 2.0, y: context.availableSize.height - environment.safeInsets.bottom - textSettings.size.height / 2.0 - 89.0 - additionalBottomInset)) .appear(Transition.Appear({ _, view, transition in if let view = view as? TextSettingsComponent.View, !transition.animation.isImmediate { view.animateIn() @@ -1293,11 +1298,6 @@ private final class DrawingScreenComponent: CombinedComponent { ) } - var additionalBottomInset: CGFloat = 0.0 - if component.sourceHint == .storyEditor { - additionalBottomInset = max(0.0, previewBottomInset - environment.safeInsets.bottom - 49.0) - } - let rightButtonPosition = rightEdge - 24.0 var offsetX: CGFloat = leftEdge + 24.0 let delta: CGFloat = (rightButtonPosition - offsetX) / 7.0 diff --git a/submodules/TelegramUI/Components/MediaEditor/MetalResources/EditorVideo.metal b/submodules/TelegramUI/Components/MediaEditor/MetalResources/EditorVideo.metal index ac60ab77da..24d0047e79 100644 --- a/submodules/TelegramUI/Components/MediaEditor/MetalResources/EditorVideo.metal +++ b/submodules/TelegramUI/Components/MediaEditor/MetalResources/EditorVideo.metal @@ -4,6 +4,30 @@ using namespace metal; +static inline +float sRGB_nonLinearNormToLinear(float normV) +{ + if (normV <= 0.04045f) { + normV *= (1.0f / 12.92f); + } else { + const float a = 0.055f; + const float gamma = 2.4f; + //const float gamma = 1.0f / (1.0f / 2.4f); + normV = (normV + a) * (1.0f / (1.0f + a)); + normV = pow(normV, gamma); + } + + return normV; +} + +static inline +float4 sRGB_gamma_decode(const float4 rgba) { + rgba.r = sRGB_nonLinearNormToLinear(rgba.r); + rgba.g = sRGB_nonLinearNormToLinear(rgba.g); + rgba.b = sRGB_nonLinearNormToLinear(rgba.b); + return rgba; +} + static inline float4 BT709_decode(const float Y, const float Cb, const float Cr) { float Yn = Y; @@ -13,8 +37,8 @@ static inline float4 BT709_decode(const float Y, const float Cb, const float Cr) float3 YCbCr = float3(Yn, Cbn, Crn); const float3x3 kColorConversion709 = float3x3(float3(1.0, 1.0, 1.0), - float3(0.0f, -0.1873, 1.8556), - float3(1.5748, -0.4681, 0.0)); + float3(0.0f, -0.18732, 1.8556), + float3(1.5748, -0.46812, 0.0)); float3 rgb = kColorConversion709 * YCbCr; @@ -23,7 +47,6 @@ static inline float4 BT709_decode(const float Y, const float Cb, const float Cr) return float4(rgb.r, rgb.g, rgb.b, 1.0f); } - fragment float4 bt709ToRGBFragmentShader(RasterizerData in [[stage_in]], texture2d inYTexture [[texture(0)]], texture2d inUVTexture [[texture(1)]] @@ -38,5 +61,7 @@ fragment float4 bt709ToRGBFragmentShader(RasterizerData in [[stage_in]], float Cr = float(uvSamples[1]); float4 pixel = BT709_decode(Y, Cb, Cr); + pixel = sRGB_gamma_decode(pixel); + pixel.rgb = pow(pixel.rgb, 1.0 / 2.2); return pixel; } diff --git a/submodules/TelegramUI/Components/MediaEditor/Sources/VideoTextureSource.swift b/submodules/TelegramUI/Components/MediaEditor/Sources/VideoTextureSource.swift index a2c9051877..f87426ee1c 100644 --- a/submodules/TelegramUI/Components/MediaEditor/Sources/VideoTextureSource.swift +++ b/submodules/TelegramUI/Components/MediaEditor/Sources/VideoTextureSource.swift @@ -273,7 +273,7 @@ final class VideoInputPass: DefaultRenderPass { textureDescriptor.textureType = .type2D textureDescriptor.width = outputWidth textureDescriptor.height = outputHeight - textureDescriptor.pixelFormat = .bgra8Unorm + textureDescriptor.pixelFormat = self.pixelFormat textureDescriptor.storageMode = .private textureDescriptor.usage = [.shaderRead, .shaderWrite, .renderTarget] if let texture = device.makeTexture(descriptor: textureDescriptor) {