Skip to content

Commit 1ae27ba

Browse files
author
BoboTiG
committed
Version 0.1.1
1 parent 4d6e266 commit 1ae27ba

File tree

4 files changed

+76
-44
lines changed

4 files changed

+76
-44
lines changed

doc/CHANGELOG

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ History:
33
<see Git checkin messages for history>
44

55
devel 201y/mm/dd
6-
- [test] warn the user in case of outdated MSS version
6+
-
7+
8+
0.1.1 2015/04/10
9+
- little code review
10+
- add doc/TESTING
11+
- remove Bonus section from README.rst
12+
- tests: remove test-linux binary
13+
- MSSLinux: fix monitor count
714

815
0.1.0 2015/04/10
916
- fix code with YAPF tool

doc/TESTING

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
The current MSS version was succesfully tested on these OS.
2+
You have another OS to add? Let us know, open a ticket on GitHub :)
3+
4+
GNU/Linux:
5+
Debian 8.0 (jessie)
6+
Mageia 4.1
7+
Ubuntu 14.04.2 LTS (Trusty Tahr)
8+
Ubuntu 14.10 (Utopic Unicorn)
9+
Zorin OS 9
10+
11+
Mac OS X:
12+
OS X 10.7 (Lion)
13+
OS X 10.8 (Mountain Lion)
14+
15+
Microsoft Windows:
16+
Windows XP
17+
Windows 7
18+
Windows 8
19+
Windows 8.1

mss.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from __future__ import (unicode_literals, print_function)
1515

16-
__version__ = '0.1.0'
16+
__version__ = '0.1.1'
1717
__author__ = "Mickaël 'Tiger-222' Schoentgen"
1818
__copyright__ = '''
1919
Copyright (c) 2013-2015, Mickaël 'Tiger-222' Schoentgen

test/test-raw.py

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,71 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4-
# Test raw data.
4+
# Test raw data generated by test-linux.
55

66
import mss
7-
from struct import pack
8-
import os.path
9-
import zlib
107
import sys
118

9+
if mss.__version__ < '0.1.0':
10+
from struct import pack
11+
import os.path
12+
import zlib
1213

13-
def save_img(data, width, height, output):
14-
''' Dump data to the image file.
15-
Pure python PNG implementation.
16-
Image represented as RGB tuples, no interlacing.
17-
http://inaps.org/journal/comment-fonctionne-le-png
18-
'''
14+
# Copied from MSS.save_img()
15+
# @deprecated
16+
def save_img(data, width, height, output):
17+
''' Dump data to the image file.
18+
Pure python PNG implementation.
19+
Image represented as RGB tuples, no interlacing.
20+
http://inaps.org/journal/comment-fonctionne-le-png
21+
'''
1922

20-
to_take = (width * 3 + 3) & -4
21-
padding = 0 if to_take % 8 == 0 else (to_take % 8) // 2
22-
scanlines = b''.join(
23-
[b'0' + data[(y * to_take):(y * to_take) + to_take - padding]
24-
for y in range(height)])
23+
to_take = (width * 3 + 3) & -4
24+
padding = 0 if to_take % 8 == 0 else (to_take % 8) // 2
25+
scanlines = b''.join(
26+
[b'0' + data[(y * to_take):(y * to_take) + to_take - padding]
27+
for y in range(height)])
2528

26-
magic = pack(b'>8B', 137, 80, 78, 71, 13, 10, 26, 10)
29+
magic = pack(b'>8B', 137, 80, 78, 71, 13, 10, 26, 10)
2730

28-
# Header: size, marker, data, CRC32
29-
ihdr = [b'', b'IHDR', b'', b'']
30-
ihdr[2] = pack(b'>2I5B', width, height, 8, 2, 0, 0, 0)
31-
ihdr[3] = pack(b'>I', zlib.crc32(b''.join(ihdr[1:3])) & 0xffffffff)
32-
ihdr[0] = pack(b'>I', len(ihdr[2]))
31+
# Header: size, marker, data, CRC32
32+
ihdr = [b'', b'IHDR', b'', b'']
33+
ihdr[2] = pack(b'>2I5B', width, height, 8, 2, 0, 0, 0)
34+
ihdr[3] = pack(b'>I', zlib.crc32(b''.join(ihdr[1:3])) & 0xffffffff)
35+
ihdr[0] = pack(b'>I', len(ihdr[2]))
3336

34-
# Data: size, marker, data, CRC32
35-
idat = [b'', b'IDAT', b'', b'']
36-
idat[2] = zlib.compress(scanlines, 9)
37-
idat[3] = pack(b'>I', zlib.crc32(b''.join(idat[1:3])) & 0xffffffff)
38-
idat[0] = pack(b'>I', len(idat[2]))
37+
# Data: size, marker, data, CRC32
38+
idat = [b'', b'IDAT', b'', b'']
39+
idat[2] = zlib.compress(scanlines, 9)
40+
idat[3] = pack(b'>I', zlib.crc32(b''.join(idat[1:3])) & 0xffffffff)
41+
idat[0] = pack(b'>I', len(idat[2]))
3942

40-
# Footer: size, marker, None, CRC32
41-
iend = [b'', b'IEND', b'', b'']
42-
iend[3] = pack(b'>I', zlib.crc32(iend[1]) & 0xffffffff)
43-
iend[0] = pack(b'>I', len(iend[2]))
43+
# Footer: size, marker, None, CRC32
44+
iend = [b'', b'IEND', b'', b'']
45+
iend[3] = pack(b'>I', zlib.crc32(iend[1]) & 0xffffffff)
46+
iend[0] = pack(b'>I', len(iend[2]))
4447

45-
with open(output, 'wb') as fileh:
46-
fileh.write(
47-
magic + b''.join(ihdr) + b''.join(idat) + b''.join(iend))
48-
if not os.path.isfile(output):
49-
msg = 'Impossible to write data to file "{}".'.format(output)
50-
raise ScreenshotError(msg)
48+
with open(output, 'wb') as fileh:
49+
fileh.write(
50+
magic + b''.join(ihdr) + b''.join(idat) + b''.join(iend))
51+
if not os.path.isfile(output):
52+
msg = 'Impossible to write data to file "{}".'.format(output)
53+
raise ScreenshotError(msg)
5154

5255
if len(sys.argv) < 4:
53-
print('python {0} data.raw width height'.format(sys.argv[0]))
56+
print('python {} data.raw width height'.format(sys.argv[0]))
5457
else:
55-
with open(sys.argv[1], 'rb') as f:
56-
data = f.read()
58+
with open(sys.argv[1], 'rb') as fileh:
59+
data = fileh.read()
5760
width = int(sys.argv[2])
5861
height = int(sys.argv[3])
62+
output = '{}.png'.format(sys.argv[1])
5963
if mss.__version__ < '0.1.0':
6064
print('Outdated version of MSS, please `pip install --upgrade mss`')
61-
save_img(data, width, height, sys.argv[1] + '.png')
65+
save_img(data, width, height, output)
6266
else:
6367
mss = mss.MSS()
64-
mss.save_img(data, width, height, sys.argv[1] + '.png')
65-
print('File {}.png created.'.format(sys.argv[1]))
68+
mss.save_img(data, width, height, output)
69+
print('File {} created.'.format(output))
70+
sys.exit(0)
71+
print('Impossible to get contents of "{}".'.format(sys.argv[1]))

0 commit comments

Comments
 (0)