aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Pöschel <github@basicmaster.de>2015-11-29 20:38:49 +0100
committerStefan Pöschel <github@basicmaster.de>2015-11-29 20:38:49 +0100
commit4bde4dc1b818520cd5435162f41d0e9a380d1957 (patch)
tree2708df3fe2b63907a8ed37e4cad0527ea2f9a19c
parentc13636b1bba681b6e0e7ecf220af03d2a163638e (diff)
downloadODR-PadEnc-4bde4dc1b818520cd5435162f41d0e9a380d1957.tar.gz
ODR-PadEnc-4bde4dc1b818520cd5435162f41d0e9a380d1957.tar.bz2
ODR-PadEnc-4bde4dc1b818520cd5435162f41d0e9a380d1957.zip
MOT encoder: fix possible odd target image size
The method MagickBorderImage adds the same amount of border on left/right resp. top/bottom side. Thus if the source image has an odd size (e.g. 201x200 px), the resulting size gets odd, too (here 319x240 px). To prevent this, the border is added by inserting the resized image centered into a black background of 320x240 px.
-rw-r--r--src/mot-encoder.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/mot-encoder.cpp b/src/mot-encoder.cpp
index 9abbd0e..e1c965f 100644
--- a/src/mot-encoder.cpp
+++ b/src/mot-encoder.cpp
@@ -905,6 +905,7 @@ size_t resizeImage(MagickWand* m_wand, unsigned char** blob)
size_t height = MagickGetImageHeight(m_wand);
size_t width = MagickGetImageWidth(m_wand);
+ MagickWand *bg_wand = NULL;
PixelWand *p_wand = NULL;
while (height > 240 || width > 320) {
@@ -924,23 +925,28 @@ size_t resizeImage(MagickWand* m_wand, unsigned char** blob)
// Make sure smaller images are 320x240 pixels, and
// add a black border
+ bg_wand = NewMagickWand();
+
p_wand = NewPixelWand();
PixelSetColor(p_wand, "black");
- MagickBorderImage(m_wand, p_wand, (320-width)/2, (240-height)/2);
+ MagickNewImage(bg_wand, 320, 240, p_wand);
DestroyPixelWand(p_wand);
- height = MagickGetImageHeight(m_wand);
- width = MagickGetImageWidth(m_wand);
+ MagickCompositeImage(bg_wand, m_wand, OverCompositeOp, (320-width)/2, (240-height)/2);
- MagickSetImageFormat(m_wand, "jpg");
+
+ height = MagickGetImageHeight(bg_wand);
+ width = MagickGetImageWidth(bg_wand);
+
+ MagickSetImageFormat(bg_wand, "jpg");
int quality = 100;
do {
quality -= 5;
- MagickSetImageCompressionQuality(m_wand, quality);
- *blob = MagickGetImagesBlob(m_wand, &blobsize);
+ MagickSetImageCompressionQuality(bg_wand, quality);
+ *blob = MagickGetImagesBlob(bg_wand, &blobsize);
} while (blobsize > MAXSLIDESIZE && quality > MINQUALITY);
if (blobsize > MAXSLIDESIZE) {
@@ -954,6 +960,8 @@ size_t resizeImage(MagickWand* m_wand, unsigned char** blob)
fprintf(stderr, "mot-encoder resized image to %zu x %zu. Size after compression %zu bytes (q=%d)\n",
width, height, blobsize, quality);
}
+
+ DestroyMagickWand(bg_wand);
return blobsize;
}
#endif