aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2020-09-14 14:53:28 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2020-09-14 14:53:28 +0200
commit6ea59e3c2b2fba81ed01a11c0ddfdd2d26455bfb (patch)
treed293f37b54f6d63fdb7c2fb3694822f0c692547a
parentbe7c6e78d334ffa9919b970aaecf2ff5f27a0354 (diff)
downloadODR-PadEnc-6ea59e3c2b2fba81ed01a11c0ddfdd2d26455bfb.tar.gz
ODR-PadEnc-6ea59e3c2b2fba81ed01a11c0ddfdd2d26455bfb.tar.bz2
ODR-PadEnc-6ea59e3c2b2fba81ed01a11c0ddfdd2d26455bfb.zip
Handle slides ending in _PadEncRawMode.jpg always in RAW
-rw-r--r--README.md2
-rw-r--r--src/odr-padenc.cpp2
-rw-r--r--src/sls.cpp56
-rw-r--r--src/sls.h4
4 files changed, 45 insertions, 19 deletions
diff --git a/README.md b/README.md
index fe47d46..5d00e24 100644
--- a/README.md
+++ b/README.md
@@ -67,6 +67,8 @@ RAW Format
If ImageMagick is not compiled in, or when enabled with the `-R` option, the images
are not modified, and are transmitted as-is. Use this if you can guarantee that
the generated files are smaller than 50kB and not larger than 320x240 pixels.
+Files whose name end in `_PadEncRawMode.png` or `_PadEncRawMode.jpg` will always
+be transmitted in RAW mode.
It may be useful to apply [`optipng`](http://optipng.sourceforge.net) to any PNG file prior to transmission.
Supported Encoders
diff --git a/src/odr-padenc.cpp b/src/odr-padenc.cpp
index da47d5b..e348713 100644
--- a/src/odr-padenc.cpp
+++ b/src/odr-padenc.cpp
@@ -84,6 +84,8 @@ static void usage(const char* name) {
" Default: %zu (Simple Profile)\n"
" -R, --raw-slides Do not process slides. Integrity checks and resizing\n"
" slides is skipped. Use this if you know what you are doing !\n"
+ " Slides whose name ends in _PadEncRawMode.jpg or _PadEncRawMode.png are always transmitted unprocessed, regardless of\n"
+ " the -R option being set \n"
" It is useful only when -d is used\n"
" -v, --verbose Print more information to the console (may be used more than once)\n"
" --version Print version information and quit\n"
diff --git a/src/sls.cpp b/src/sls.cpp
index f0b72f7..f6cfb6f 100644
--- a/src/sls.cpp
+++ b/src/sls.cpp
@@ -369,6 +369,19 @@ static void dump_slide(const std::string& dump_name, const uint8_t *blob, size_t
fclose(fd);
}
+static bool filename_specifies_raw_mode(const std::string& fname)
+{
+ const size_t sep = fname.rfind("_");
+ if (sep != std::string::npos) {
+ std::string suffix = fname.substr(sep, std::string::npos);
+ std::transform(suffix.begin(), suffix.end(), suffix.begin(), ::tolower);
+ return suffix == "_padencrawmode.png" or suffix == "_padencrawmode.jpg";
+ }
+ else {
+ return false;
+ }
+}
+
bool SLSEncoder::encodeSlide(const std::string& fname, int fidx, bool raw_slides, size_t max_slide_size, const std::string& dump_name)
{
bool result = false;
@@ -377,11 +390,14 @@ bool SLSEncoder::encodeSlide(const std::string& fname, int fidx, bool raw_slides
MagickWand *m_wand = NULL;
#endif
- uint8_t* blob = NULL;
+ uint8_t *raw_blob = NULL;
+ uint8_t *magick_blob = NULL;
size_t blobsize;
bool jfif_not_png = true;
- if (!raw_slides) {
+ const bool raw_slide = filename_specifies_raw_mode(fname) or raw_slides;
+
+ if (!raw_slide) {
#if HAVE_MAGICKWAND
/*! By default, we do resize the image to 320x240, with a quality such that
* the blobsize is at most MAXSLIDESIZE.
@@ -451,7 +467,7 @@ bool SLSEncoder::encodeSlide(const std::string& fname, int fidx, bool raw_slides
if (native_support && height <= 240 && width <= 320 && not jpeg_progr) {
// Don't recompress the image and check if the blobsize is suitable
- blob = MagickGetImageBlob(m_wand, &blobsize);
+ magick_blob = MagickGetImageBlob(m_wand, &blobsize);
if (blobsize <= max_slide_size) {
if (verbose) {
@@ -460,13 +476,13 @@ bool SLSEncoder::encodeSlide(const std::string& fname, int fidx, bool raw_slides
}
resize_required = false;
} else {
- MagickRelinquishMemory(blob);
- blob = NULL;
+ MagickRelinquishMemory(magick_blob);
+ magick_blob = NULL;
}
}
if (resize_required) {
- blobsize = resizeImage(m_wand, &blob, fname, &jfif_not_png, max_slide_size);
+ blobsize = resizeImage(m_wand, &magick_blob, fname, &jfif_not_png, max_slide_size);
} else {
// warn if unresized image smaller than default dimension
warnOnSmallerImage(height, width, fname);
@@ -501,15 +517,15 @@ bool SLSEncoder::encodeSlide(const std::string& fname, int fidx, bool raw_slides
}
// allocate memory to contain the whole file:
- blob = (uint8_t*) malloc(blobsize);
- if (blob == NULL) {
+ raw_blob = (uint8_t*) malloc(blobsize);
+ if (raw_blob == NULL) {
fprintf(stderr, "ODR-PadEnc Error: Memory allocation error\n");
fclose(pFile);
goto encodefile_out;
}
// copy the file into the buffer:
- if (fread(blob, blobsize, 1, pFile) != 1) {
+ if (fread(raw_blob, blobsize, 1, pFile) != 1) {
fprintf(stderr, "ODR-PadEnc Error: Could not read file\n");
fclose(pFile);
goto encodefile_out;
@@ -537,6 +553,12 @@ bool SLSEncoder::encodeSlide(const std::string& fname, int fidx, bool raw_slides
}
if (blobsize) {
+ if (raw_blob == nullptr and magick_blob == nullptr) {
+ fprintf(stderr, "ODR-PadEnc logic error: either raw_blob or magick_blob must be non-null! See src/sls.cpp line %d\n", __LINE__);
+ abort();
+ }
+ const uint8_t *blob = raw_blob ? raw_blob : magick_blob;
+
MSCDG msc;
DATA_GROUP* dgli;
DATA_GROUP* mscdg;
@@ -561,7 +583,7 @@ bool SLSEncoder::encodeSlide(const std::string& fname, int fidx, bool raw_slides
// MOT Body
for (size_t i = 0; i < nseg; i++) {
- unsigned char *curseg = blob + i * MAXSEGLEN;
+ const uint8_t *curseg = blob + i * MAXSEGLEN;
size_t curseglen;
int last;
@@ -589,14 +611,14 @@ bool SLSEncoder::encodeSlide(const std::string& fname, int fidx, bool raw_slides
}
encodefile_out:
- if (blob) {
- if(raw_slides) {
- free(blob);
- } else {
+ if (raw_blob) {
+ free(raw_blob);
+ }
+
+ if (magick_blob) {
#if HAVE_MAGICKWAND
- MagickRelinquishMemory(blob);
+ MagickRelinquishMemory(magick_blob);
#endif
- }
}
#if HAVE_MAGICKWAND
@@ -730,7 +752,7 @@ uint8_vector_t SLSEncoder::createMotHeader(size_t blobsize, int fidx, bool jfif_
void SLSEncoder::createMscDG(MSCDG* msc, unsigned short int dgtype,
int *cindex, unsigned short int segnum, unsigned short int lastseg,
- unsigned short int tid, unsigned char* data,
+ unsigned short int tid, const uint8_t* data,
unsigned short int datalen)
{
msc->extflag = 0;
diff --git a/src/sls.h b/src/sls.h
index 07e05dc..dbbcf3c 100644
--- a/src/sls.h
+++ b/src/sls.h
@@ -73,7 +73,7 @@ struct MSCDG {
unsigned char rcount; // 3 bits
unsigned short int seglen; // 13 bits
// Mot segment
- unsigned char* segdata;
+ const uint8_t* segdata;
// MSC data group CRC
unsigned short int crc; // 16 bits
};
@@ -237,7 +237,7 @@ private:
uint8_vector_t createMotHeader(size_t blobsize, int fidx, bool jfif_not_png, const std::string &params_fname);
void createMscDG(MSCDG* msc, unsigned short int dgtype,
int *cindex, unsigned short int segnum, unsigned short int lastseg,
- unsigned short int tid, unsigned char* data,
+ unsigned short int tid, const uint8_t* data,
unsigned short int datalen);
DATA_GROUP* packMscDG(MSCDG* msc);