Guest User

Untitled

a guest
May 22nd, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. /* compile with
  2. *
  3. * gcc -g -Wall try269.c `pkg-config vips --cflags --libs`
  4. *
  5. */
  6.  
  7. #include <stdio.h>
  8.  
  9. #include <vips/vips.h>
  10.  
  11. static int
  12. wof_generate_packshot(VipsImage **out, VipsImage *product) {
  13.  
  14. VipsImage *base = vips_image_new();
  15. VipsImage **t = (VipsImage **) vips_object_local_array(VIPS_OBJECT(base), 12);
  16.  
  17. int width = product->Xsize;
  18. int height = product->Ysize;
  19.  
  20. if (
  21. // resize product image in t[0]
  22. vips_resize( product, &t[0], 0.9, NULL ) ||
  23.  
  24. // find pixels over 250 and feather slightly ... JPG compression arifacts
  25. // will typically be around this range
  26. //
  27. // bandand() ANDs all the tests together, ie. we find pixels where r AND g
  28. // AND b are all >250
  29. vips_more_const1( t[0], &t[1], 250.0, NULL ) ||
  30. vips_bandand( t[1], &t[2], NULL ) ||
  31. vips_gaussblur( t[2], &t[3], 1,
  32. "precision", VIPS_PRECISION_INTEGER,
  33. NULL ) ||
  34.  
  35. /* Make the new background, and blend with our product shot.
  36. */
  37. !(t[4] = vips_image_new_from_image1( t[0], 230 )) ||
  38. vips_ifthenelse( t[3], t[4], t[0], &t[5],
  39. "blend", TRUE,
  40. NULL ) ||
  41.  
  42. /* Expand outwards with the new background colour.
  43. */
  44. vips_gravity( t[5], out, VIPS_COMPASS_DIRECTION_CENTRE, width, height,
  45. "extend", VIPS_EXTEND_COPY,
  46. NULL )
  47.  
  48. ) {
  49. g_object_unref(base);
  50. return 1;
  51. }
  52.  
  53. g_object_unref(base);
  54.  
  55. return 0;
  56. }
  57.  
  58. int
  59. main( int argc, char **argv )
  60. {
  61. int i;
  62.  
  63. if( VIPS_INIT( argv[0] ) )
  64. vips_error_exit( NULL );
  65.  
  66. for( i = 1; i < argc; i++ ) {
  67. VipsImage *in;
  68. VipsImage *x;
  69.  
  70. printf( "loop %d ...\n", i );
  71. if( !(in = vips_image_new_from_file( argv[i],
  72. "access", VIPS_ACCESS_SEQUENTIAL,
  73. NULL )) )
  74. vips_error_exit( NULL );
  75. if( wof_generate_packshot( &x, in ) )
  76. vips_error_exit( NULL );
  77. if( vips_image_write_to_file( x, "x.jpg", NULL ) )
  78. vips_error_exit( NULL );
  79. g_object_unref( x );
  80. g_object_unref( in );
  81. }
  82.  
  83. return( 0 );
  84. }
Add Comment
Please, Sign In to add comment