Commit 3b0385f6 authored by Nathan/Eilisha Shiraini's avatar Nathan/Eilisha Shiraini
Browse files

Documented the interleaving module (and using correct terms)

parent d8df2102
from . import draw
from . import interpolate
\ No newline at end of file
from . import interleave
"""
Code interleaving modes
This module contains the various ways
by which multiple 2D codes can be combined
in the same image.
Each class in this module is an enumeration,
with the vaue being the table associating each code
with the list of colors to use to represent its modules
(that is, the color for value 0 and color for value 1).
Attributes
----------
INTERLEAVING_MODES
Dictionnary containing the interleaving modes available,
as well as additional information.
The key of the dictionnary is an internal name for the interleaving mode,
the value is a dictionnary with the following fields:
- ``int`` : The enum value of the interpolation.
- ``mode`` : The image mode, which is the value to pass to Pillow's ``Image.new()``
- ``maxcodes`` : The maximum number of codes that can be interleaved by this mode
- ``desc`` : A short one-line description of this interleaving mode
"""
from enum import Enum
class BWInterpolate(Enum):
class BWInterleave(Enum):
"""
Interleaving for single bit (black/white) image
This class only contain one interleaving type, for a good reason:
you can only put one single information on a single bit.
Attributes
----------
SINGLE
Only interleaving mode available, black squares
on white background.
"""
SINGLE = [
(0xFF, 0x00),
]
class GrayInterpolate(Enum):
class GrayInterleave(Enum):
"""
Interleaving for an 8 bits grayscale image
This class contains the interleaving methods available
for a grayscale image, with 8 bits per pixel.
Attributes
----------
SINGLE
Interleaving for 1 code. Identical to the black & white mode.
GRAY
Interleaving using actual grayscale levels of 0%, 34%, 66% and 100% brightness.
Designed to be easily decodable by scanning it.
NIBBLE
Interleaving where each code occupies a different nibble of the byte.
Made to be easily decodable from the original image file.
Birghtness levels used are 0%, 5%, 95% and 100%.
FULL
Interleaves 8 codes, each code going in one bit of the pixel color.
Results in the full grayscale spectrum being used, cannot be decoded by scanning.
"""
SINGLE = [
(0xFF, 0x00),
]
......@@ -16,6 +75,11 @@ class GrayInterpolate(Enum):
(0x57, 0x00),
]
NIBBLE = [
(0xF0, 0x00),
(0x0F, 0x00),
]
FULL = [
(0x80, 0x00),
(0x40, 0x00),
......@@ -27,7 +91,47 @@ class GrayInterpolate(Enum):
(0x01, 0x00),
]
class RGBInterpolate(Enum):
class RGBInterleave(Enum):
"""
Interleaving for a 24 bits RGB image
This class contains the interleaving methods available
for a full color image, with 24 bits per pixel
(8 bits for each color channel).
Attributes
----------
SINGLE
Interleaving for 1 code. Identical to the black & white mode.
RC
Interleaves 2 codes, putting the first one on the red channel
and the second one on both green and blue channels
(resulting in the color cyan).
GM
Interleaves 2 codes, putting the first one on the green channel
and the second one on both red and blue channels
(resulting in the color magenta).
BY
Interleaves 2 codes, putting the first one on the blue channel
and the second one on both green and red channels
(resulting in the color yellow).
TRICHANNEL
Interleaves 3 codes, with one on each channel (red, green and blue).
Can be decoded both by scanning and reading the original file.
HALFCHANNEL
Interleaves 2 codes per channel (6 in total)
by using easily distiguishable brightness levels.
Uses 0%, 34%, 66% and 100% brightness.
Easy to decode by scanning.
NIBBLE
Interleaves 2 codes per channel (6 in total)
by putting one code per nibble of the channel byte.
Uses 0%, 5%, 95% and 100% brightness.
Easy to decode by reading the image file.
FULL
Interleaves 24 codes, each code going in one bit of the pixel color.
Results in the full color spectrum being used, cannot be decoded by scanning.
"""
SINGLE = [
((0xFF, 0xFF, 0xFF), (0x00, 0x00, 0x00)),
]
......@@ -58,6 +162,14 @@ class RGBInterpolate(Enum):
((0x00, 0x00, 0xA8), (0x00, 0x00, 0x00)),
((0x00, 0x00, 0x57), (0x00, 0x00, 0x00)),
]
NIBBLE = [
((0xF0, 0x00, 0x00), (0x00, 0x00, 0x00)),
((0x0F, 0x00, 0x00), (0x00, 0x00, 0x00)),
((0x00, 0xF0, 0x00), (0x00, 0x00, 0x00)),
((0x00, 0x0F, 0x00), (0x00, 0x00, 0x00)),
((0x00, 0x00, 0xF0), (0x00, 0x00, 0x00)),
((0x00, 0x00, 0x0F), (0x00, 0x00, 0x00)),
]
FULL = [
((0x80, 0x00, 0x00), (0x00, 0x00, 0x00)),
......@@ -86,59 +198,71 @@ class RGBInterpolate(Enum):
((0x00, 0x00, 0x01), (0x00, 0x00, 0x00)),
]
INTERPOLATION_MODES = {
INTERLEAVING_MODES = {
'single' : {
'int' : BWInterpolate.SINGLE,
'int' : BWInterleave.SINGLE,
'mode' : '1',
'maxcodes' : 1,
'desc' : 'For a single code, black squares on white background',
},
'halfgray' : {
'int' : GrayInterpolate.GRAY,
'int' : GrayInterleave.GRAY,
'mode' : 'L',
'maxcodes' : 2,
'desc' : 'Two codes in a grayscale image, using 0%, 34%, 66%, and 100% brightness',
},
'graynibble' : {
'int' : GrayInterleave.NIBBLE,
'mode' : 'L',
'maxcodes' : 2,
'desc' : 'Two codes in a grayscale image, each on one nibble of the pixel',
},
'fullgray' : {
'int' : GrayInterpolate.FULL,
'int' : GrayInterleave.FULL,
'mode' : 'L',
'maxcodes' : 8,
'desc' : 'One code per bit in an 8 bits grayscale image',
},
'redcyan' : {
'int' : RGBInterpolate.RC,
'int' : RGBInterleave.RC,
'mode' : 'RGB',
'maxcodes' : 2,
'desc' : 'One code on the red channel, the other on green and blue',
},
'greenmagenta' : {
'int' : RGBInterpolate.GM,
'int' : RGBInterleave.GM,
'mode' : 'RGB',
'maxcodes' : 2,
'desc' : 'One code on the green channel, the other on red and blue',
},
'blueyellow' : {
'int' : RGBInterpolate.BY,
'int' : RGBInterleave.BY,
'mode' : 'RGB',
'maxcodes' : 2,
'desc' : 'One code on the blue channel, the other on green and red',
},
'rgb' : {
'int' : RGBInterpolate.TRICHANNEL,
'int' : RGBInterleave.TRICHANNEL,
'mode' : 'RGB',
'maxcodes' : 3,
'desc' : 'One code per channel, 3 in total',
'desc' : 'One code per channel byte, 3 in total',
},
'rgb2' : {
'int' : RGBInterpolate.HALFCHANNEL,
'int' : RGBInterleave.HALFCHANNEL,
'mode' : 'RGB',
'maxcodes' : 6,
'desc' : 'Two codes per channel (see "halfgray"), 6 in total',
},
'rgbnibble' : {
'int' : RGBInterleave.NIBBLE,
'mode' : 'RGB',
'maxcodes' : 6,
'desc' : 'One code per channel nibble (see "graynibble"), 6 in total',
},
'allcolors' : {
'int' : RGBInterpolate.FULL,
'int' : RGBInterleave.FULL,
'mode' : 'RGB',
'maxcodes' : 24,
'desc' : 'One code per bit on a 24 bits RGB image'
......
......@@ -19,6 +19,7 @@ BUILDERS : :py:class:`dict`
Builder descriptions
--------------------
A "builder description dictionnary" is a dictionnary containing the following 5 entries:
- ``id`` : The name of the module
- ``name`` : The name of the code as defined in the builder module
- ``builder`` : The code builder class
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment