mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
workaround to avoid manually copying library files
This commit is contained in:
parent
2c50bea22c
commit
28089de353
2
oss-internship-2020/openjpeg/.gitignore
vendored
2
oss-internship-2020/openjpeg/.gitignore
vendored
|
@ -1 +1,3 @@
|
|||
build/
|
||||
examples/convert_lib.cc
|
||||
examples/convert_lib.h
|
||||
|
|
|
@ -12,13 +12,27 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# copy of one of the converting functions
|
||||
# put here to omit the library's complex build logic
|
||||
add_custom_target(patching_reverse_before
|
||||
COMMAND cd ${PROJECT_SOURCE_DIR}/openjpeg/src/bin/jp2/ && patch -R --no-backup-if-mismatch -r /dev/null convert.c < ${PROJECT_SOURCE_DIR}/examples/convert.patch > /dev/null || (exit 0)
|
||||
COMMAND cd ${PROJECT_SOURCE_DIR}/openjpeg/src/bin/jp2/ && patch -R --no-backup-if-mismatch -r /dev/null convert.h < ${PROJECT_SOURCE_DIR}/examples/convert_h.patch > /dev/null || (exit 0)
|
||||
)
|
||||
|
||||
add_custom_command(
|
||||
DEPENDS opj_decompress opj_compress opj_dump
|
||||
OUTPUT ${PROJECT_SOURCE_DIR}/examples/convert_lib.cc ${PROJECT_SOURCE_DIR}/examples/convert_lib.h
|
||||
COMMAND cd ${PROJECT_SOURCE_DIR}/openjpeg/src/bin/jp2/ && patch convert.c < ${PROJECT_SOURCE_DIR}/examples/convert.patch > /dev/null && cp convert.c ${PROJECT_SOURCE_DIR}/examples/convert_lib.cc
|
||||
COMMAND cd ${PROJECT_SOURCE_DIR}/openjpeg/src/bin/jp2/ && patch convert.h < ${PROJECT_SOURCE_DIR}/examples/convert_h.patch > /dev/null && cp convert.h ${PROJECT_SOURCE_DIR}/examples/convert_lib.h
|
||||
)
|
||||
|
||||
add_library(convert_helper STATIC
|
||||
convert_helper.h
|
||||
convert_helper.cc
|
||||
${PROJECT_SOURCE_DIR}/examples/convert_lib.cc
|
||||
${PROJECT_SOURCE_DIR}/examples/convert_lib.h
|
||||
)
|
||||
|
||||
add_dependencies(opj_decompress patching_reverse_before)
|
||||
add_dependencies(opj_compress patching_reverse_before)
|
||||
add_dependencies(opj_dump patching_reverse_before)
|
||||
|
||||
add_executable(decompress_sandboxed
|
||||
decompress_example.cc
|
||||
)
|
||||
|
@ -33,3 +47,10 @@ target_link_libraries(convert_helper PRIVATE
|
|||
openjp2_sapi
|
||||
sapi::sapi
|
||||
)
|
||||
|
||||
add_custom_target(patching_reverse ALL
|
||||
COMMAND cd ${PROJECT_SOURCE_DIR}/openjpeg/src/bin/jp2/ && patch -R convert.c < ${PROJECT_SOURCE_DIR}/examples/convert.patch > /dev/null
|
||||
COMMAND cd ${PROJECT_SOURCE_DIR}/openjpeg/src/bin/jp2/ && patch -R convert.h < ${PROJECT_SOURCE_DIR}/examples/convert_h.patch > /dev/null
|
||||
)
|
||||
|
||||
add_dependencies(patching_reverse decompress_sandboxed)
|
||||
|
|
2871
oss-internship-2020/openjpeg/examples/convert.patch
Normal file
2871
oss-internship-2020/openjpeg/examples/convert.patch
Normal file
File diff suppressed because it is too large
Load Diff
135
oss-internship-2020/openjpeg/examples/convert_h.patch
Normal file
135
oss-internship-2020/openjpeg/examples/convert_h.patch
Normal file
|
@ -0,0 +1,135 @@
|
|||
--- convert.h 2020-08-27 15:46:45.028628305 +0000
|
||||
+++ ../../../../examples/convert_helper.h 2020-08-27 14:26:02.155455250 +0000
|
||||
@@ -1,126 +1,8 @@
|
||||
-/*
|
||||
- * The copyright in this software is being made available under the 2-clauses
|
||||
- * BSD License, included below. This software may be subject to other third
|
||||
- * party and contributor rights, including patent rights, and no such rights
|
||||
- * are granted under this license.
|
||||
- *
|
||||
- * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
|
||||
- * Copyright (c) 2002-2014, Professor Benoit Macq
|
||||
- * Copyright (c) 2001-2003, David Janssens
|
||||
- * Copyright (c) 2002-2003, Yannick Verschueren
|
||||
- * Copyright (c) 2003-2007, Francois-Olivier Devaux
|
||||
- * Copyright (c) 2003-2014, Antonin Descampe
|
||||
- * Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
- * All rights reserved.
|
||||
- *
|
||||
- * Redistribution and use in source and binary forms, with or without
|
||||
- * modification, are permitted provided that the following conditions
|
||||
- * are met:
|
||||
- * 1. Redistributions of source code must retain the above copyright
|
||||
- * notice, this list of conditions and the following disclaimer.
|
||||
- * 2. Redistributions in binary form must reproduce the above copyright
|
||||
- * notice, this list of conditions and the following disclaimer in the
|
||||
- * documentation and/or other materials provided with the distribution.
|
||||
- *
|
||||
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
- * POSSIBILITY OF SUCH DAMAGE.
|
||||
- */
|
||||
-#ifndef __J2K_CONVERT_H
|
||||
-#define __J2K_CONVERT_H
|
||||
+// imagetopnm and the two functions it calls internaly are copied from the
|
||||
+// library's tools; from openjpeg/src/bin/jp2/convert.c
|
||||
|
||||
-/**@name RAW component encoding parameters */
|
||||
-/*@{*/
|
||||
-typedef struct raw_comp_cparameters {
|
||||
- /** subsampling in X direction */
|
||||
- int dx;
|
||||
- /** subsampling in Y direction */
|
||||
- int dy;
|
||||
- /*@}*/
|
||||
-} raw_comp_cparameters_t;
|
||||
-
|
||||
-/**@name RAW image encoding parameters */
|
||||
-/*@{*/
|
||||
-typedef struct raw_cparameters {
|
||||
- /** width of the raw image */
|
||||
- int rawWidth;
|
||||
- /** height of the raw image */
|
||||
- int rawHeight;
|
||||
- /** number of components of the raw image */
|
||||
- int rawComp;
|
||||
- /** bit depth of the raw image */
|
||||
- int rawBitDepth;
|
||||
- /** signed/unsigned raw image */
|
||||
- OPJ_BOOL rawSigned;
|
||||
- /** raw components parameters */
|
||||
- raw_comp_cparameters_t *rawComps;
|
||||
- /*@}*/
|
||||
-} raw_cparameters_t;
|
||||
-
|
||||
-/* Component precision clipping */
|
||||
-void clip_component(opj_image_comp_t* component, OPJ_UINT32 precision);
|
||||
-/* Component precision scaling */
|
||||
-void scale_component(opj_image_comp_t* component, OPJ_UINT32 precision);
|
||||
-
|
||||
-/* planar / interleaved conversions */
|
||||
-typedef void (* convert_32s_CXPX)(const OPJ_INT32* pSrc, OPJ_INT32* const* pDst,
|
||||
- OPJ_SIZE_T length);
|
||||
-extern const convert_32s_CXPX convert_32s_CXPX_LUT[5];
|
||||
-typedef void (* convert_32s_PXCX)(OPJ_INT32 const* const* pSrc, OPJ_INT32* pDst,
|
||||
- OPJ_SIZE_T length, OPJ_INT32 adjust);
|
||||
-extern const convert_32s_PXCX convert_32s_PXCX_LUT[5];
|
||||
-/* bit depth conversions */
|
||||
-typedef void (* convert_XXx32s_C1R)(const OPJ_BYTE* pSrc, OPJ_INT32* pDst,
|
||||
- OPJ_SIZE_T length);
|
||||
-extern const convert_XXx32s_C1R convert_XXu32s_C1R_LUT[9]; /* up to 8bpp */
|
||||
-typedef void (* convert_32sXXx_C1R)(const OPJ_INT32* pSrc, OPJ_BYTE* pDst,
|
||||
- OPJ_SIZE_T length);
|
||||
-extern const convert_32sXXx_C1R convert_32sXXu_C1R_LUT[9]; /* up to 8bpp */
|
||||
-
|
||||
-
|
||||
-/* TGA conversion */
|
||||
-opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters);
|
||||
-int imagetotga(opj_image_t * image, const char *outfile);
|
||||
-
|
||||
-/* BMP conversion */
|
||||
-opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters);
|
||||
-int imagetobmp(opj_image_t *image, const char *outfile);
|
||||
-
|
||||
-/* TIFF conversion*/
|
||||
-opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters);
|
||||
-int imagetotif(opj_image_t *image, const char *outfile);
|
||||
-/**
|
||||
-Load a single image component encoded in PGX file format
|
||||
-@param filename Name of the PGX file to load
|
||||
-@param parameters *List ?*
|
||||
-@return Returns a greyscale image if successful, returns NULL otherwise
|
||||
-*/
|
||||
-opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters);
|
||||
-int imagetopgx(opj_image_t *image, const char *outfile);
|
||||
-
|
||||
-opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters);
|
||||
-int imagetopnm(opj_image_t *image, const char *outfile, int force_split);
|
||||
-
|
||||
-/* RAW conversion */
|
||||
-int imagetoraw(opj_image_t * image, const char *outfile);
|
||||
-int imagetorawl(opj_image_t * image, const char *outfile);
|
||||
-opj_image_t* rawtoimage(const char *filename, opj_cparameters_t *parameters,
|
||||
- raw_cparameters_t *raw_cp);
|
||||
-opj_image_t* rawltoimage(const char *filename, opj_cparameters_t *parameters,
|
||||
- raw_cparameters_t *raw_cp);
|
||||
-
|
||||
-/* PNG conversion*/
|
||||
-extern int imagetopng(opj_image_t *image, const char *write_idf);
|
||||
-extern opj_image_t* pngtoimage(const char *filename,
|
||||
- opj_cparameters_t *parameters);
|
||||
-
|
||||
-#endif /* __J2K_CONVERT_H */
|
||||
+#include "openjp2_sapi.sapi.h"
|
||||
|
||||
+const char* opj_version(void);
|
||||
+static int are_comps_similar(opj_image_t* image);
|
||||
+int imagetopnm(opj_image_t* image, const char* outfile, int force_split);
|
|
@ -1,345 +0,0 @@
|
|||
/*
|
||||
* The copyright in this software is being made available under the 2-clauses
|
||||
* BSD License, included below. This software may be subject to other third
|
||||
* party and contributor rights, including patent rights, and no such rights
|
||||
* are granted under this license.
|
||||
*
|
||||
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2002-2014, Professor Benoit Macq
|
||||
* Copyright (c) 2001-2003, David Janssens
|
||||
* Copyright (c) 2002-2003, Yannick Verschueren
|
||||
* Copyright (c) 2003-2007, Francois-Olivier Devaux
|
||||
* Copyright (c) 2003-2014, Antonin Descampe
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2006-2007, Parvatha Elangovan
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
// copies of a few library tools
|
||||
|
||||
#include "convert_helper.h"
|
||||
|
||||
#define OPJ_TRUE 1
|
||||
#define OPJ_FALSE 0
|
||||
|
||||
const char *opj_version(void) { return "2.3.1"; }
|
||||
|
||||
static int are_comps_similar(opj_image_t *image) {
|
||||
unsigned int i;
|
||||
for (i = 1; i < image->numcomps; i++) {
|
||||
if (image->comps[0].dx != image->comps[i].dx ||
|
||||
image->comps[0].dy != image->comps[i].dy ||
|
||||
(i <= 2 && (image->comps[0].prec != image->comps[i].prec ||
|
||||
image->comps[0].sgnd != image->comps[i].sgnd))) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
}
|
||||
return OPJ_TRUE;
|
||||
}
|
||||
|
||||
int imagetopnm(opj_image_t *image, const char *outfile, int force_split) {
|
||||
int *red, *green, *blue, *alpha;
|
||||
int wr, hr, max;
|
||||
int i;
|
||||
unsigned int compno, ncomp;
|
||||
int adjustR, adjustG, adjustB, adjustA;
|
||||
int fails, two, want_gray, has_alpha, triple;
|
||||
int prec, v;
|
||||
FILE *fdest = NULL;
|
||||
const char *tmp = outfile;
|
||||
char *destname;
|
||||
|
||||
alpha = NULL;
|
||||
|
||||
if ((prec = (int)image->comps[0].prec) > 16) {
|
||||
fprintf(stderr,
|
||||
"%s:%d:imagetopnm\n\tprecision %d is larger than 16"
|
||||
"\n\t: refused.\n",
|
||||
__FILE__, __LINE__, prec);
|
||||
return 1;
|
||||
}
|
||||
|
||||
two = has_alpha = 0;
|
||||
fails = 1;
|
||||
ncomp = image->numcomps;
|
||||
|
||||
while (*tmp) {
|
||||
++tmp;
|
||||
}
|
||||
tmp -= 2;
|
||||
want_gray = (*tmp == 'g' || *tmp == 'G');
|
||||
ncomp = image->numcomps;
|
||||
|
||||
if (want_gray) {
|
||||
ncomp = 1;
|
||||
}
|
||||
|
||||
if ((force_split == 0) && ncomp >= 2 && are_comps_similar(image)) {
|
||||
fdest = fopen(outfile, "wb");
|
||||
|
||||
if (!fdest) {
|
||||
fprintf(stderr, "ERROR -> failed to open %s for writing\n", outfile);
|
||||
return fails;
|
||||
}
|
||||
two = (prec > 8);
|
||||
triple = (ncomp > 2);
|
||||
wr = (int)image->comps[0].w;
|
||||
hr = (int)image->comps[0].h;
|
||||
max = (1 << prec) - 1;
|
||||
has_alpha = (ncomp == 4 || ncomp == 2);
|
||||
|
||||
red = image->comps[0].data;
|
||||
if (red == NULL) {
|
||||
fprintf(stderr, "imagetopnm: planes[%d] == NULL.\n", 0);
|
||||
fprintf(stderr, "\tAborting\n");
|
||||
fclose(fdest);
|
||||
return fails;
|
||||
}
|
||||
|
||||
if (triple) {
|
||||
green = image->comps[1].data;
|
||||
blue = image->comps[2].data;
|
||||
for (i = 1; i <= 2; i++) {
|
||||
if (image->comps[i].data == NULL) {
|
||||
fprintf(stderr, "imagetopnm: planes[%d] == NULL.\n", i);
|
||||
fprintf(stderr, "\tAborting\n");
|
||||
fclose(fdest);
|
||||
return fails;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
green = blue = NULL;
|
||||
}
|
||||
|
||||
if (has_alpha) {
|
||||
const char *tt = (triple ? "RGB_ALPHA" : "GRAYSCALE_ALPHA");
|
||||
|
||||
fprintf(fdest,
|
||||
"P7\n# OpenJPEG-%s\nWIDTH %d\nHEIGHT %d\nDEPTH %u\n"
|
||||
"MAXVAL %d\nTUPLTYPE %s\nENDHDR\n",
|
||||
opj_version(), wr, hr, ncomp, max, tt);
|
||||
alpha = image->comps[ncomp - 1].data;
|
||||
adjustA = (image->comps[ncomp - 1].sgnd
|
||||
? 1 << (image->comps[ncomp - 1].prec - 1)
|
||||
: 0);
|
||||
} else {
|
||||
fprintf(fdest, "P6\n# OpenJPEG-%s\n%d %d\n%d\n", opj_version(), wr, hr,
|
||||
max);
|
||||
adjustA = 0;
|
||||
}
|
||||
adjustR = (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
|
||||
|
||||
if (triple) {
|
||||
adjustG = (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0);
|
||||
adjustB = (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0);
|
||||
} else {
|
||||
adjustG = adjustB = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < wr * hr; ++i) {
|
||||
if (two) {
|
||||
v = *red + adjustR;
|
||||
++red;
|
||||
if (v > 65535) {
|
||||
v = 65535;
|
||||
} else if (v < 0) {
|
||||
v = 0;
|
||||
}
|
||||
|
||||
/* netpbm: */
|
||||
fprintf(fdest, "%c%c", (unsigned char)(v >> 8), (unsigned char)v);
|
||||
|
||||
if (triple) {
|
||||
v = *green + adjustG;
|
||||
++green;
|
||||
if (v > 65535) {
|
||||
v = 65535;
|
||||
} else if (v < 0) {
|
||||
v = 0;
|
||||
}
|
||||
|
||||
/* netpbm: */
|
||||
fprintf(fdest, "%c%c", (unsigned char)(v >> 8), (unsigned char)v);
|
||||
|
||||
v = *blue + adjustB;
|
||||
++blue;
|
||||
if (v > 65535) {
|
||||
v = 65535;
|
||||
} else if (v < 0) {
|
||||
v = 0;
|
||||
}
|
||||
|
||||
/* netpbm: */
|
||||
fprintf(fdest, "%c%c", (unsigned char)(v >> 8), (unsigned char)v);
|
||||
|
||||
} /* if(triple) */
|
||||
|
||||
if (has_alpha) {
|
||||
v = *alpha + adjustA;
|
||||
++alpha;
|
||||
if (v > 65535) {
|
||||
v = 65535;
|
||||
} else if (v < 0) {
|
||||
v = 0;
|
||||
}
|
||||
|
||||
/* netpbm: */
|
||||
fprintf(fdest, "%c%c", (unsigned char)(v >> 8), (unsigned char)v);
|
||||
}
|
||||
continue;
|
||||
|
||||
} /* if(two) */
|
||||
|
||||
/* prec <= 8: */
|
||||
v = *red++;
|
||||
if (v > 255) {
|
||||
v = 255;
|
||||
} else if (v < 0) {
|
||||
v = 0;
|
||||
}
|
||||
|
||||
fprintf(fdest, "%c", (unsigned char)v);
|
||||
if (triple) {
|
||||
v = *green++;
|
||||
if (v > 255) {
|
||||
v = 255;
|
||||
} else if (v < 0) {
|
||||
v = 0;
|
||||
}
|
||||
|
||||
fprintf(fdest, "%c", (unsigned char)v);
|
||||
v = *blue++;
|
||||
if (v > 255) {
|
||||
v = 255;
|
||||
} else if (v < 0) {
|
||||
v = 0;
|
||||
}
|
||||
|
||||
fprintf(fdest, "%c", (unsigned char)v);
|
||||
}
|
||||
if (has_alpha) {
|
||||
v = *alpha++;
|
||||
if (v > 255) {
|
||||
v = 255;
|
||||
} else if (v < 0) {
|
||||
v = 0;
|
||||
}
|
||||
|
||||
fprintf(fdest, "%c", (unsigned char)v);
|
||||
}
|
||||
} /* for(i */
|
||||
|
||||
fclose(fdest);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* YUV or MONO: */
|
||||
|
||||
if (image->numcomps > ncomp) {
|
||||
fprintf(stderr, "WARNING -> [PGM file] Only the first component\n");
|
||||
fprintf(stderr, " is written to the file\n");
|
||||
}
|
||||
destname = (char *)malloc(strlen(outfile) + 8);
|
||||
if (destname == NULL) {
|
||||
fprintf(stderr, "imagetopnm: memory out\n");
|
||||
return 1;
|
||||
}
|
||||
for (compno = 0; compno < ncomp; compno++) {
|
||||
if (ncomp > 1) {
|
||||
/*sprintf(destname, "%d.%s", compno, outfile);*/
|
||||
const size_t olen = strlen(outfile);
|
||||
const size_t dotpos = olen - 4;
|
||||
|
||||
strncpy(destname, outfile, dotpos);
|
||||
sprintf(destname + dotpos, "_%u.pgm", compno);
|
||||
} else {
|
||||
sprintf(destname, "%s", outfile);
|
||||
}
|
||||
|
||||
fdest = fopen(destname, "wb");
|
||||
if (!fdest) {
|
||||
fprintf(stderr, "ERROR -> failed to open %s for writing\n", destname);
|
||||
free(destname);
|
||||
return 1;
|
||||
}
|
||||
wr = (int)image->comps[compno].w;
|
||||
hr = (int)image->comps[compno].h;
|
||||
prec = (int)image->comps[compno].prec;
|
||||
max = (1 << prec) - 1;
|
||||
|
||||
fprintf(fdest, "P5\n#OpenJPEG-%s\n%d %d\n%d\n", opj_version(), wr, hr, max);
|
||||
|
||||
red = image->comps[compno].data;
|
||||
|
||||
if (!red) {
|
||||
fclose(fdest);
|
||||
continue;
|
||||
}
|
||||
|
||||
adjustR =
|
||||
(image->comps[compno].sgnd ? 1 << (image->comps[compno].prec - 1) : 0);
|
||||
|
||||
if (prec > 8) {
|
||||
for (i = 0; i < wr * hr; i++) {
|
||||
v = *red + adjustR;
|
||||
++red;
|
||||
if (v > 65535) {
|
||||
v = 65535;
|
||||
} else if (v < 0) {
|
||||
v = 0;
|
||||
}
|
||||
|
||||
/* netpbm: */
|
||||
fprintf(fdest, "%c%c", (unsigned char)(v >> 8), (unsigned char)v);
|
||||
|
||||
if (has_alpha) {
|
||||
v = *alpha++;
|
||||
if (v > 65535) {
|
||||
v = 65535;
|
||||
} else if (v < 0) {
|
||||
v = 0;
|
||||
}
|
||||
|
||||
/* netpbm: */
|
||||
fprintf(fdest, "%c%c", (unsigned char)(v >> 8), (unsigned char)v);
|
||||
}
|
||||
} /* for(i */
|
||||
} else { /* prec <= 8 */
|
||||
for (i = 0; i < wr * hr; ++i) {
|
||||
v = *red + adjustR;
|
||||
++red;
|
||||
if (v > 255) {
|
||||
v = 255;
|
||||
} else if (v < 0) {
|
||||
v = 0;
|
||||
}
|
||||
fprintf(fdest, "%c", (unsigned char)v);
|
||||
}
|
||||
}
|
||||
fclose(fdest);
|
||||
} /* for (compno */
|
||||
free(destname);
|
||||
|
||||
return 0;
|
||||
} /* imagetopnm() */
|
|
@ -1,8 +0,0 @@
|
|||
// imagetopnm and the two functions it calls internaly are copied from the
|
||||
// library's tools; from openjpeg/src/bin/jp2/convert.c
|
||||
|
||||
#include "openjp2_sapi.sapi.h"
|
||||
|
||||
const char* opj_version(void);
|
||||
static int are_comps_similar(opj_image_t* image);
|
||||
int imagetopnm(opj_image_t* image, const char* outfile, int force_split);
|
|
@ -21,8 +21,7 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/algorithm/container.h"
|
||||
#include "convert_helper.h"
|
||||
#include "convert_lib.h"
|
||||
#include "openjp2_sapi.sapi.h"
|
||||
|
||||
class Openjp2SapiSandbox : public Openjp2Sandbox {
|
||||
|
|
Loading…
Reference in New Issue
Block a user