mirror of
https://github.com/cedricbonhomme/Stegano.git
synced 2025-05-12 17:18:30 +02:00
Refacto lsbset.reveal to use getpixel
This commit is contained in:
parent
257d2c2f68
commit
58dbb94c5e
1 changed files with 11 additions and 5 deletions
|
@ -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 :]
|
||||
|
|
Loading…
Add table
Reference in a new issue