diff options
| author | jvoisin | 2013-10-27 23:01:20 +0000 |
|---|---|---|
| committer | jvoisin | 2013-10-27 23:01:20 +0000 |
| commit | 4c81e731a485d3ea84049ef6d568153c8b10e90b (patch) | |
| tree | 86ad43d7df67ed8d27cfbe7ff60dda1545784845 /MAT/images.py | |
| parent | 6f21743fdae533d7a94f64fb03d706fb342aff01 (diff) | |
Improves documentation
Diffstat (limited to 'MAT/images.py')
| -rw-r--r-- | MAT/images.py | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/MAT/images.py b/MAT/images.py index 55c1a90..dc96e6a 100644 --- a/MAT/images.py +++ b/MAT/images.py | |||
| @@ -1,41 +1,52 @@ | |||
| 1 | ''' | 1 | ''' Takes care about pictures formats |
| 2 | Takes care about pictures formats | 2 | |
| 3 | References: | ||
| 4 | - JFIF: http://www.ecma-international.org/publications/techreports/E-TR-098.htm | ||
| 5 | - PNG: http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/PNG.html | ||
| 6 | - PNG: http://www.w3.org/TR/PNG-Chunks.html | ||
| 3 | ''' | 7 | ''' |
| 4 | 8 | ||
| 5 | import parser | 9 | import parser |
| 6 | 10 | ||
| 7 | 11 | ||
| 8 | class JpegStripper(parser.GenericParser): | 12 | class JpegStripper(parser.GenericParser): |
| 9 | ''' | 13 | ''' Represents a jpeg file. |
| 10 | represents a jpeg file | 14 | Custom Huffman and Quantization tables |
| 15 | are stripped: they may leak | ||
| 16 | some info, and the quality loss is minor. | ||
| 11 | ''' | 17 | ''' |
| 12 | def _should_remove(self, field): | 18 | def _should_remove(self, field): |
| 19 | ''' Return True if the field is compromising | ||
| 13 | ''' | 20 | ''' |
| 14 | return True if the field is compromising | 21 | field_list = frozenset([ |
| 15 | ''' | 22 | 'start_image', # start of the image |
| 16 | field_list = frozenset(['start_image', 'app0', 'start_frame', | 23 | 'app0', # JFIF data |
| 17 | 'start_scan', 'data', 'end_image']) | 24 | 'start_frame', # specify width, height, number of components |
| 25 | 'start_scan', # specify which slice of data the top-to-bottom scan contains | ||
| 26 | 'data', # actual data | ||
| 27 | 'end_image']) # end of the image | ||
| 18 | if field.name in field_list: | 28 | if field.name in field_list: |
| 19 | return False | 29 | return False |
| 20 | elif field.name.startswith('quantization['): | 30 | elif field.name.startswith('quantization['): # custom Quant. tables |
| 21 | return False | 31 | return False |
| 22 | elif field.name.startswith('huffman['): | 32 | elif field.name.startswith('huffman['): # custom Huffman tables |
| 23 | return False | 33 | return False |
| 24 | return True | 34 | return True |
| 25 | 35 | ||
| 26 | 36 | ||
| 27 | class PngStripper(parser.GenericParser): | 37 | class PngStripper(parser.GenericParser): |
| 28 | ''' | 38 | ''' Represents a png file |
| 29 | represents a png file | ||
| 30 | see : http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/PNG.html | ||
| 31 | ''' | 39 | ''' |
| 32 | def _should_remove(self, field): | 40 | def _should_remove(self, field): |
| 41 | ''' Return True if the field is compromising | ||
| 33 | ''' | 42 | ''' |
| 34 | return True if the field is compromising | 43 | field_list = frozenset([ |
| 35 | ''' | 44 | 'id', |
| 36 | field_list = frozenset(['id', 'header', 'physical', 'end']) | 45 | 'header', # PNG header |
| 46 | 'physical', # the intended pixel size or aspect ratio | ||
| 47 | 'end']) # end of the image | ||
| 37 | if field.name in field_list: | 48 | if field.name in field_list: |
| 38 | return False | 49 | return False |
| 39 | if field.name.startswith('data['): | 50 | if field.name.startswith('data['): # data |
| 40 | return False | 51 | return False |
| 41 | return True | 52 | return True |
