Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define PROGRESSIVE 1
- string interp_type("bicubic");
- string ifilename("inputimage.png");
- string ofilename("outputimage.jpg");
- vips::VIMask sharpen_filter(MASK_XSIZE, MASK_YSIZE, MASK_SCALE, MASK_OFFSET,
- std::vector<int> MASK_COEFF);
- /* Get target_height from the user */
- vips::VImage in(ifilename.c_str());
- input_height = in.Ysize();
- aspect_ratio = double(in.Xsize()) / double(in.Ysize());
- target_width = int(target_height * aspect_ratio);
- scale = target_height / (double) input_height;
- /* Shrink to integer factor first - This is faster */
- int shrink_factor = floor(1.0 / scale);
- if ((1.0 / scale) > 2.0) {
- out = in.shrink(double(shrink_factor), double(shrink_factor));
- }
- /* Use affine transform to get to the required size */
- int height_aft_shrink = floor(input_height / shrink_factor);
- scale = target_height / (double) height_aft_shrink;
- out = out.affinei((char *) interp_type.c_str(), scale, 0, 0, scale,
- 0, 0, 0, 0, target_width, target_height);
- /* Apply Sharpening Filter */
- if (target_width < 150 || target_height < 150) {
- out = out.conv(sharpen_filter);
- }
- if ( vips_foreign_save((VipsImage *) (out.image()),
- (char *) ofilename.c_str(),
- "interlace", PROGRESSIVE ,
- NULL) ) {
- cout << "Error in saving file-" << ofilename
- << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement