Пример #1
0
void
bottom_padder::boi (const context& ctx)
{
  logic_error e ("bottom_padder only works with raster images");

  if (!ctx.is_raster_image ())
    BOOST_THROW_EXCEPTION (e);

  streamsize pixels = width_.amount< double > () * ctx.x_resolution ();
  if (pixels != ctx_.width ())
    log::error ("width padding not supported yet");

  streamsize lines = height_.amount< double > () * ctx.y_resolution ();

  ctx_ = ctx;
  ctx_.height (lines);

  octets_left_ = lines * ctx_.octets_per_line ();
}
Пример #2
0
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);
}
Пример #3
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;
}