From 5711244be4698447f5ea768d1ddba2540ae616c1 Mon Sep 17 00:00:00 2001 From: Arity-T Date: Mon, 18 Nov 2024 02:07:14 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BA=D0=B0=D0=B6=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B8=20=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B8=D0=B7=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lab3/app/Main.hs | 6 ++++-- lab3/src/Lib.hs | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lab3/app/Main.hs b/lab3/app/Main.hs index a82cd5b..297644f 100644 --- a/lab3/app/Main.hs +++ b/lab3/app/Main.hs @@ -27,5 +27,7 @@ main = do Left err -> putStrLn $ "Ошибка при чтении изображения: " ++ err Right dynImg -> do let img = convertRGB8 dynImg - putStrLn $ "Ширина: " ++ show (imageWidth img) - putStrLn $ "Высота: " ++ show (imageHeight img) \ No newline at end of file + let width = imageWidth img + let height = imageHeight img + let resultImage = generateImage (encodePixel 1 img encryptedTextBits) width height + saveBmpImage "tmp/david.bmp" (ImageRGB8 resultImage) diff --git a/lab3/src/Lib.hs b/lab3/src/Lib.hs index 8a3f3db..192ffc9 100644 --- a/lab3/src/Lib.hs +++ b/lab3/src/Lib.hs @@ -4,9 +4,12 @@ module Lib encryptCaesar, decryptCaesar, textToBits, - bitsToText + bitsToText, + encodePixel ) where +import Codec.Picture + import Data.Char (ord, chr) import Data.Bits (testBit) import qualified Data.Vector.Unboxed as VU @@ -47,4 +50,12 @@ bitsToText bits | otherwise = (chr $ bitsToInt (VU.take 8 bits)) : bitsToText (VU.drop 8 bits) where bitsToInt charBits = - sum [bit * (2 ^ index) | (bit, index) <- zip (VU.toList charBits) [7 :: Int,6..0]] \ No newline at end of file + sum [bit * (2 ^ index) | (bit, index) <- zip (VU.toList charBits) [7 :: Int,6..0]] + +encodePixel :: Int -> Image PixelRGB8 -> VU.Vector Int -> Int -> Int -> PixelRGB8 +encodePixel encodeBitsCount img bits x y = PixelRGB8 newR newG newB + where + PixelRGB8 r g b = pixelAt img x y + newR = b + newG = g + newB = r