Refacto lsbset.reveal to use getpixel

This commit is contained in:
Flavien 2022-11-08 21:44:43 +01:00
parent 257d2c2f68
commit 58dbb94c5e

View file

@ -25,11 +25,8 @@ __date__ = "$Date: 2016/03/13 $"
__revision__ = "$Date: 2019/05/31 $"
__license__ = "GPLv3"
import sys
from typing import IO, Iterator, Union
from PIL import Image
from stegano import tools
@ -120,8 +117,16 @@ def reveal(
while True:
generated_number = next(generator)
# color = [r, g, b]
for color in img_list[generated_number][:3]: # ignore the alpha
col = generated_number % width
row = int(generated_number / width)
# pixel = [r, g, b] or [r,g,b,a]
pixel = img.getpixel((col, row))
if img.mode == "RGBA":
pixel = pixel[:3] # ignore the alpha
for color in pixel:
buff += (color & 1) << (tools.ENCODINGS[encoding] - 1 - count)
count += 1
if count == tools.ENCODINGS[encoding]:
@ -132,5 +137,6 @@ def reveal(
limit = int("".join(bitab[:-1]))
else:
raise IndexError("Impossible to detect message.")
if len(bitab) - len(str(limit)) - 1 == limit:
return "".join(bitab)[len(str(limit)) + 1 :]