Дешифровка текста из картинки

This commit is contained in:
2024-11-19 13:56:31 +03:00
parent 3205247f1c
commit 2dedc4416a
2 changed files with 41 additions and 13 deletions

View File

@@ -95,3 +95,21 @@ encodePixel bitsPerByte img bits x y = PixelRGB8 newR newG newB
newR = intToWord8 $ ((word8ToInt r) .&. mask) .|. bitsIntR
newG = intToWord8 $ ((word8ToInt g) .&. mask) .|. bitsIntG
newB = intToWord8 $ ((word8ToInt b) .&. mask) .|. bitsIntB
extractBits :: Int -> Pixel8 -> [Int]
extractBits bitsPerByte pixelByte =
[ if testBit pixelByte i then 1 else 0 | i <- [bitsPerByte-1, bitsPerByte-2..0] ]
extractBitsFromPixel :: Int -> PixelRGB8 -> [Int]
extractBitsFromPixel bitsPerByte (PixelRGB8 r g b) =
let bitsR = extractBits bitsPerByte r
bitsG = extractBits bitsPerByte g
bitsB = extractBits bitsPerByte b
in bitsR ++ bitsG ++ bitsB
extractBitsFromImage :: Int -> Image PixelRGB8 -> [Int]
extractBitsFromImage bitsPerByte img =
let width = imageWidth img
height = imageHeight img
pixels = [ pixelAt img x y | y <- [0..height - 1], x <- [0..width - 1] ]
in concatMap (extractBitsFromPixel bitsPerByte) pixels