better python imageize

sets interpretation as well ... was causing problems with jpg save
colour transforms
This commit is contained in:
John Cupitt 2015-02-10 14:08:37 +00:00
parent 62177ad24e
commit 640477dc62
3 changed files with 34 additions and 30 deletions

37
TODO
View File

@ -1,42 +1,19 @@
- try: - should cplusplus and ruby imageize preserve interpretation too?
#!/usr/bin/python - why can't we do
import sys im = Vips.Image.new_from_file(sys.argv[1], access = "sequential")
from gi.repository import Vips
# we can stream the image, turn on sequential access
#im = Vips.Image.new_from_file(sys.argv[1], access = Vips.Access.SEQUENTIAL)
im = Vips.Image.new_from_file(sys.argv[1])
text = Vips.Image.text(sys.argv[3], width = 500, dpi = 300)
text = (text * 0.3).cast("uchar")
text = text.embed(100, 100, text.width + 200, text.width + 200)
text = text.replicate(1 + im.width / text.width, 1 + im.height / text.height)
text = text.crop(0, 0, im.width, im.height)
im = text.ifthenelse([255, 0, 0], im, blend = True)
im.write_to_file(sys.argv[2])
makes a mono output from a colour input!
x = c.ifthenelse(a, b)
c - mono image
a - vector constant
b - colour image
ValueError: invalid literal for int() with base 10: 'sequential'
- msb in colour should not touch alpha channel - msb in colour should not touch alpha channel
... or should it? should converting RGBA from 8 to 16-bit touch alpha too? ... or should it? should converting RGBA from 8 to 16-bit touch alpha too?
probably probably
- use vips_resize() in vipsthumbnail? - use vips_resize() in vipsthumbnail?
should the sharpening filter be selectable? should the sharpening filter be selectable?

View File

@ -85,6 +85,9 @@ def imageize(match_image, value):
pixel = (Vips.Image.black(1, 1) + value).cast(match_image.format) pixel = (Vips.Image.black(1, 1) + value).cast(match_image.format)
image = pixel.embed(0, 0, match_image.width, match_image.height, image = pixel.embed(0, 0, match_image.width, match_image.height,
extend = Vips.Extend.COPY) extend = Vips.Extend.COPY)
image = image.copy(interpretation = match_image.interpretation,
xres = match_image.xres,
yres = match_image.yres)
return image return image
# we'd like to use memoryview to avoid copying things like ICC profiles, but # we'd like to use memoryview to avoid copying things like ICC profiles, but

View File

@ -486,6 +486,30 @@ class TestConversion(unittest.TestCase):
result = r.getpoint(10, 10) result = r.getpoint(10, 10)
self.assertAlmostEqualObjects(result, [3, 3, 13]) self.assertAlmostEqualObjects(result, [3, 3, 13])
test = self.mono > 3
r = test.ifthenelse([1, 2, 3], self.colour)
self.assertEqual(r.width, self.colour.width)
self.assertEqual(r.height, self.colour.height)
self.assertEqual(r.bands, self.colour.bands)
self.assertEqual(r.format, self.colour.format)
self.assertEqual(r.interpretation, self.colour.interpretation)
result = r.getpoint(10, 10)
self.assertAlmostEqualObjects(result, [2, 3, 4])
result = r.getpoint(50, 50)
self.assertAlmostEqualObjects(result, [1, 2, 3])
test = self.mono
r = test.ifthenelse([1, 2, 3], self.colour, blend = True)
self.assertEqual(r.width, self.colour.width)
self.assertEqual(r.height, self.colour.height)
self.assertEqual(r.bands, self.colour.bands)
self.assertEqual(r.format, self.colour.format)
self.assertEqual(r.interpretation, self.colour.interpretation)
result = r.getpoint(10, 10)
self.assertAlmostEqualObjects(result, [2, 3, 4], places = 1)
result = r.getpoint(50, 50)
self.assertAlmostEqualObjects(result, [3.0, 4.9, 6.9], places = 1)
def test_insert(self): def test_insert(self):
for x in all_formats: for x in all_formats:
for y in all_formats: for y in all_formats: