Искажение и сохранение изображения
This commit is contained in:
@@ -27,5 +27,7 @@ main = do
|
|||||||
Left err -> putStrLn $ "Ошибка при чтении изображения: " ++ err
|
Left err -> putStrLn $ "Ошибка при чтении изображения: " ++ err
|
||||||
Right dynImg -> do
|
Right dynImg -> do
|
||||||
let img = convertRGB8 dynImg
|
let img = convertRGB8 dynImg
|
||||||
putStrLn $ "Ширина: " ++ show (imageWidth img)
|
let width = imageWidth img
|
||||||
putStrLn $ "Высота: " ++ show (imageHeight img)
|
let height = imageHeight img
|
||||||
|
let resultImage = generateImage (encodePixel 1 img encryptedTextBits) width height
|
||||||
|
saveBmpImage "tmp/david.bmp" (ImageRGB8 resultImage)
|
||||||
|
|||||||
@@ -4,9 +4,12 @@ module Lib
|
|||||||
encryptCaesar,
|
encryptCaesar,
|
||||||
decryptCaesar,
|
decryptCaesar,
|
||||||
textToBits,
|
textToBits,
|
||||||
bitsToText
|
bitsToText,
|
||||||
|
encodePixel
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
import Codec.Picture
|
||||||
|
|
||||||
import Data.Char (ord, chr)
|
import Data.Char (ord, chr)
|
||||||
import Data.Bits (testBit)
|
import Data.Bits (testBit)
|
||||||
import qualified Data.Vector.Unboxed as VU
|
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)
|
| otherwise = (chr $ bitsToInt (VU.take 8 bits)) : bitsToText (VU.drop 8 bits)
|
||||||
where
|
where
|
||||||
bitsToInt charBits =
|
bitsToInt charBits =
|
||||||
sum [bit * (2 ^ index) | (bit, index) <- zip (VU.toList charBits) [7 :: Int,6..0]]
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user