Advertisement
vinvinod

shrinking with vips (in c++)

Nov 11th, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1.     #define PROGRESSIVE 1
  2.     string interp_type("bicubic");
  3.     string ifilename("inputimage.png");
  4.     string ofilename("outputimage.jpg");
  5.  
  6.     vips::VIMask sharpen_filter(MASK_XSIZE, MASK_YSIZE, MASK_SCALE, MASK_OFFSET,
  7.                             std::vector<int> MASK_COEFF);
  8.  
  9.     /* Get target_height from the user */
  10.     vips::VImage in(ifilename.c_str());
  11.    
  12.     input_height = in.Ysize();
  13.     aspect_ratio = double(in.Xsize()) / double(in.Ysize());
  14.     target_width = int(target_height * aspect_ratio);
  15.    
  16.     scale = target_height / (double) input_height;
  17.  
  18.         /* Shrink to integer factor first - This is faster */
  19.         int shrink_factor = floor(1.0 / scale);
  20.         if ((1.0 / scale) > 2.0) {
  21.             out = in.shrink(double(shrink_factor), double(shrink_factor));
  22.         }
  23.        
  24.         /* Use affine transform to get to the required size */
  25.         int height_aft_shrink = floor(input_height / shrink_factor);
  26.         scale = target_height / (double) height_aft_shrink;
  27.         out = out.affinei((char *) interp_type.c_str(), scale, 0, 0, scale,
  28.                                         0, 0, 0, 0, target_width, target_height);
  29.  
  30.         /* Apply Sharpening Filter */
  31.         if (target_width < 150 || target_height < 150) {
  32.             out = out.conv(sharpen_filter);
  33.         }
  34.    
  35.     if ( vips_foreign_save((VipsImage *) (out.image()),
  36.                 (char *) ofilename.c_str(),
  37.                 "interlace", PROGRESSIVE ,
  38.                 NULL) ) {
  39.             cout << "Error in saving file-" << ofilename
  40.                     << endl;
  41.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement