Skip to content

Commit

Permalink
Add choice of codec (JP2 or J2K) when writing jp2k files.
Browse files Browse the repository at this point in the history
* also bump the patch rev number: from 1.81.0 --> 1.81.1
  • Loading branch information
DanBloomberg committed Jun 9, 2021
1 parent f177527 commit 6dfffd6
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 22 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake Targets")
project(leptonica C CXX)

set(VERSION_MAJOR 1)
set(VERSION_MINOR 82)
set(VERSION_PATCH 0)
set(VERSION_MINOR 81)
set(VERSION_PATCH 1)
set(VERSION_PLAIN ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
set(MINIMUM_WEBPMUX_VERSION 0.5.0)

Expand Down
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = Leptonica
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 1.81.0
PROJECT_NUMBER = 1.81.1

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AC_PREREQ([2.50])
AC_INIT([leptonica], [1.81.0])
AC_INIT([leptonica], [1.81.1])
AC_CONFIG_AUX_DIR([config])
AC_CONFIG_HEADERS([config_auto.h:config/config.h.in])
AC_CONFIG_SRCDIR([src/adaptmap.c])
Expand Down
4 changes: 2 additions & 2 deletions src/allheaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#define LIBLEPT_MAJOR_VERSION 1
#define LIBLEPT_MINOR_VERSION 81
#define LIBLEPT_PATCH_VERSION 0
#define LIBLEPT_PATCH_VERSION 1

#include "alltypes.h"

Expand Down Expand Up @@ -1085,7 +1085,7 @@ LEPT_DLL extern l_int32 fgetJp2kResolution ( FILE *fp, l_int32 *pxres, l_int32 *
LEPT_DLL extern PIX * pixReadJp2k ( const char *filename, l_uint32 reduction, BOX *box, l_int32 hint, l_int32 debug );
LEPT_DLL extern PIX * pixReadStreamJp2k ( FILE *fp, l_uint32 reduction, BOX *box, l_int32 hint, l_int32 debug );
LEPT_DLL extern l_ok pixWriteJp2k ( const char *filename, PIX *pix, l_int32 quality, l_int32 nlevels, l_int32 hint, l_int32 debug );
LEPT_DLL extern l_ok pixWriteStreamJp2k ( FILE *fp, PIX *pix, l_int32 quality, l_int32 nlevels, l_int32 hint, l_int32 debug );
LEPT_DLL extern l_ok pixWriteStreamJp2k ( FILE *fp, PIX *pix, l_int32 quality, l_int32 nlevels, l_int32 codec, l_int32 hint, l_int32 debug );
LEPT_DLL extern PIX * pixReadMemJp2k ( const l_uint8 *data, size_t size, l_uint32 reduction, BOX *box, l_int32 hint, l_int32 debug );
LEPT_DLL extern l_ok pixWriteMemJp2k ( l_uint8 **pdata, size_t *psize, PIX *pix, l_int32 quality, l_int32 nlevels, l_int32 hint, l_int32 debug );
LEPT_DLL extern PIX * pixReadJpeg ( const char *filename, l_int32 cmapflag, l_int32 reduction, l_int32 *pnwarn, l_int32 hint );
Expand Down
2 changes: 1 addition & 1 deletion src/allheaders_top.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#define LIBLEPT_MAJOR_VERSION 1
#define LIBLEPT_MINOR_VERSION 81
#define LIBLEPT_PATCH_VERSION 0
#define LIBLEPT_PATCH_VERSION 1

#include "alltypes.h"

Expand Down
26 changes: 18 additions & 8 deletions src/jp2kio.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,9 @@ PIX *pix = NULL;
* reduction factors of 1, 2, 4, 8 and 16 are encoded, and retrieval
* is done at the level requested when reading. For default,
* use either 5 or 0.
* (3) The %hint parameter is not yet in use.
* (4) For now, we only support 1 "layer" for quality.
* (3) By default, we use the JP2 codec.
* (4) The %hint parameter is not yet in use.
* (5) For now, we only support 1 "layer" for quality.
* </pre>
*/
l_ok
Expand All @@ -497,7 +498,8 @@ FILE *fp;
if ((fp = fopenWriteStream(filename, "wb+")) == NULL)
return ERROR_INT("stream not opened", procName, 1);

if (pixWriteStreamJp2k(fp, pix, quality, nlevels, hint, debug)) {
if (pixWriteStreamJp2k(fp, pix, quality, nlevels, L_JP2_CODEC,
hint, debug)) {
fclose(fp);
return ERROR_INT("pix not written to stream", procName, 1);
}
Expand All @@ -514,21 +516,21 @@ FILE *fp;
* \param[in] pix any depth, cmap is OK
* \param[in] quality SNR > 0; 0 for default (34); 100 for lossless
* \param[in] nlevels <= 10
* \param[in] codec L_JP2_CODEC or L_J2K_CODEC
* \param[in] hint a bitwise OR of L_JP2K_* values; 0 for default
* \param[in] debug output callback messages, etc
* \return 0 if OK, 1 on error
* <pre>
* Notes:
* (1) See pixWriteJp2k() for usage.
* (2) For an encoder with more encoding options, see, e.g.,
* https://github.com/OpenJPEG/openjpeg/blob/master/tests/test_tile_encoder.c
* </pre>
*/
l_ok
pixWriteStreamJp2k(FILE *fp,
PIX *pix,
l_int32 quality,
l_int32 nlevels,
l_int32 codec,
l_int32 hint,
l_int32 debug)
{
Expand Down Expand Up @@ -563,6 +565,8 @@ opj_image_t *image = NULL;
L_WARNING("nlevels = %d > 10; setting to 10\n", procName, nlevels);
nlevels = 10;
}
if (codec != L_JP2_CODEC && codec != L_J2K_CODEC)
return ERROR_INT("valid codec not identified\n", procName, 1);

opjVersion = opj_version();
if (opjVersion[0] != '2') {
Expand Down Expand Up @@ -620,7 +624,11 @@ opj_image_t *image = NULL;
}

/* Get the encoder handle */
if ((l_codec = opj_create_compress(OPJ_CODEC_JP2)) == NULL) {
if (codec == L_JP2_CODEC)
l_codec = opj_create_compress(OPJ_CODEC_JP2);
else /* codec == L_J2K_CODEC */
l_codec = opj_create_compress(OPJ_CODEC_J2K);
if (!l_codec) {
opj_image_destroy(image);
LEPT_FREE(parameters.cp_comment);
return ERROR_INT("failed to get the encoder handle\n", procName, 1);
Expand Down Expand Up @@ -859,7 +867,8 @@ FILE *fp;
#if HAVE_FMEMOPEN
if ((fp = open_memstream((char **)pdata, psize)) == NULL)
return ERROR_INT("stream not opened", procName, 1);
ret = pixWriteStreamJp2k(fp, pix, quality, nlevels, hint, debug);
ret = pixWriteStreamJp2k(fp, pix, quality, nlevels, L_JP2_CODEC,
hint, debug);
fputc('\0', fp);
fclose(fp);
*psize = *psize - 1;
Expand All @@ -872,7 +881,8 @@ FILE *fp;
if ((fp = tmpfile()) == NULL)
return ERROR_INT("tmpfile stream not opened", procName, 1);
#endif /* _WIN32 */
ret = pixWriteStreamJp2k(fp, pix, quality, nlevels, hint, debug);
ret = pixWriteStreamJp2k(fp, pix, quality, nlevels, L_JP2_CODEC,
hint, debug);
rewind(fp);
*pdata = l_binaryReadStream(fp, psize);
fclose(fp);
Expand Down
9 changes: 5 additions & 4 deletions src/jp2kiostub.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,16 @@ PIX * pixReadStreamJp2k(FILE *fp, l_uint32 reduction, BOX *box,
/* ----------------------------------------------------------------------*/

l_ok pixWriteJp2k(const char *filename, PIX *pix, l_int32 quality,
l_int32 nlevels, l_int32 hint, l_int32 debug)
l_int32 nlevels, l_int32 hint, l_int32 debug)
{
return ERROR_INT("function not present", "pixWriteJp2k", 1);
}

/* ----------------------------------------------------------------------*/

l_ok pixWriteStreamJp2k(FILE *fp, PIX *pix, l_int32 quality,
l_int32 nlevels, l_int32 hint, l_int32 debug)
l_int32 nlevels, l_int32 codec,
l_int32 hint, l_int32 debug)
{
return ERROR_INT("function not present", "pixWriteStreamJp2k", 1);
}
Expand All @@ -85,8 +86,8 @@ PIX * pixReadMemJp2k(const l_uint8 *data, size_t size, l_uint32 reduction,
/* ----------------------------------------------------------------------*/

l_ok pixWriteMemJp2k(l_uint8 **pdata, size_t *psize, PIX *pix,
l_int32 quality, l_int32 nlevels, l_int32 hint,
l_int32 debug)
l_int32 quality, l_int32 nlevels, l_int32 hint,
l_int32 debug)
{
return ERROR_INT("function not present", "pixWriteMemJp2k", 1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/makefile.static
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ LIBRARIAN_SHARED = gcc -shared
# <libname>.X, and <libname>, where Y is the minor revision number.
MAJOR_REV = 1
MINOR_REV = 81
PATCH_REV = 0
PATCH_REV = 1

#########################################################

Expand Down
2 changes: 1 addition & 1 deletion src/writefile.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ pixWriteStream(FILE *fp,
return pixWriteStreamGif(fp, pix);

case IFF_JP2:
return pixWriteStreamJp2k(fp, pix, 34, 4, 0, 0);
return pixWriteStreamJp2k(fp, pix, 34, 4, L_JP2_CODEC, 0, 0);

case IFF_WEBP:
return pixWriteStreamWebP(fp, pix, 80, 0);
Expand Down
2 changes: 1 addition & 1 deletion sw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void build(Solution &s)
t += "org.sw.demo.webmproject.webp"_dep;
};

auto &leptonica = s.addTarget<LibraryTarget>("danbloomberg.leptonica", "1.82.0");
auto &leptonica = s.addTarget<LibraryTarget>("danbloomberg.leptonica", "1.81.1");
leptonica += Git("https://github.com/DanBloomberg/leptonica");

{
Expand Down
3 changes: 3 additions & 0 deletions version-notes.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ <h2 align=center> <IMG SRC="moller52.jpg" border=1 ALIGN_MIDDLE> </h2>

<pre>

1.81.1 June 10, 2021
* Added choice of codec (JP2 or J2K) when writing jp2k files.

1.81.0 June 6, 2021
* Fixed problems with tiff pdf wrapping photometry.
* Fixed scaling issues in prog/cleanpdf for printing.
Expand Down

0 comments on commit 6dfffd6

Please sign in to comment.