A fix to the jpeg driver making it operate with parameters like the other file formats.

This commit is contained in:
Blake Thompson 2015-03-05 21:51:48 -06:00
parent 34e02bec38
commit ea6677df37
4 changed files with 28 additions and 6 deletions

View file

@ -340,7 +340,8 @@ enum image_dtype : std::uint8_t
image_dtype_gray64,
image_dtype_gray64s,
image_dtype_gray64f,
image_dtype_null
image_dtype_null,
IMAGE_DTYPE_MAX
};
} // end ns

View file

@ -306,6 +306,7 @@ inline image_any create_image_any(int width,
case image_dtype_null:
return image_any(std::move(image_null()));
case image_dtype_rgba8:
case IMAGE_DTYPE_MAX:
default:
return image_any(std::move(image_rgba8(width, height, initialize, premultiplied, painted)));
}

View file

@ -340,6 +340,10 @@ MAPNIK_DECL image_any image_copy(image_any const& data, image_dtype type, double
return image_any(std::move(image_copy<image_gray64f>(data, offset, scaling)));
case image_dtype_null:
throw std::runtime_error("Can not cast a null image");
case IMAGE_DTYPE_MAX:
default:
throw std::runtime_error("Can not cast unknown type");
}
throw std::runtime_error("Unknown image type passed");
}

View file

@ -46,16 +46,32 @@ jpeg_saver::jpeg_saver(std::ostream & stream, std::string const& t):
stream_(stream), t_(t) {}
template <typename T>
void process_rgba8_jpeg(T const& image, std::string const& t, std::ostream & stream)
void process_rgba8_jpeg(T const& image, std::string const& type, std::ostream & stream)
{
#if defined(HAVE_JPEG)
int quality = 85;
std::string val = t.substr(5);
if (!val.empty())
//std::string val = type.substr(4);
if (type != "jpeg")
{
if (!mapnik::util::string2int(val,quality) || quality < 0 || quality > 100)
boost::char_separator<char> sep(":");
boost::tokenizer< boost::char_separator<char> > tokens(type, sep);
for (auto const& t : tokens)
{
throw ImageWriterException("invalid jpeg quality: '" + val + "'");
if (t == "jpeg")
{
continue;
}
else if (boost::algorithm::starts_with(t, "quality="))
{
std::string val = t.substr(8);
if (!val.empty())
{
if (!mapnik::util::string2int(val,quality) || quality < 0 || quality > 100)
{
throw ImageWriterException("invalid jpeg quality: '" + val + "'");
}
}
}
}
}
save_as_jpeg(stream, quality, image);