summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mot-encoder.cpp80
1 files changed, 38 insertions, 42 deletions
diff --git a/src/mot-encoder.cpp b/src/mot-encoder.cpp
index a5373d2..fc9b517 100644
--- a/src/mot-encoder.cpp
+++ b/src/mot-encoder.cpp
@@ -707,15 +707,15 @@ int main(int argc, char *argv[])
}
if (dir && not dls_file.empty()) {
- fprintf(stderr, "mot-encoder encoding Slideshow from %s and DLS from %s to %s\n",
+ fprintf(stderr, "mot-encoder encoding Slideshow from '%s' and DLS from '%s' to '%s'\n",
dir, dls_file.c_str(), output);
}
else if (dir) {
- fprintf(stderr, "mot-encoder encoding Slideshow from %s to %s. No DLS.\n",
+ fprintf(stderr, "mot-encoder encoding Slideshow from '%s' to '%s'. No DLS.\n",
dir, output);
}
else if (not dls_file.empty()) {
- fprintf(stderr, "mot-encoder encoding DLS from %s to %s. No Slideshow.\n",
+ fprintf(stderr, "mot-encoder encoding DLS from '%s' to '%s'. No Slideshow.\n",
dls_file.c_str(), output);
}
else {
@@ -809,7 +809,7 @@ int main(int argc, char *argv[])
slides_to_transmit.push_back(md);
if (verbose) {
- fprintf(stderr, "mot-encoder found slide %s, fidx %d\n", imagepath, md.fidx);
+ fprintf(stderr, "mot-encoder found slide '%s', fidx %d\n", imagepath, md.fidx);
}
}
}
@@ -835,12 +835,12 @@ int main(int argc, char *argv[])
ret = encodeFile(output_fd, it->filepath, it->fidx, raw_slides);
if (ret != 1) {
- fprintf(stderr, "mot-encoder Error: cannot encode file %s\n", it->filepath.c_str());
+ fprintf(stderr, "mot-encoder Error: cannot encode file '%s'\n", it->filepath.c_str());
}
if (erase_after_tx) {
if (unlink(it->filepath.c_str()) == -1) {
- fprintf(stderr, "mot-encoder Error: erasing file %s failed: ", it->filepath.c_str());
+ fprintf(stderr, "mot-encoder Error: erasing file '%s' failed: ", it->filepath.c_str());
perror("");
}
}
@@ -892,20 +892,25 @@ DATA_GROUP* createDataGroupLengthIndicator(size_t len) {
}
-// Resize the image or add a black border around it
+void warnOnSmallerImage(size_t height, size_t width, std::string& fname) {
+ if (height < 240 || width < 320)
+ fprintf(stderr, "mot-encoder Warning: Image '%s' smaller than recommended size (%zu x %zu < 320 x 240 px)\n", fname.c_str(), width, height);
+}
+
+
+// Scales the image down if needed,
// so that it is 320x240 pixels.
-// Automatically reduce the quality to make sure the
+// Automatically reduces the quality to make sure the
// blobsize is not too large.
//
// Returns: the blobsize
#if HAVE_MAGICKWAND
-size_t resizeImage(MagickWand* m_wand, unsigned char** blob)
+size_t resizeImage(MagickWand* m_wand, unsigned char** blob, std::string& fname)
{
size_t blobsize;
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) {
@@ -923,30 +928,15 @@ size_t resizeImage(MagickWand* m_wand, unsigned char** blob)
height = MagickGetImageHeight(m_wand);
width = MagickGetImageWidth(m_wand);
- // Make sure smaller images are 320x240 pixels, and
- // add a black border
- bg_wand = NewMagickWand();
-
- p_wand = NewPixelWand();
- PixelSetColor(p_wand, "black");
- MagickNewImage(bg_wand, 320, 240, p_wand);
- DestroyPixelWand(p_wand);
-
- MagickCompositeImage(bg_wand, m_wand, OverCompositeOp, (320-width)/2, (240-height)/2);
-
-
- height = MagickGetImageHeight(bg_wand);
- width = MagickGetImageWidth(bg_wand);
-
- MagickSetImageFormat(bg_wand, "jpg");
+ MagickSetImageFormat(m_wand, "jpg");
int quality = 100;
do {
quality -= 5;
- MagickSetImageCompressionQuality(bg_wand, quality);
- *blob = MagickGetImagesBlob(bg_wand, &blobsize);
+ MagickSetImageCompressionQuality(m_wand, quality);
+ *blob = MagickGetImagesBlob(m_wand, &blobsize);
} while (blobsize > MAXSLIDESIZE && quality > MINQUALITY);
if (blobsize > MAXSLIDESIZE) {
@@ -961,7 +951,9 @@ size_t resizeImage(MagickWand* m_wand, unsigned char** blob)
width, height, blobsize, quality);
}
- DestroyMagickWand(bg_wand);
+ // warn if resized image smaller than default dimension
+ warnOnSmallerImage(height, width, fname);
+
return blobsize;
}
#endif
@@ -1015,7 +1007,7 @@ int encodeFile(int output_fd, std::string& fname, int fidx, bool raw_slides)
err = MagickReadImage(m_wand, fname.c_str());
if (err == MagickFalse) {
- fprintf(stderr, "mot-encoder Error: Unable to load image %s\n",
+ fprintf(stderr, "mot-encoder Error: Unable to load image '%s'\n",
fname.c_str());
goto encodefile_out;
@@ -1038,7 +1030,7 @@ int encodeFile(int output_fd, std::string& fname, int fidx, bool raw_slides)
orig_is_jpeg = true;
if (verbose) {
- fprintf(stderr, "mot-encoder image: %s (id=%d)."
+ fprintf(stderr, "mot-encoder image: '%s' (id=%d)."
" Original size: %zu x %zu. (%s, q=%zu, progr=%s)\n",
fname.c_str(), fidx, width, height, orig_format, orig_quality, jpeg_progr ? "y" : "n");
}
@@ -1048,13 +1040,13 @@ int encodeFile(int output_fd, std::string& fname, int fidx, bool raw_slides)
jfif_not_png = false;
if (verbose) {
- fprintf(stderr, "mot-encoder image: %s (id=%d)."
+ fprintf(stderr, "mot-encoder image: '%s' (id=%d)."
" Original size: %zu x %zu. (%s)\n",
fname.c_str(), fidx, width, height, orig_format);
}
}
else if (verbose) {
- fprintf(stderr, "mot-encoder image: %s (id=%d)."
+ fprintf(stderr, "mot-encoder image: '%s' (id=%d)."
" Original size: %zu x %zu. (%s)\n",
fname.c_str(), fidx, width, height, orig_format);
}
@@ -1062,20 +1054,20 @@ int encodeFile(int output_fd, std::string& fname, int fidx, bool raw_slides)
free(orig_format);
}
else {
- fprintf(stderr, "mot-encoder Warning: Unable to detect image format %s\n",
+ fprintf(stderr, "mot-encoder Warning: Unable to detect image format of '%s'\n",
fname.c_str());
- fprintf(stderr, "mot-encoder image: %s (id=%d). Original size: %zu x %zu.\n",
+ fprintf(stderr, "mot-encoder image: '%s' (id=%d). Original size: %zu x %zu.\n",
fname.c_str(), fidx, width, height);
}
- if ((orig_is_jpeg || orig_is_png) && height == 240 && width == 320 && not jpeg_progr) {
+ if ((orig_is_jpeg || orig_is_png) && height <= 240 && width <= 320 && not jpeg_progr) {
// Don't recompress the image and check if the blobsize is suitable
blob = MagickGetImagesBlob(m_wand, &blobsize);
- if (blobsize < MAXSLIDESIZE) {
+ if (blobsize <= MAXSLIDESIZE) {
if (verbose) {
- fprintf(stderr, "mot-encoder image: %s (id=%d). No resize needed: %zu Bytes\n",
+ fprintf(stderr, "mot-encoder image: '%s' (id=%d). No resize needed: %zu Bytes\n",
fname.c_str(), fidx, blobsize);
}
resize_required = false;
@@ -1083,11 +1075,15 @@ int encodeFile(int output_fd, std::string& fname, int fidx, bool raw_slides)
}
if (resize_required) {
- blobsize = resizeImage(m_wand, &blob);
+ blobsize = resizeImage(m_wand, &blob, fname);
// resizeImage always creates a jpg output
jfif_not_png = true;
}
+ else {
+ // warn if unresized image smaller than default dimension
+ warnOnSmallerImage(height, width, fname);
+ }
#else
fprintf(stderr, "mot-encoder has not been compiled with MagickWand, only RAW slides are supported!\n");
@@ -1099,7 +1095,7 @@ int encodeFile(int output_fd, std::string& fname, int fidx, bool raw_slides)
// read file
FILE* pFile = fopen(fname.c_str(), "rb");
if (pFile == NULL) {
- fprintf(stderr, "mot-encoder Error: Unable to load file %s\n",
+ fprintf(stderr, "mot-encoder Error: Unable to load file '%s'\n",
fname.c_str());
goto encodefile_out;
}
@@ -1110,7 +1106,7 @@ int encodeFile(int output_fd, std::string& fname, int fidx, bool raw_slides)
rewind(pFile);
if (blobsize > MAXSLIDESIZE) {
- fprintf(stderr, "mot-encoder Warning: blob in raw-slide %s too large\n",
+ fprintf(stderr, "mot-encoder Warning: blob in raw-slide '%s' too large\n",
fname.c_str());
}
@@ -1229,7 +1225,7 @@ void createMotHeader(size_t blobsize, int fidx, unsigned char* mothdr, int* moth
jfif_not_png ? "jpg" : "png" );
if (verbose) {
- fprintf(stderr, "mot-encoder writing image as %s\n", cntemp);
+ fprintf(stderr, "mot-encoder writing image as '%s'\n", cntemp);
}
for (i = 0; i < strlen(cntemp); i++) {