context magick::estimate (const context& ctx) { double x_sample_factor = x_resolution_ / ctx.x_resolution (); double y_sample_factor = y_resolution_ / ctx.y_resolution (); context rv (ctx); rv.width (ctx.width () * x_sample_factor); rv.height (ctx.height () * y_sample_factor); rv.resolution (x_resolution_, y_resolution_); if (force_extent_) { rv.width (width_ * x_resolution_); rv.height (height_ * y_resolution_); } if (image_format_) { /**/ if (image_format_ == "GIF" ) rv.content_type ("image/gif"); else if (image_format_ == "JPEG") rv.content_type ("image/jpeg"); else if (image_format_ == "PDF") { rv.content_type (bilevel_ ? "image/x-portable-bitmap" : "image/jpeg"); } else if (image_format_ == "PNG" ) rv.content_type ("image/png"); else if (image_format_ == "PNM" ) { rv.content_type ("image/x-portable-anymap"); } else if (image_format_ == "TIFF") rv.content_type ("image/x-raster"); else { // internal error } } else { rv.content_type ("image/x-raster"); } if (bilevel_) { rv.depth (1); } return rv; }
void padding::eoi (const context& ctx) { context::size_type padding; if (ctx_.width () >= ctx.width ()) { padding = ctx_.scan_width () - ctx.scan_width (); if (padding) log::alert ("%1% padding octets remain") % padding; ctx_.width (ctx.width (), padding); } else { log::alert ("%1% pixels inadvertently cropped when removing padding octets") % (ctx.width () - ctx_.width ()); } if (ctx_.height () >= ctx.height ()) { padding = ctx_.scan_height () - ctx.scan_height (); if (padding) log::alert ("%1% padding scan lines remain") % padding; ctx_.height (ctx.height (), padding); } else { log::alert ("%1% pixels inadvertently cropped when removing padding lines") % (ctx.height () - ctx_.height ()); } }
void padding::boi (const context& ctx) { logic_error e (_("padding only works with raster images of known size")); if (!ctx.is_raster_image ()) BOOST_THROW_EXCEPTION (e); if (0 != ctx.padding_octets () && context::unknown_size == ctx.width ()) BOOST_THROW_EXCEPTION (e); if (0 != ctx.padding_lines () && context::unknown_size == ctx.height ()) BOOST_THROW_EXCEPTION (e); w_padding_ = ctx.padding_octets (); h_padding_ = ctx.padding_lines (); scan_line_count_ = 0; skip_ = 0; ctx_ = ctx; ctx_.width (ctx.width (), 0); // zap our padding settings ctx_.height (ctx.height (), 0); }
std::string magick::arguments (const context& ctx) { using std::string; string argv; // Set up input data characteristics argv += " -size " + geom_(ctx.width (), ctx.height ()); argv += " -depth " + lexical_cast< string > (ctx.depth ()); argv += " -density " + geom_(ctx.x_resolution (), ctx.y_resolution ()); argv += " -units PixelsPerInch"; if (ctx.is_raster_image ()) { /**/ if (ctx.is_rgb ()) argv += " rgb:-"; else if (1 != ctx.depth ()) argv += " gray:-"; else argv += " mono:-"; } else argv += " -"; // Pass output resolutions so they can be embedded where supported // by the data format. argv += " -density " + geom_(ctx_.x_resolution (), ctx_.y_resolution ()); // Specify the "resampling" algorithm and parameters, if necessary. if ( x_resolution_ != ctx.x_resolution () || y_resolution_ != ctx.y_resolution ()) { double x_sample_factor = x_resolution_ / ctx.x_resolution (); double y_sample_factor = y_resolution_ / ctx.y_resolution (); argv += " -scale " + geom_(ctx.width () * x_sample_factor, ctx.height () * y_sample_factor) + "!"; } if (force_extent_) argv += " -extent " + geom_(width_ * x_resolution_, height_ * y_resolution_); if (color_correction_) { if (HAVE_IMAGE_MAGICK && !image_magick_version_before_("6.6.1-0")) argv += " -color-matrix"; else argv += " -recolor"; argv += " \""; for (size_t i = 0; i < sizeof (cct_) / sizeof (*cct_); ++i) argv += lexical_cast< string > (cct_[i]) + " "; argv += "\""; } if (bilevel_) { // Thresholding an already thresholded image should be safe argv += " -threshold " + lexical_cast< string > (threshold_) + "%"; if (image_format_ == "PNG") { argv += " -monochrome"; } else { argv += " -type bilevel"; } } // Prevent GraphicsMagick from converting gray JPEG images to RGB if (HAVE_GRAPHICS_MAGICK && !ctx.is_rgb ()) argv += " -colorspace gray"; if (image_format_) { /**/ if (image_format_ == "GIF" ) argv += " gif:-"; else if (image_format_ == "JPEG") argv += " jpeg:-"; else if (image_format_ == "PDF" ) { if (!bilevel_) argv += " jpeg:-"; else argv += " pbm:-"; } else if (image_format_ == "PNG" ) argv += " png:-"; else if (image_format_ == "PNM" ) argv += " pnm:-"; else if (image_format_ == "TIFF") { argv += " -depth " + lexical_cast< string > (ctx_.depth ()); /**/ if (ctx_.is_rgb ()) argv += " rgb:-"; else { if (HAVE_GRAPHICS_MAGICK && bilevel_) argv += " mono:-"; else argv += " gray:-"; } } else { argv += " -"; } } else { argv += " -depth " + lexical_cast< string > (ctx_.depth ()); /**/ if (ctx_.is_rgb ()) argv += " rgb:-"; else { if (HAVE_GRAPHICS_MAGICK && bilevel_) argv += " mono:-"; else argv += " gray:-"; } } return argv; }