add tests for thumbnail
This commit is contained in:
parent
0faedcd088
commit
7d0c821a6e
4
TODO
4
TODO
|
@ -1,7 +1,3 @@
|
|||
- add thumbnail tests
|
||||
|
||||
rework vipsthumbnail.c
|
||||
|
||||
- not sure about utf8 error messages on win
|
||||
|
||||
- strange:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// headers for vips operations
|
||||
// Thu 18 Aug 16:02:54 BST 2016
|
||||
// Wed 2 Nov 13:48:15 GMT 2016
|
||||
// this file is generated automatically, do not edit!
|
||||
|
||||
static void system( char * cmd_format , VOption *options = 0 );
|
||||
|
@ -142,6 +142,7 @@ void ppmsave( char * filename , VOption *options = 0 );
|
|||
void radsave( char * filename , VOption *options = 0 );
|
||||
VipsBlob * radsave_buffer( VOption *options = 0 );
|
||||
void dzsave( char * filename , VOption *options = 0 );
|
||||
VipsBlob * dzsave_buffer( VOption *options = 0 );
|
||||
void pngsave( char * filename , VOption *options = 0 );
|
||||
VipsBlob * pngsave_buffer( VOption *options = 0 );
|
||||
void jpegsave( char * filename , VOption *options = 0 );
|
||||
|
@ -150,7 +151,10 @@ void jpegsave_mime( VOption *options = 0 );
|
|||
void webpsave( char * filename , VOption *options = 0 );
|
||||
VipsBlob * webpsave_buffer( VOption *options = 0 );
|
||||
void tiffsave( char * filename , VOption *options = 0 );
|
||||
VipsBlob * tiffsave_buffer( VOption *options = 0 );
|
||||
void fitssave( char * filename , VOption *options = 0 );
|
||||
static VImage thumbnail( char * filename , int width , VOption *options = 0 );
|
||||
static VImage thumbnail_buffer( VipsBlob * buffer , int width , VOption *options = 0 );
|
||||
VImage mapim( VImage index , VOption *options = 0 );
|
||||
VImage shrink( double hshrink , double vshrink , VOption *options = 0 );
|
||||
VImage shrinkh( int hshrink , VOption *options = 0 );
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// bodies for vips operations
|
||||
// Thu 18 Aug 16:01:57 BST 2016
|
||||
// Wed 2 Nov 13:48:04 GMT 2016
|
||||
// this file is generated automatically, do not edit!
|
||||
|
||||
void VImage::system( char * cmd_format , VOption *options )
|
||||
|
@ -1757,6 +1757,18 @@ void VImage::dzsave( char * filename , VOption *options )
|
|||
set( "filename", filename ) );
|
||||
}
|
||||
|
||||
VipsBlob * VImage::dzsave_buffer( VOption *options )
|
||||
{
|
||||
VipsBlob * buffer;
|
||||
|
||||
call( "dzsave_buffer" ,
|
||||
(options ? options : VImage::option()) ->
|
||||
set( "in", *this ) ->
|
||||
set( "buffer", &buffer ) );
|
||||
|
||||
return( buffer );
|
||||
}
|
||||
|
||||
void VImage::pngsave( char * filename , VOption *options )
|
||||
{
|
||||
call( "pngsave" ,
|
||||
|
@ -1832,6 +1844,18 @@ void VImage::tiffsave( char * filename , VOption *options )
|
|||
set( "filename", filename ) );
|
||||
}
|
||||
|
||||
VipsBlob * VImage::tiffsave_buffer( VOption *options )
|
||||
{
|
||||
VipsBlob * buffer;
|
||||
|
||||
call( "tiffsave_buffer" ,
|
||||
(options ? options : VImage::option()) ->
|
||||
set( "in", *this ) ->
|
||||
set( "buffer", &buffer ) );
|
||||
|
||||
return( buffer );
|
||||
}
|
||||
|
||||
void VImage::fitssave( char * filename , VOption *options )
|
||||
{
|
||||
call( "fitssave" ,
|
||||
|
@ -1840,6 +1864,32 @@ void VImage::fitssave( char * filename , VOption *options )
|
|||
set( "filename", filename ) );
|
||||
}
|
||||
|
||||
VImage VImage::thumbnail( char * filename , int width , VOption *options )
|
||||
{
|
||||
VImage out;
|
||||
|
||||
call( "thumbnail" ,
|
||||
(options ? options : VImage::option()) ->
|
||||
set( "filename", filename ) ->
|
||||
set( "out", &out ) ->
|
||||
set( "width", width ) );
|
||||
|
||||
return( out );
|
||||
}
|
||||
|
||||
VImage VImage::thumbnail_buffer( VipsBlob * buffer , int width , VOption *options )
|
||||
{
|
||||
VImage out;
|
||||
|
||||
call( "thumbnail_buffer" ,
|
||||
(options ? options : VImage::option()) ->
|
||||
set( "buffer", buffer ) ->
|
||||
set( "out", &out ) ->
|
||||
set( "width", width ) );
|
||||
|
||||
return( out );
|
||||
}
|
||||
|
||||
VImage VImage::mapim( VImage index , VOption *options )
|
||||
{
|
||||
VImage out;
|
||||
|
|
|
@ -683,10 +683,11 @@ vips_thumbnail_file_init( VipsThumbnailFile *file )
|
|||
* also be far slower, since tricks like JPEG shrink-on-load cannot be used in
|
||||
* linear space.
|
||||
*
|
||||
* If you set @export_profile to the filename of an ICC profile, the image will
|
||||
* be transformed to the target colourspace before writing to the output. You
|
||||
* can also give an @import_profile which will be used if the input image has
|
||||
* no ICC profile, or if the profile embedded in the input image is broken.
|
||||
* If you set @export_profile to the filename of an ICC profile, the image
|
||||
* will be transformed to the target colourspace before writing to the
|
||||
* output. You can also give an @import_profile which will be used if the
|
||||
* input image has no ICC profile, or if the profile embedded in the
|
||||
* input image is broken.
|
||||
*
|
||||
* See also: vips_thumbnail_buffer().
|
||||
*
|
||||
|
@ -747,7 +748,8 @@ vips_thumbnail_buffer_get_info( VipsThumbnail *thumbnail )
|
|||
* scale, never both.
|
||||
*/
|
||||
static VipsImage *
|
||||
vips_thumbnail_buffer_open( VipsThumbnail *thumbnail, int shrink, double scale )
|
||||
vips_thumbnail_buffer_open( VipsThumbnail *thumbnail,
|
||||
int shrink, double scale )
|
||||
{
|
||||
VipsThumbnailBuffer *buffer = (VipsThumbnailBuffer *) thumbnail;
|
||||
|
||||
|
|
|
@ -1068,61 +1068,63 @@ class Image(Vips.Image):
|
|||
# see above
|
||||
|
||||
class_methods = [
|
||||
"system",
|
||||
"sum",
|
||||
"analyzeload",
|
||||
"arrayjoin",
|
||||
"black",
|
||||
"gaussnoise",
|
||||
"text",
|
||||
"xyz",
|
||||
"gaussmat",
|
||||
"logmat",
|
||||
"eye",
|
||||
"grey",
|
||||
"zone",
|
||||
"sines",
|
||||
"mask_ideal",
|
||||
"mask_ideal_ring",
|
||||
"mask_ideal_band",
|
||||
"mask_butterworth",
|
||||
"mask_butterworth_ring",
|
||||
"mask_butterworth_band",
|
||||
"mask_gaussian",
|
||||
"mask_gaussian_ring",
|
||||
"mask_gaussian_band",
|
||||
"mask_fractal",
|
||||
"tonelut",
|
||||
"identity",
|
||||
"perlin",
|
||||
"worley",
|
||||
"fractsurf",
|
||||
"radload",
|
||||
"ppmload",
|
||||
"csvload",
|
||||
"matrixload",
|
||||
"analyzeload",
|
||||
"rawload",
|
||||
"vipsload",
|
||||
"pngload",
|
||||
"pngload_buffer",
|
||||
"matload",
|
||||
"jpegload",
|
||||
"jpegload_buffer",
|
||||
"webpload",
|
||||
"webpload_buffer",
|
||||
"tiffload",
|
||||
"tiffload_buffer",
|
||||
"pdfload",
|
||||
"pdfload_buffer",
|
||||
"svgload",
|
||||
"svgload_buffer",
|
||||
"eye",
|
||||
"fitsload",
|
||||
"fractsurf",
|
||||
"gaussmat",
|
||||
"gaussnoise",
|
||||
"gifload",
|
||||
"gifload_buffer",
|
||||
"openslideload",
|
||||
"grey",
|
||||
"identity",
|
||||
"jpegload",
|
||||
"jpegload_buffer",
|
||||
"logmat",
|
||||
"magickload",
|
||||
"magickload_buffer",
|
||||
"fitsload",
|
||||
"openexrload"]
|
||||
"mask_butterworth",
|
||||
"mask_butterworth_band",
|
||||
"mask_butterworth_ring",
|
||||
"mask_fractal",
|
||||
"mask_gaussian",
|
||||
"mask_gaussian_band",
|
||||
"mask_gaussian_ring",
|
||||
"mask_ideal",
|
||||
"mask_ideal_band",
|
||||
"mask_ideal_ring",
|
||||
"matload",
|
||||
"matrixload",
|
||||
"openexrload",
|
||||
"openslideload",
|
||||
"pdfload",
|
||||
"pdfload_buffer",
|
||||
"perlin",
|
||||
"pngload",
|
||||
"pngload_buffer",
|
||||
"ppmload",
|
||||
"radload",
|
||||
"rawload",
|
||||
"sines",
|
||||
"sum",
|
||||
"svgload",
|
||||
"svgload_buffer",
|
||||
"system",
|
||||
"text",
|
||||
"thumbnail",
|
||||
"thumbnail_buffer",
|
||||
"tiffload",
|
||||
"tiffload_buffer",
|
||||
"tonelut",
|
||||
"vipsload",
|
||||
"webpload",
|
||||
"webpload_buffer",
|
||||
"worley",
|
||||
"xyz",
|
||||
"zone"]
|
||||
|
||||
def generate_class_method(name):
|
||||
@classmethod
|
||||
|
|
|
@ -105,8 +105,11 @@ class TestResample(unittest.TestCase):
|
|||
for x, y in zip_expand(a, b):
|
||||
self.assertAlmostEqual(x, y, places = places, msg = msg)
|
||||
|
||||
def setUp(self):
|
||||
self.jpeg_file = "images/йцук.jpg"
|
||||
|
||||
def test_affine(self):
|
||||
im = Vips.Image.new_from_file("images/йцук.jpg")
|
||||
im = Vips.Image.new_from_file(self.jpeg_file)
|
||||
|
||||
# vsqbs is non-interpolatory, don't test this way
|
||||
for name in ["nearest", "bicubic", "bilinear", "nohalo", "lbb"]:
|
||||
|
@ -118,7 +121,7 @@ class TestResample(unittest.TestCase):
|
|||
self.assertEqual((x - im).abs().max(), 0)
|
||||
|
||||
def test_reduce(self):
|
||||
im = Vips.Image.new_from_file("images/йцук.jpg")
|
||||
im = Vips.Image.new_from_file(self.jpeg_file)
|
||||
# cast down to 0-127, the smallest range, so we aren't messed up by
|
||||
# clipping
|
||||
im = im.cast(Vips.BandFormat.CHAR)
|
||||
|
@ -166,7 +169,7 @@ class TestResample(unittest.TestCase):
|
|||
self.assertEqual(d, 0)
|
||||
|
||||
def test_resize(self):
|
||||
im = Vips.Image.new_from_file("images/йцук.jpg")
|
||||
im = Vips.Image.new_from_file(self.jpeg_file)
|
||||
im2 = im.resize(0.25)
|
||||
self.assertEqual(im2.width, round(im.width / 4.0))
|
||||
self.assertEqual(im2.height, round(im.height / 4.0))
|
||||
|
@ -178,7 +181,7 @@ class TestResample(unittest.TestCase):
|
|||
self.assertEqual(x.height, 1)
|
||||
|
||||
def test_shrink(self):
|
||||
im = Vips.Image.new_from_file("images/йцук.jpg")
|
||||
im = Vips.Image.new_from_file(self.jpeg_file)
|
||||
im2 = im.shrink(4, 4)
|
||||
self.assertEqual(im2.width, round(im.width / 4.0))
|
||||
self.assertEqual(im2.height, round(im.height / 4.0))
|
||||
|
@ -189,22 +192,52 @@ class TestResample(unittest.TestCase):
|
|||
self.assertEqual(im2.height, round(im.height / 2.5))
|
||||
self.assertLess(abs(im.avg() - im2.avg()), 1)
|
||||
|
||||
def test_thumbnail(self):
|
||||
im = Vips.Image.thumbnail(self.jpeg_file, 100)
|
||||
|
||||
self.assertEqual(im.width, 100)
|
||||
self.assertEqual(im.bands, 3)
|
||||
self.assertEqual(im.bands, 3)
|
||||
|
||||
# the average shouldn't move too much
|
||||
im_orig = Vips.Image.new_from_file(self.jpeg_file)
|
||||
self.assertLess(abs(im_orig.avg() - im.avg()), 1)
|
||||
|
||||
# make sure we always get the right width
|
||||
for width in range(1000, 1, -13):
|
||||
im = Vips.Image.thumbnail(self.jpeg_file, width)
|
||||
self.assertEqual(im.width, width)
|
||||
|
||||
# should fit one of width or height
|
||||
im = Vips.Image.thumbnail(self.jpeg_file, 100, height = 300)
|
||||
self.assertEqual(im.width, 100)
|
||||
self.assertNotEqual(im.height, 300)
|
||||
im = Vips.Image.thumbnail(self.jpeg_file, 300, height = 100)
|
||||
self.assertNotEqual(im.width, 300)
|
||||
self.assertEqual(im.height, 100)
|
||||
|
||||
# with @crop, should fit both width and height
|
||||
im = Vips.Image.thumbnail(self.jpeg_file, 100,
|
||||
height = 300, crop = True)
|
||||
self.assertEqual(im.width, 100)
|
||||
self.assertEqual(im.height, 300)
|
||||
|
||||
def test_similarity(self):
|
||||
im = Vips.Image.new_from_file("images/йцук.jpg")
|
||||
im = Vips.Image.new_from_file(self.jpeg_file)
|
||||
im2 = im.similarity(angle = 90)
|
||||
im3 = im.affine([0, -1, 1, 0])
|
||||
# rounding in calculating the affine transform from the angle stops this
|
||||
# being exactly true
|
||||
# rounding in calculating the affine transform from the angle stops
|
||||
# this being exactly true
|
||||
self.assertLess((im2 - im3).abs().max(), 50)
|
||||
|
||||
def test_similarity_scale(self):
|
||||
im = Vips.Image.new_from_file("images/йцук.jpg")
|
||||
im = Vips.Image.new_from_file(self.jpeg_file)
|
||||
im2 = im.similarity(scale = 2)
|
||||
im3 = im.affine([2, 0, 0, 2])
|
||||
self.assertEqual((im2 - im3).abs().max(), 0)
|
||||
|
||||
def test_mapim(self):
|
||||
im = Vips.Image.new_from_file("images/йцук.jpg")
|
||||
im = Vips.Image.new_from_file(self.jpeg_file)
|
||||
|
||||
p = to_polar(im)
|
||||
r = to_rectangular(p)
|
||||
|
|
Loading…
Reference in New Issue