mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 01:16:16 +03:00
flake8 and tests
This commit is contained in:
parent
1bd4919a35
commit
f94b6b4025
|
@ -19,7 +19,6 @@
|
|||
|
||||
__version__ = "0.3"
|
||||
|
||||
import os
|
||||
from PIL import Image, ImageFile, ImagePalette, _binary
|
||||
|
||||
|
||||
|
@ -102,20 +101,20 @@ class TgaImageFile(ImageFile.ImageFile):
|
|||
self.info["compression"] = "tga_rle"
|
||||
|
||||
if idlen:
|
||||
self.fp.seek(idlen, os.SEEK_CUR)
|
||||
self.info["id_section"] = self.fp.read(idlen)
|
||||
|
||||
if colormaptype:
|
||||
# read palette
|
||||
start, size, mapdepth = i16(s[3:]), i16(s[5:]), i16(s[7:])
|
||||
if mapdepth == 16:
|
||||
self.palette = ImagePalette.raw("BGR;16",
|
||||
b"\0"*2*start + self.fp.read(2*size))
|
||||
self.palette = ImagePalette.raw(
|
||||
"BGR;16", b"\0"*2*start + self.fp.read(2*size))
|
||||
elif mapdepth == 24:
|
||||
self.palette = ImagePalette.raw("BGR",
|
||||
b"\0"*3*start + self.fp.read(3*size))
|
||||
self.palette = ImagePalette.raw(
|
||||
"BGR", b"\0"*3*start + self.fp.read(3*size))
|
||||
elif mapdepth == 32:
|
||||
self.palette = ImagePalette.raw("BGRA",
|
||||
b"\0"*4*start + self.fp.read(4*size))
|
||||
self.palette = ImagePalette.raw(
|
||||
"BGRA", b"\0"*4*start + self.fp.read(4*size))
|
||||
|
||||
# setup tile descriptor
|
||||
try:
|
||||
|
@ -146,6 +145,7 @@ SAVE = {
|
|||
"RGBA": ("BGRA", 32, 0, 2),
|
||||
}
|
||||
|
||||
|
||||
def _save(im, fp, filename, check=0):
|
||||
|
||||
try:
|
||||
|
@ -186,7 +186,8 @@ def _save(im, fp, filename, check=0):
|
|||
if colormaptype:
|
||||
fp.write(im.im.getpalette("RGB", "BGR"))
|
||||
|
||||
ImageFile._save(im, fp, [("raw", (0,0)+im.size, 0, (rawmode, 0, orientation))])
|
||||
ImageFile._save(
|
||||
im, fp, [("raw", (0, 0) + im.size, 0, (rawmode, 0, orientation))])
|
||||
|
||||
#
|
||||
# --------------------------------------------------------------------
|
||||
|
|
BIN
Tests/images/tga_id_field.tga
Normal file
BIN
Tests/images/tga_id_field.tga
Normal file
Binary file not shown.
22
Tests/test_file_tga.py
Normal file
22
Tests/test_file_tga.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
from helper import unittest, PillowTestCase
|
||||
|
||||
from PIL import Image
|
||||
|
||||
|
||||
class TestFileSun(PillowTestCase):
|
||||
|
||||
def test_sanity(self):
|
||||
# tga file with id field
|
||||
test_file = "Tests/images/tga_id_field.tga"
|
||||
|
||||
# Act
|
||||
im = Image.open(test_file)
|
||||
|
||||
# Assert
|
||||
self.assertEqual(im.size, (100, 100))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
# End of file
|
Loading…
Reference in New Issue
Block a user