@@ -19,8 +19,7 @@ SET(OPENJPEG_VERSION_MINOR 4)
|
|||||||
SET(OPENJPEG_VERSION_BUILD 0)
|
SET(OPENJPEG_VERSION_BUILD 0)
|
||||||
SET(OPENJPEG_VERSION
|
SET(OPENJPEG_VERSION
|
||||||
"${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
|
"${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
|
||||||
SET(PACKAGE_VERSION
|
|
||||||
"${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
|
|
||||||
# This setting of SOVERSION assumes that any API change
|
# This setting of SOVERSION assumes that any API change
|
||||||
# will increment either the minor or major version number of openjpeg
|
# will increment either the minor or major version number of openjpeg
|
||||||
SET(OPENJPEG_LIBRARY_PROPERTIES
|
SET(OPENJPEG_LIBRARY_PROPERTIES
|
||||||
@@ -67,58 +66,6 @@ IF(CMAKE_COMPILER_IS_GNUCC)
|
|||||||
SET(CMAKE_C_FLAGS_RELEASE "-ffast-math ${CMAKE_C_FLAGS_RELEASE}")
|
SET(CMAKE_C_FLAGS_RELEASE "-ffast-math ${CMAKE_C_FLAGS_RELEASE}")
|
||||||
ENDIF(CMAKE_COMPILER_IS_GNUCC)
|
ENDIF(CMAKE_COMPILER_IS_GNUCC)
|
||||||
|
|
||||||
FIND_FILE(HAVE_STRINGS_H_FOUND strings.h)
|
|
||||||
IF(NOT HAVE_STRINGS_H_FOUND STREQUAL "HAVE_STRINGS_H_FOUND-NOTFOUND")
|
|
||||||
FIND_FILE(HAVE_STRINGS_H strings.h)
|
|
||||||
SET(HAS_STRINGS_H 1)
|
|
||||||
ENDIF()
|
|
||||||
FIND_FILE(HAVE_INTTYPES_H_FOUND inttypes.h)
|
|
||||||
IF(NOT HAVE_INTTYPES_H_FOUND STREQUAL "HAVE_INTTYPES_H_FOUND-NOTFOUND")
|
|
||||||
FIND_FILE(HAVE_INTTYPES_H inttypes.h)
|
|
||||||
SET(HAS_INTTYPES_H 1)
|
|
||||||
ENDIF()
|
|
||||||
FIND_FILE(HAVE_MEMORY_H_FOUND memory.h)
|
|
||||||
IF(NOT HAVE_MEMORY_H_FOUND STREQUAL "HAVE_MEMORY_H_FOUND-NOTFOUND")
|
|
||||||
FIND_FILE(HAVE_MEMORY_H memory.h)
|
|
||||||
SET(HAS_MEMORY_H 1)
|
|
||||||
ENDIF()
|
|
||||||
FIND_FILE(HAVE_STDINT_H_FOUND stdint.h)
|
|
||||||
IF(NOT HAVE_STDINT_H_FOUND STREQUAL "HAVE_STDINT_H_FOUND-NOTFOUND")
|
|
||||||
FIND_FILE(HAVE_STDINT_H stdint.h)
|
|
||||||
SET(HAS_STDINT_H 1)
|
|
||||||
ENDIF()
|
|
||||||
FIND_FILE(HAVE_STDLIB_H_FOUND stdlib.h)
|
|
||||||
IF(NOT HAVE_STDLIB_H_FOUND STREQUAL "HAVE_STDLIB_H_FOUND-NOTFOUND")
|
|
||||||
FIND_FILE(HAVE_STDLIB_H stdlib.h)
|
|
||||||
SET(HAS_STDLIB_H 1)
|
|
||||||
ENDIF()
|
|
||||||
FIND_FILE(HAVE_STRING_H_FOUND string.h)
|
|
||||||
IF(NOT HAVE_STRING_H_FOUND STREQUAL "HAVE_STRING_H_FOUND-NOTFOUND")
|
|
||||||
FIND_FILE(HAVE_STRING_H string.h)
|
|
||||||
SET(HAS_STRING_H 1)
|
|
||||||
ENDIF()
|
|
||||||
FIND_FILE(HAVE_SYS_STAT_H_FOUND sys/stat.h)
|
|
||||||
IF(NOT HAVE_SYS_STAT_H_FOUND STREQUAL "HAVE_SYS_STAT_H_FOUND-NOTFOUND")
|
|
||||||
FIND_FILE(HAVE_SYS_STAT_H sys/stat.h)
|
|
||||||
SET(HAS_SYS_STAT_H 1)
|
|
||||||
ENDIF()
|
|
||||||
FIND_FILE(HAVE_SYS_TYPES_H_FOUND sys/types.h)
|
|
||||||
IF(NOT HAVE_SYS_TYPES_H_FOUND STREQUAL "HAVE_SYS_TYPES_H_FOUND-NOTFOUND")
|
|
||||||
FIND_FILE(HAVE_SYS_TYPES_H sys/types.h)
|
|
||||||
SET(HAS_SYS_TYPES_H 1)
|
|
||||||
ENDIF()
|
|
||||||
FIND_FILE(HAVE_UNISTD_H_FOUND unistd.h)
|
|
||||||
IF(NOT HAVE_UNISTD_H_FOUND STREQUAL "HAVE_UNISTD_H_FOUND-NOTFOUND")
|
|
||||||
FIND_FILE(HAVE_UNISTD_H unistd.h)
|
|
||||||
SET(HAS_UNISTD_H 1)
|
|
||||||
ENDIF()
|
|
||||||
|
|
||||||
# generate opj_config.h
|
|
||||||
CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/opj_configh.cmake.in"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/opj_config.h"
|
|
||||||
@ONLY
|
|
||||||
)
|
|
||||||
|
|
||||||
# Defines the source code for the library
|
# Defines the source code for the library
|
||||||
SET(OPENJPEG_SRCS
|
SET(OPENJPEG_SRCS
|
||||||
bio.c
|
bio.c
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
Utility functions
|
Utility functions
|
||||||
==========================================================*/
|
==========================================================*/
|
||||||
|
|
||||||
#ifndef _WIN32
|
#if !defined(_MSC_VER) && !defined(__MINGW32__)
|
||||||
static char*
|
static char*
|
||||||
i2a(unsigned i, char *a, unsigned r) {
|
i2a(unsigned i, char *a, unsigned r) {
|
||||||
if (i/r > 0) a = i2a(i/r,a,r);
|
if (i/r > 0) a = i2a(i/r,a,r);
|
||||||
@@ -57,7 +57,7 @@ _itoa(int i, char *a, int r) {
|
|||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* !_WIN32 */
|
#endif /* !WIN32 */
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------- */
|
/* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2005, Herv<EFBFBD> Drolon, FreeImage Team
|
* Copyright (c) 2005, Herv Drolon, FreeImage Team
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
|||||||
@@ -258,6 +258,80 @@ char *j2k_convert_progression_order(OPJ_PROG_ORDER prg_order){
|
|||||||
return po->str_prog;
|
return po->str_prog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void j2k_dump_image(FILE *fd, opj_image_t * img) {
|
||||||
|
int compno;
|
||||||
|
fprintf(fd, "image {\n");
|
||||||
|
fprintf(fd, " x0=%d, y0=%d, x1=%d, y1=%d\n", img->x0, img->y0, img->x1, img->y1);
|
||||||
|
fprintf(fd, " numcomps=%d\n", img->numcomps);
|
||||||
|
for (compno = 0; compno < img->numcomps; compno++) {
|
||||||
|
opj_image_comp_t *comp = &img->comps[compno];
|
||||||
|
fprintf(fd, " comp %d {\n", compno);
|
||||||
|
fprintf(fd, " dx=%d, dy=%d\n", comp->dx, comp->dy);
|
||||||
|
fprintf(fd, " prec=%d\n", comp->prec);
|
||||||
|
//fprintf(fd, " bpp=%d\n", comp->bpp);
|
||||||
|
fprintf(fd, " sgnd=%d\n", comp->sgnd);
|
||||||
|
fprintf(fd, " }\n");
|
||||||
|
}
|
||||||
|
fprintf(fd, "}\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void j2k_dump_cp(FILE *fd, opj_image_t * img, opj_cp_t * cp) {
|
||||||
|
int tileno, compno, layno, bandno, resno, numbands;
|
||||||
|
fprintf(fd, "coding parameters {\n");
|
||||||
|
fprintf(fd, " tx0=%d, ty0=%d\n", cp->tx0, cp->ty0);
|
||||||
|
fprintf(fd, " tdx=%d, tdy=%d\n", cp->tdx, cp->tdy);
|
||||||
|
fprintf(fd, " tw=%d, th=%d\n", cp->tw, cp->th);
|
||||||
|
for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
|
||||||
|
opj_tcp_t *tcp = &cp->tcps[tileno];
|
||||||
|
fprintf(fd, " tile %d {\n", tileno);
|
||||||
|
fprintf(fd, " csty=%x\n", tcp->csty);
|
||||||
|
fprintf(fd, " prg=%d\n", tcp->prg);
|
||||||
|
fprintf(fd, " numlayers=%d\n", tcp->numlayers);
|
||||||
|
fprintf(fd, " mct=%d\n", tcp->mct);
|
||||||
|
fprintf(fd, " rates=");
|
||||||
|
for (layno = 0; layno < tcp->numlayers; layno++) {
|
||||||
|
fprintf(fd, "%.1f ", tcp->rates[layno]);
|
||||||
|
}
|
||||||
|
fprintf(fd, "\n");
|
||||||
|
for (compno = 0; compno < img->numcomps; compno++) {
|
||||||
|
opj_tccp_t *tccp = &tcp->tccps[compno];
|
||||||
|
fprintf(fd, " comp %d {\n", compno);
|
||||||
|
fprintf(fd, " csty=%x\n", tccp->csty);
|
||||||
|
fprintf(fd, " numresolutions=%d\n", tccp->numresolutions);
|
||||||
|
fprintf(fd, " cblkw=%d\n", tccp->cblkw);
|
||||||
|
fprintf(fd, " cblkh=%d\n", tccp->cblkh);
|
||||||
|
fprintf(fd, " cblksty=%x\n", tccp->cblksty);
|
||||||
|
fprintf(fd, " qmfbid=%d\n", tccp->qmfbid);
|
||||||
|
fprintf(fd, " qntsty=%d\n", tccp->qntsty);
|
||||||
|
fprintf(fd, " numgbits=%d\n", tccp->numgbits);
|
||||||
|
fprintf(fd, " roishift=%d\n", tccp->roishift);
|
||||||
|
fprintf(fd, " stepsizes=");
|
||||||
|
numbands = tccp->qntsty == J2K_CCP_QNTSTY_SIQNT ? 1 : tccp->numresolutions * 3 - 2;
|
||||||
|
for (bandno = 0; bandno < numbands; bandno++) {
|
||||||
|
fprintf(fd, "(%d,%d) ", tccp->stepsizes[bandno].mant,
|
||||||
|
tccp->stepsizes[bandno].expn);
|
||||||
|
}
|
||||||
|
fprintf(fd, "\n");
|
||||||
|
|
||||||
|
if (tccp->csty & J2K_CCP_CSTY_PRT) {
|
||||||
|
fprintf(fd, " prcw=");
|
||||||
|
for (resno = 0; resno < tccp->numresolutions; resno++) {
|
||||||
|
fprintf(fd, "%d ", tccp->prcw[resno]);
|
||||||
|
}
|
||||||
|
fprintf(fd, "\n");
|
||||||
|
fprintf(fd, " prch=");
|
||||||
|
for (resno = 0; resno < tccp->numresolutions; resno++) {
|
||||||
|
fprintf(fd, "%d ", tccp->prch[resno]);
|
||||||
|
}
|
||||||
|
fprintf(fd, "\n");
|
||||||
|
}
|
||||||
|
fprintf(fd, " }\n");
|
||||||
|
}
|
||||||
|
fprintf(fd, " }\n");
|
||||||
|
}
|
||||||
|
fprintf(fd, "}\n");
|
||||||
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------- */
|
/* ----------------------------------------------------------------------- */
|
||||||
static int j2k_get_num_tp(opj_cp_t *cp,int pino,int tileno){
|
static int j2k_get_num_tp(opj_cp_t *cp,int pino,int tileno){
|
||||||
char *prog;
|
char *prog;
|
||||||
@@ -2222,6 +2296,8 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestre
|
|||||||
|
|
||||||
cp = j2k->cp;
|
cp = j2k->cp;
|
||||||
|
|
||||||
|
/* j2k_dump_cp(stdout, image, cp); */
|
||||||
|
|
||||||
/* INDEX >> */
|
/* INDEX >> */
|
||||||
j2k->cstr_info = cstr_info;
|
j2k->cstr_info = cstr_info;
|
||||||
if (cstr_info) {
|
if (cstr_info) {
|
||||||
|
|||||||
@@ -438,6 +438,8 @@ Encode an image into a JPEG-2000 codestream
|
|||||||
*/
|
*/
|
||||||
bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
|
bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
|
||||||
|
|
||||||
|
void j2k_dump_image(FILE *fd, opj_image_t * img);
|
||||||
|
void j2k_dump_cp(FILE *fd, opj_image_t * img, opj_cp_t * cp);
|
||||||
/* ----------------------------------------------------------------------- */
|
/* ----------------------------------------------------------------------- */
|
||||||
/*@}*/
|
/*@}*/
|
||||||
|
|
||||||
|
|||||||
@@ -24,18 +24,18 @@
|
|||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#else
|
#else
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <sys/times.h>
|
#include <sys/times.h>
|
||||||
#endif /* _WIN32 */
|
#endif /* WIN32 */
|
||||||
#include "opj_includes.h"
|
#include "opj_includes.h"
|
||||||
|
|
||||||
double opj_clock(void) {
|
double opj_clock(void) {
|
||||||
#ifdef _WIN32
|
#ifdef WIN32
|
||||||
/* _WIN32: use QueryPerformance (very accurate) */
|
/* WIN32: use QueryPerformance (very accurate) */
|
||||||
LARGE_INTEGER freq , t ;
|
LARGE_INTEGER freq , t ;
|
||||||
/* freq is the clock speed of the CPU */
|
/* freq is the clock speed of the CPU */
|
||||||
QueryPerformanceFrequency(&freq) ;
|
QueryPerformanceFrequency(&freq) ;
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "opj_includes.h"
|
#include "opj_includes.h"
|
||||||
|
|
||||||
/** @defgroup JP2 JP2 - JPEG-2000 file format reader/writer */
|
/** @defgroup JP2 JP2 - JPEG-2000 file format reader/writer */
|
||||||
@@ -56,6 +57,7 @@ static void jp2_write_ihdr(opj_jp2_t *jp2, opj_cio_t *cio);
|
|||||||
static void jp2_write_bpcc(opj_jp2_t *jp2, opj_cio_t *cio);
|
static void jp2_write_bpcc(opj_jp2_t *jp2, opj_cio_t *cio);
|
||||||
static bool jp2_read_bpcc(opj_jp2_t *jp2, opj_cio_t *cio);
|
static bool jp2_read_bpcc(opj_jp2_t *jp2, opj_cio_t *cio);
|
||||||
static void jp2_write_colr(opj_jp2_t *jp2, opj_cio_t *cio);
|
static void jp2_write_colr(opj_jp2_t *jp2, opj_cio_t *cio);
|
||||||
|
static bool jp2_read_colr(opj_jp2_t *jp2, opj_cio_t *cio);
|
||||||
/**
|
/**
|
||||||
Write the FTYP box - File type box
|
Write the FTYP box - File type box
|
||||||
@param jp2 JP2 handle
|
@param jp2 JP2 handle
|
||||||
@@ -83,47 +85,10 @@ static bool jp2_read_jp(opj_jp2_t *jp2, opj_cio_t *cio);
|
|||||||
Decode the structure of a JP2 file
|
Decode the structure of a JP2 file
|
||||||
@param jp2 JP2 handle
|
@param jp2 JP2 handle
|
||||||
@param cio Input buffer stream
|
@param cio Input buffer stream
|
||||||
@param color Collector for profile, cdef and pclr data
|
|
||||||
@return Returns true if successful, returns false otherwise
|
@return Returns true if successful, returns false otherwise
|
||||||
*/
|
*/
|
||||||
static bool jp2_read_struct(opj_jp2_t *jp2, opj_cio_t *cio,
|
static bool jp2_read_struct(opj_jp2_t *jp2, opj_cio_t *cio);
|
||||||
opj_jp2_color_t *color);
|
|
||||||
/**
|
|
||||||
Apply collected palette data
|
|
||||||
@param color Collector for profile, cdef and pclr data
|
|
||||||
@param image
|
|
||||||
*/
|
|
||||||
static void jp2_apply_pclr(opj_jp2_color_t *color, opj_image_t *image);
|
|
||||||
/**
|
|
||||||
Collect palette data
|
|
||||||
@param jp2 JP2 handle
|
|
||||||
@param cio Input buffer stream
|
|
||||||
@param box
|
|
||||||
@param color Collector for profile, cdef and pclr data
|
|
||||||
@return Returns true if successful, returns false otherwise
|
|
||||||
*/
|
|
||||||
static bool jp2_read_pclr(opj_jp2_t *jp2, opj_cio_t *cio,
|
|
||||||
opj_jp2_box_t *box, opj_jp2_color_t *color);
|
|
||||||
/**
|
|
||||||
Collect component mapping data
|
|
||||||
@param jp2 JP2 handle
|
|
||||||
@param cio Input buffer stream
|
|
||||||
@param box
|
|
||||||
@param color Collector for profile, cdef and pclr data
|
|
||||||
@return Returns true if successful, returns false otherwise
|
|
||||||
*/
|
|
||||||
static bool jp2_read_cmap(opj_jp2_t *jp2, opj_cio_t *cio,
|
|
||||||
opj_jp2_box_t *box, opj_jp2_color_t *color);
|
|
||||||
/**
|
|
||||||
Collect colour specification data
|
|
||||||
@param jp2 JP2 handle
|
|
||||||
@param cio Input buffer stream
|
|
||||||
@param box
|
|
||||||
@param color Collector for profile, cdef and pclr data
|
|
||||||
@return Returns true if successful, returns false otherwise
|
|
||||||
*/
|
|
||||||
static bool jp2_read_colr(opj_jp2_t *jp2, opj_cio_t *cio,
|
|
||||||
opj_jp2_box_t *box, opj_jp2_color_t *color);
|
|
||||||
/*@}*/
|
/*@}*/
|
||||||
|
|
||||||
/*@}*/
|
/*@}*/
|
||||||
@@ -293,458 +258,42 @@ static void jp2_write_colr(opj_jp2_t *jp2, opj_cio_t *cio) {
|
|||||||
cio_seek(cio, box.init_pos + box.length);
|
cio_seek(cio, box.init_pos + box.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void jp2_free_pclr(opj_jp2_color_t *color)
|
static bool jp2_read_colr(opj_jp2_t *jp2, opj_cio_t *cio) {
|
||||||
{
|
opj_jp2_box_t box;
|
||||||
opj_free(color->jp2_pclr->channel_sign);
|
|
||||||
opj_free(color->jp2_pclr->channel_size);
|
|
||||||
opj_free(color->jp2_pclr->entries);
|
|
||||||
|
|
||||||
if(color->jp2_pclr->cmap) opj_free(color->jp2_pclr->cmap);
|
|
||||||
|
|
||||||
opj_free(color->jp2_pclr); color->jp2_pclr = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void free_color_data(opj_jp2_color_t *color)
|
|
||||||
{
|
|
||||||
if(color->jp2_pclr)
|
|
||||||
{
|
|
||||||
jp2_free_pclr(color);
|
|
||||||
}
|
|
||||||
if(color->jp2_cdef)
|
|
||||||
{
|
|
||||||
if(color->jp2_cdef->info) opj_free(color->jp2_cdef->info);
|
|
||||||
opj_free(color->jp2_cdef);
|
|
||||||
}
|
|
||||||
if(color->icc_profile_buf) opj_free(color->icc_profile_buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void jp2_apply_pclr(opj_jp2_color_t *color, opj_image_t *image)
|
|
||||||
{
|
|
||||||
opj_image_comp_t *old_comps, *new_comps;
|
|
||||||
unsigned char *channel_size, *channel_sign;
|
|
||||||
unsigned int *entries;
|
|
||||||
opj_jp2_cmap_comp_t *cmap;
|
|
||||||
int *src, *dst;
|
|
||||||
unsigned int j, max;
|
|
||||||
unsigned short i, nr_channels, cmp, pcol;
|
|
||||||
int k, top_k;
|
|
||||||
|
|
||||||
channel_size = color->jp2_pclr->channel_size;
|
|
||||||
channel_sign = color->jp2_pclr->channel_sign;
|
|
||||||
entries = color->jp2_pclr->entries;
|
|
||||||
cmap = color->jp2_pclr->cmap;
|
|
||||||
nr_channels = color->jp2_pclr->nr_channels;
|
|
||||||
|
|
||||||
old_comps = image->comps;
|
|
||||||
new_comps = (opj_image_comp_t*)
|
|
||||||
opj_malloc(nr_channels * sizeof(opj_image_comp_t));
|
|
||||||
|
|
||||||
for(i = 0; i < nr_channels; ++i)
|
|
||||||
{
|
|
||||||
pcol = cmap[i].pcol; cmp = cmap[i].cmp;
|
|
||||||
|
|
||||||
new_comps[pcol] = old_comps[cmp];
|
|
||||||
|
|
||||||
if(cmap[i].mtyp == 0) /* Direct use */
|
|
||||||
{
|
|
||||||
old_comps[cmp].data = NULL; continue;
|
|
||||||
}
|
|
||||||
/* Palette mapping: */
|
|
||||||
new_comps[pcol].data = (int*)
|
|
||||||
opj_malloc(old_comps[cmp].w * old_comps[cmp].h * sizeof(int));
|
|
||||||
new_comps[pcol].prec = channel_size[i];
|
|
||||||
new_comps[pcol].sgnd = channel_sign[i];
|
|
||||||
}
|
|
||||||
top_k = color->jp2_pclr->nr_entries - 1;
|
|
||||||
|
|
||||||
for(i = 0; i < nr_channels; ++i)
|
|
||||||
{
|
|
||||||
/* Direct use: */
|
|
||||||
if(cmap[i].mtyp == 0) continue;
|
|
||||||
|
|
||||||
/* Palette mapping: */
|
|
||||||
cmp = cmap[i].cmp; pcol = cmap[i].pcol;
|
|
||||||
src = old_comps[cmp].data;
|
|
||||||
dst = new_comps[pcol].data;
|
|
||||||
max = new_comps[pcol].w * new_comps[pcol].h;
|
|
||||||
|
|
||||||
for(j = 0; j < max; ++j)
|
|
||||||
{
|
|
||||||
/* The index */
|
|
||||||
if((k = src[j]) < 0) k = 0; else if(k > top_k) k = top_k;
|
|
||||||
/* The colour */
|
|
||||||
dst[j] = entries[k * nr_channels + pcol];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
max = image->numcomps;
|
|
||||||
for(i = 0; i < max; ++i)
|
|
||||||
{
|
|
||||||
if(old_comps[i].data) opj_free(old_comps[i].data);
|
|
||||||
}
|
|
||||||
opj_free(old_comps);
|
|
||||||
image->comps = new_comps;
|
|
||||||
image->numcomps = nr_channels;
|
|
||||||
|
|
||||||
jp2_free_pclr(color);
|
|
||||||
|
|
||||||
}/* apply_pclr() */
|
|
||||||
|
|
||||||
static bool jp2_read_pclr(opj_jp2_t *jp2, opj_cio_t *cio,
|
|
||||||
opj_jp2_box_t *box, opj_jp2_color_t *color)
|
|
||||||
{
|
|
||||||
opj_jp2_pclr_t *jp2_pclr;
|
|
||||||
unsigned char *channel_size, *channel_sign;
|
|
||||||
unsigned int *entries;
|
|
||||||
unsigned short nr_entries, nr_channels;
|
|
||||||
unsigned short i, j;
|
|
||||||
unsigned char uc;
|
|
||||||
|
|
||||||
/* Part 1, I.5.3.4: 'There shall be at most one Palette box inside
|
|
||||||
* a JP2 Header box' :
|
|
||||||
*/
|
|
||||||
if(color->jp2_pclr) return false;
|
|
||||||
|
|
||||||
nr_entries = cio_read(cio, 2); /* NE */
|
|
||||||
nr_channels = cio_read(cio, 1);/* NPC */
|
|
||||||
|
|
||||||
entries = (unsigned int*)
|
|
||||||
opj_malloc(nr_channels * nr_entries * sizeof(unsigned int));
|
|
||||||
channel_size = (unsigned char*)opj_malloc(nr_channels);
|
|
||||||
channel_sign = (unsigned char*)opj_malloc(nr_channels);
|
|
||||||
|
|
||||||
jp2_pclr = (opj_jp2_pclr_t*)opj_malloc(sizeof(opj_jp2_pclr_t));
|
|
||||||
jp2_pclr->channel_sign = channel_sign;
|
|
||||||
jp2_pclr->channel_size = channel_size;
|
|
||||||
jp2_pclr->entries = entries;
|
|
||||||
jp2_pclr->nr_entries = nr_entries;
|
|
||||||
jp2_pclr->nr_channels = nr_channels;
|
|
||||||
jp2_pclr->cmap = NULL;
|
|
||||||
|
|
||||||
color->jp2_pclr = jp2_pclr;
|
|
||||||
|
|
||||||
for(i = 0; i < nr_channels; ++i)
|
|
||||||
{
|
|
||||||
uc = cio_read(cio, 1); /* Bi */
|
|
||||||
channel_size[i] = (uc & 0x7f) + 1;
|
|
||||||
channel_sign[i] = (uc & 0x80)?1:0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(j = 0; j < nr_entries; ++j)
|
|
||||||
{
|
|
||||||
for(i = 0; i < nr_channels; ++i)
|
|
||||||
{
|
|
||||||
/* Cji */
|
|
||||||
*entries++ = cio_read(cio, channel_size[i]>>3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}/* jp2_read_pclr() */
|
|
||||||
|
|
||||||
static bool jp2_read_cmap(opj_jp2_t *jp2, opj_cio_t *cio,
|
|
||||||
opj_jp2_box_t *box, opj_jp2_color_t *color)
|
|
||||||
{
|
|
||||||
opj_jp2_cmap_comp_t *cmap;
|
|
||||||
unsigned short i, nr_channels;
|
|
||||||
|
|
||||||
/* Need nr_channels: */
|
|
||||||
if(color->jp2_pclr == NULL) return false;
|
|
||||||
|
|
||||||
/* Part 1, I.5.3.5: 'There shall be at most one Component Mapping box
|
|
||||||
* inside a JP2 Header box' :
|
|
||||||
*/
|
|
||||||
if(color->jp2_pclr->cmap) return false;
|
|
||||||
|
|
||||||
nr_channels = color->jp2_pclr->nr_channels;
|
|
||||||
cmap = (opj_jp2_cmap_comp_t*)
|
|
||||||
opj_malloc(nr_channels * sizeof(opj_jp2_cmap_comp_t));
|
|
||||||
|
|
||||||
for(i = 0; i < nr_channels; ++i)
|
|
||||||
{
|
|
||||||
cmap[i].cmp = cio_read(cio, 2);
|
|
||||||
cmap[i].mtyp = cio_read(cio, 1);
|
|
||||||
cmap[i].pcol = cio_read(cio, 1);
|
|
||||||
|
|
||||||
}
|
|
||||||
color->jp2_pclr->cmap = cmap;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}/* jp2_read_cmap() */
|
|
||||||
|
|
||||||
static void jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color)
|
|
||||||
{
|
|
||||||
opj_jp2_cdef_info_t *info;
|
|
||||||
int color_space;
|
|
||||||
unsigned short i, n, cn, typ, asoc, acn;
|
|
||||||
|
|
||||||
color_space = image->color_space;
|
|
||||||
info = color->jp2_cdef->info;
|
|
||||||
n = color->jp2_cdef->n;
|
|
||||||
|
|
||||||
for(i = 0; i < n; ++i)
|
|
||||||
{
|
|
||||||
/* WATCH: acn = asoc - 1 ! */
|
|
||||||
if((asoc = info[i].asoc) == 0) continue;
|
|
||||||
|
|
||||||
cn = info[i].cn; typ = info[i].typ; acn = asoc - 1;
|
|
||||||
|
|
||||||
if(cn != acn)
|
|
||||||
{
|
|
||||||
opj_image_comp_t saved;
|
|
||||||
|
|
||||||
memcpy(&saved, &image->comps[cn], sizeof(opj_image_comp_t));
|
|
||||||
memcpy(&image->comps[cn], &image->comps[acn], sizeof(opj_image_comp_t));
|
|
||||||
memcpy(&image->comps[acn], &saved, sizeof(opj_image_comp_t));
|
|
||||||
|
|
||||||
info[i].asoc = cn + 1;
|
|
||||||
info[acn].asoc = info[acn].cn + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(color->jp2_cdef->info) opj_free(color->jp2_cdef->info);
|
|
||||||
|
|
||||||
opj_free(color->jp2_cdef); color->jp2_cdef = NULL;
|
|
||||||
|
|
||||||
}/* jp2_apply_cdef() */
|
|
||||||
|
|
||||||
static bool jp2_read_cdef(opj_jp2_t *jp2, opj_cio_t *cio,
|
|
||||||
opj_jp2_box_t *box, opj_jp2_color_t *color)
|
|
||||||
{
|
|
||||||
opj_jp2_cdef_info_t *info;
|
|
||||||
unsigned short i, n;
|
|
||||||
|
|
||||||
/* Part 1, I.5.3.6: 'The shall be at most one Channel Definition box
|
|
||||||
* inside a JP2 Header box.'
|
|
||||||
*/
|
|
||||||
if(color->jp2_cdef) return false;
|
|
||||||
|
|
||||||
if((n = cio_read(cio, 2)) == 0) return false; /* szukw000: FIXME */
|
|
||||||
|
|
||||||
info = (opj_jp2_cdef_info_t*)
|
|
||||||
opj_malloc(n * sizeof(opj_jp2_cdef_info_t));
|
|
||||||
|
|
||||||
color->jp2_cdef = (opj_jp2_cdef_t*)opj_malloc(sizeof(opj_jp2_cdef_t));
|
|
||||||
color->jp2_cdef->info = info;
|
|
||||||
color->jp2_cdef->n = n;
|
|
||||||
|
|
||||||
for(i = 0; i < n; ++i)
|
|
||||||
{
|
|
||||||
info[i].cn = cio_read(cio, 2);
|
|
||||||
info[i].typ = cio_read(cio, 2);
|
|
||||||
info[i].asoc = cio_read(cio, 2);
|
|
||||||
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}/* jp2_read_cdef() */
|
|
||||||
|
|
||||||
static bool jp2_read_colr(opj_jp2_t *jp2, opj_cio_t *cio,
|
|
||||||
opj_jp2_box_t *box, opj_jp2_color_t *color)
|
|
||||||
{
|
|
||||||
int skip_len;
|
int skip_len;
|
||||||
opj_common_ptr cinfo;
|
|
||||||
|
|
||||||
/* Part 1, I.5.3.3 : 'A conforming JP2 reader shall ignore all Colour
|
opj_common_ptr cinfo = jp2->cinfo;
|
||||||
* Specification boxes after the first.'
|
|
||||||
*/
|
|
||||||
if(color->jp2_has_colr) return false;
|
|
||||||
|
|
||||||
cinfo = jp2->cinfo;
|
jp2_read_boxhdr(cinfo, cio, &box);
|
||||||
|
do {
|
||||||
|
if (JP2_COLR != box.type) {
|
||||||
|
cio_skip(cio, box.length - 8);
|
||||||
|
jp2_read_boxhdr(cinfo, cio, &box);
|
||||||
|
}
|
||||||
|
} while(JP2_COLR != box.type);
|
||||||
|
|
||||||
jp2->meth = cio_read(cio, 1); /* METH */
|
jp2->meth = cio_read(cio, 1); /* METH */
|
||||||
jp2->precedence = cio_read(cio, 1); /* PRECEDENCE */
|
jp2->precedence = cio_read(cio, 1); /* PRECEDENCE */
|
||||||
jp2->approx = cio_read(cio, 1); /* APPROX */
|
jp2->approx = cio_read(cio, 1); /* APPROX */
|
||||||
|
|
||||||
if (jp2->meth == 1)
|
if (jp2->meth == 1) {
|
||||||
{
|
|
||||||
jp2->enumcs = cio_read(cio, 4); /* EnumCS */
|
jp2->enumcs = cio_read(cio, 4); /* EnumCS */
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* skip PROFILE */
|
/* skip PROFILE */
|
||||||
skip_len = box->init_pos + box->length - cio_tell(cio);
|
skip_len = box.init_pos + box.length - cio_tell(cio);
|
||||||
if (skip_len < 0)
|
if (skip_len < 0) {
|
||||||
{
|
opj_event_msg(cinfo, EVT_ERROR, "Error with JP2H box size\n");
|
||||||
opj_event_msg(cinfo, EVT_ERROR, "Error with COLR box size\n");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(skip_len > 0)
|
cio_skip(cio, box.init_pos + box.length - cio_tell(cio));
|
||||||
{
|
|
||||||
unsigned char *start;
|
|
||||||
|
|
||||||
start = cio_getbp(cio);
|
|
||||||
color->icc_profile_buf = (unsigned char*)opj_malloc(skip_len);
|
|
||||||
color->icc_profile_len = skip_len;
|
|
||||||
|
|
||||||
cio_skip(cio, box->init_pos + box->length - cio_tell(cio));
|
|
||||||
|
|
||||||
memcpy(color->icc_profile_buf, start, skip_len);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cio_tell(cio) - box->init_pos != box->length)
|
if (cio_tell(cio) - box.init_pos != box.length) {
|
||||||
{
|
opj_event_msg(cinfo, EVT_ERROR, "Error with BPCC Box\n");
|
||||||
opj_event_msg(cinfo, EVT_ERROR, "Error with COLR Box\n");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
color->jp2_has_colr = 1;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}/* jp2_read_colr() */
|
|
||||||
|
|
||||||
bool jp2_read_jp2h(opj_jp2_t *jp2, opj_cio_t *cio, opj_jp2_color_t *color)
|
|
||||||
{
|
|
||||||
opj_jp2_box_t box;
|
|
||||||
unsigned int jp2h_end;
|
|
||||||
|
|
||||||
opj_common_ptr cinfo = jp2->cinfo;
|
|
||||||
|
|
||||||
jp2_read_boxhdr(cinfo, cio, &box);
|
|
||||||
do
|
|
||||||
{
|
|
||||||
if (JP2_JP2H != box.type)
|
|
||||||
{
|
|
||||||
if (box.type == JP2_JP2C)
|
|
||||||
{
|
|
||||||
opj_event_msg(cinfo, EVT_ERROR, "Expected JP2H Marker\n");
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
cio_skip(cio, box.length - 8);
|
|
||||||
|
|
||||||
if(cio->bp >= cio->end) return false;
|
|
||||||
|
|
||||||
jp2_read_boxhdr(cinfo, cio, &box);
|
|
||||||
}
|
|
||||||
} while(JP2_JP2H != box.type);
|
|
||||||
|
|
||||||
if (!jp2_read_ihdr(jp2, cio))
|
|
||||||
return false;
|
|
||||||
jp2h_end = box.init_pos + box.length;
|
|
||||||
|
|
||||||
if (jp2->bpc == 255)
|
|
||||||
{
|
|
||||||
if (!jp2_read_bpcc(jp2, cio))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
jp2_read_boxhdr(cinfo, cio, &box);
|
|
||||||
|
|
||||||
while(cio_tell(cio) < jp2h_end)
|
|
||||||
{
|
|
||||||
if(box.type == JP2_COLR)
|
|
||||||
{
|
|
||||||
if( !jp2_read_colr(jp2, cio, &box, color))
|
|
||||||
{
|
|
||||||
cio_seek(cio, box.init_pos + 8);
|
|
||||||
cio_skip(cio, box.length - 8);
|
|
||||||
}
|
|
||||||
jp2_read_boxhdr(cinfo, cio, &box);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(box.type == JP2_CDEF)
|
|
||||||
{
|
|
||||||
if( !jp2_read_cdef(jp2, cio, &box, color))
|
|
||||||
{
|
|
||||||
cio_seek(cio, box.init_pos + 8);
|
|
||||||
cio_skip(cio, box.length - 8);
|
|
||||||
}
|
|
||||||
jp2_read_boxhdr(cinfo, cio, &box);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(box.type == JP2_PCLR)
|
|
||||||
{
|
|
||||||
if( !jp2_read_pclr(jp2, cio, &box, color))
|
|
||||||
{
|
|
||||||
cio_seek(cio, box.init_pos + 8);
|
|
||||||
cio_skip(cio, box.length - 8);
|
|
||||||
}
|
|
||||||
jp2_read_boxhdr(cinfo, cio, &box);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(box.type == JP2_CMAP)
|
|
||||||
{
|
|
||||||
if( !jp2_read_cmap(jp2, cio, &box, color))
|
|
||||||
{
|
|
||||||
cio_seek(cio, box.init_pos + 8);
|
|
||||||
cio_skip(cio, box.length - 8);
|
|
||||||
}
|
|
||||||
jp2_read_boxhdr(cinfo, cio, &box);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
cio_seek(cio, box.init_pos + 8);
|
|
||||||
cio_skip(cio, box.length - 8);
|
|
||||||
jp2_read_boxhdr(cinfo, cio, &box);
|
|
||||||
|
|
||||||
}/* while(cio_tell(cio) < box_end) */
|
|
||||||
|
|
||||||
cio_seek(cio, jp2h_end);
|
|
||||||
|
|
||||||
/* Part 1, I.5.3.3 : 'must contain at least one' */
|
|
||||||
return (color->jp2_has_colr == 1);
|
|
||||||
|
|
||||||
}/* jp2_read_jp2h() */
|
|
||||||
|
|
||||||
opj_image_t* jp2_decode(opj_jp2_t *jp2, opj_cio_t *cio,
|
|
||||||
opj_codestream_info_t *cstr_info)
|
|
||||||
{
|
|
||||||
opj_common_ptr cinfo;
|
|
||||||
opj_image_t *image = NULL;
|
|
||||||
opj_jp2_color_t color;
|
|
||||||
|
|
||||||
if(!jp2 || !cio)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
memset(&color, 0, sizeof(opj_jp2_color_t));
|
|
||||||
cinfo = jp2->cinfo;
|
|
||||||
|
|
||||||
/* JP2 decoding */
|
|
||||||
if(!jp2_read_struct(jp2, cio, &color))
|
|
||||||
{
|
|
||||||
free_color_data(&color);
|
|
||||||
opj_event_msg(cinfo, EVT_ERROR, "Failed to decode jp2 structure\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* J2K decoding */
|
|
||||||
image = j2k_decode(jp2->j2k, cio, cstr_info);
|
|
||||||
|
|
||||||
if(!image)
|
|
||||||
{
|
|
||||||
free_color_data(&color);
|
|
||||||
opj_event_msg(cinfo, EVT_ERROR, "Failed to decode J2K image\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set Image Color Space */
|
|
||||||
if (jp2->enumcs == 16)
|
|
||||||
image->color_space = CLRSPC_SRGB;
|
|
||||||
else if (jp2->enumcs == 17)
|
|
||||||
image->color_space = CLRSPC_GRAY;
|
|
||||||
else if (jp2->enumcs == 18)
|
|
||||||
image->color_space = CLRSPC_SYCC;
|
|
||||||
else
|
|
||||||
image->color_space = CLRSPC_UNKNOWN;
|
|
||||||
|
|
||||||
if(color.jp2_cdef)
|
|
||||||
{
|
|
||||||
jp2_apply_cdef(image, &color);
|
|
||||||
}
|
|
||||||
if(color.jp2_pclr)
|
|
||||||
{
|
|
||||||
/* Part 1, I.5.3.4: Either both or none : */
|
|
||||||
if( !color.jp2_pclr->cmap)
|
|
||||||
jp2_free_pclr(&color);
|
|
||||||
else
|
|
||||||
jp2_apply_pclr(&color, image);
|
|
||||||
}
|
|
||||||
if(color.icc_profile_buf)
|
|
||||||
{
|
|
||||||
image->icc_profile_buf = color.icc_profile_buf;
|
|
||||||
color.icc_profile_buf = NULL;
|
|
||||||
image->icc_profile_len = color.icc_profile_len;
|
|
||||||
}
|
|
||||||
return image;
|
|
||||||
|
|
||||||
}/* jp2_decode() */
|
|
||||||
|
|
||||||
|
|
||||||
void jp2_write_jp2h(opj_jp2_t *jp2, opj_cio_t *cio) {
|
void jp2_write_jp2h(opj_jp2_t *jp2, opj_cio_t *cio) {
|
||||||
opj_jp2_box_t box;
|
opj_jp2_box_t box;
|
||||||
@@ -766,6 +315,44 @@ void jp2_write_jp2h(opj_jp2_t *jp2, opj_cio_t *cio) {
|
|||||||
cio_seek(cio, box.init_pos + box.length);
|
cio_seek(cio, box.init_pos + box.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool jp2_read_jp2h(opj_jp2_t *jp2, opj_cio_t *cio) {
|
||||||
|
opj_jp2_box_t box;
|
||||||
|
int skip_len;
|
||||||
|
|
||||||
|
opj_common_ptr cinfo = jp2->cinfo;
|
||||||
|
|
||||||
|
jp2_read_boxhdr(cinfo, cio, &box);
|
||||||
|
do {
|
||||||
|
if (JP2_JP2H != box.type) {
|
||||||
|
if (box.type == JP2_JP2C) {
|
||||||
|
opj_event_msg(cinfo, EVT_ERROR, "Expected JP2H Marker\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
cio_skip(cio, box.length - 8);
|
||||||
|
jp2_read_boxhdr(cinfo, cio, &box);
|
||||||
|
}
|
||||||
|
} while(JP2_JP2H != box.type);
|
||||||
|
|
||||||
|
if (!jp2_read_ihdr(jp2, cio))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (jp2->bpc == 255) {
|
||||||
|
if (!jp2_read_bpcc(jp2, cio))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!jp2_read_colr(jp2, cio))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
skip_len = box.init_pos + box.length - cio_tell(cio);
|
||||||
|
if (skip_len < 0) {
|
||||||
|
opj_event_msg(cinfo, EVT_ERROR, "Error with JP2H Box\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
cio_skip(cio, box.init_pos + box.length - cio_tell(cio));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static void jp2_write_ftyp(opj_jp2_t *jp2, opj_cio_t *cio) {
|
static void jp2_write_ftyp(opj_jp2_t *jp2, opj_cio_t *cio) {
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
opj_jp2_box_t box;
|
opj_jp2_box_t box;
|
||||||
@@ -902,13 +489,12 @@ static bool jp2_read_jp(opj_jp2_t *jp2, opj_cio_t *cio) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool jp2_read_struct(opj_jp2_t *jp2, opj_cio_t *cio,
|
static bool jp2_read_struct(opj_jp2_t *jp2, opj_cio_t *cio) {
|
||||||
opj_jp2_color_t *color) {
|
|
||||||
if (!jp2_read_jp(jp2, cio))
|
if (!jp2_read_jp(jp2, cio))
|
||||||
return false;
|
return false;
|
||||||
if (!jp2_read_ftyp(jp2, cio))
|
if (!jp2_read_ftyp(jp2, cio))
|
||||||
return false;
|
return false;
|
||||||
if (!jp2_read_jp2h(jp2, cio, color))
|
if (!jp2_read_jp2h(jp2, cio))
|
||||||
return false;
|
return false;
|
||||||
if (!jp2_read_jp2c(jp2, cio, &jp2->j2k_codestream_length, &jp2->j2k_codestream_offset))
|
if (!jp2_read_jp2c(jp2, cio, &jp2->j2k_codestream_length, &jp2->j2k_codestream_offset))
|
||||||
return false;
|
return false;
|
||||||
@@ -955,6 +541,42 @@ void jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters) {
|
|||||||
/* further JP2 initializations go here */
|
/* further JP2 initializations go here */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
opj_image_t* jp2_decode(opj_jp2_t *jp2, opj_cio_t *cio, opj_codestream_info_t *cstr_info) {
|
||||||
|
opj_common_ptr cinfo;
|
||||||
|
opj_image_t *image = NULL;
|
||||||
|
|
||||||
|
if(!jp2 || !cio) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
cinfo = jp2->cinfo;
|
||||||
|
|
||||||
|
/* JP2 decoding */
|
||||||
|
if(!jp2_read_struct(jp2, cio)) {
|
||||||
|
opj_event_msg(cinfo, EVT_ERROR, "Failed to decode jp2 structure\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* J2K decoding */
|
||||||
|
image = j2k_decode(jp2->j2k, cio, cstr_info);
|
||||||
|
if(!image) {
|
||||||
|
opj_event_msg(cinfo, EVT_ERROR, "Failed to decode J2K image\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set Image Color Space */
|
||||||
|
if (jp2->enumcs == 16)
|
||||||
|
image->color_space = CLRSPC_SRGB;
|
||||||
|
else if (jp2->enumcs == 17)
|
||||||
|
image->color_space = CLRSPC_GRAY;
|
||||||
|
else if (jp2->enumcs == 18)
|
||||||
|
image->color_space = CLRSPC_SYCC;
|
||||||
|
else
|
||||||
|
image->color_space = CLRSPC_UNKNOWN;
|
||||||
|
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------- */
|
/* ----------------------------------------------------------------------- */
|
||||||
/* JP2 encoder interface */
|
/* JP2 encoder interface */
|
||||||
/* ----------------------------------------------------------------------- */
|
/* ----------------------------------------------------------------------- */
|
||||||
|
|||||||
@@ -46,64 +46,11 @@
|
|||||||
#define JP2_COLR 0x636f6c72 /**< Colour specification box */
|
#define JP2_COLR 0x636f6c72 /**< Colour specification box */
|
||||||
#define JP2_JP2C 0x6a703263 /**< Contiguous codestream box */
|
#define JP2_JP2C 0x6a703263 /**< Contiguous codestream box */
|
||||||
#define JP2_URL 0x75726c20 /**< URL box */
|
#define JP2_URL 0x75726c20 /**< URL box */
|
||||||
#define JP2_DTBL 0x6474626c /**< Data Reference box */
|
#define JP2_DBTL 0x6474626c /**< ??? */
|
||||||
#define JP2_BPCC 0x62706363 /**< Bits per component box */
|
#define JP2_BPCC 0x62706363 /**< Bits per component box */
|
||||||
#define JP2_JP2 0x6a703220 /**< File type fields */
|
#define JP2_JP2 0x6a703220 /**< File type fields */
|
||||||
#define JP2_PCLR 0x70636c72 /**< Palette box */
|
|
||||||
#define JP2_CMAP 0x636d6170 /**< Component Mapping box */
|
|
||||||
#define JP2_CDEF 0x63646566 /**< Channel Definition box */
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------- */
|
/* ----------------------------------------------------------------------- */
|
||||||
/**
|
|
||||||
Channel description: channel index, type, assocation
|
|
||||||
*/
|
|
||||||
typedef struct opj_jp2_cdef_info
|
|
||||||
{
|
|
||||||
unsigned short cn, typ, asoc;
|
|
||||||
} opj_jp2_cdef_info_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
Channel descriptions and number of descriptions
|
|
||||||
*/
|
|
||||||
typedef struct opj_jp2_cdef
|
|
||||||
{
|
|
||||||
opj_jp2_cdef_info_t *info;
|
|
||||||
unsigned short n;
|
|
||||||
} opj_jp2_cdef_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
Component mappings: channel index, mapping type, palette index
|
|
||||||
*/
|
|
||||||
typedef struct opj_jp2_cmap_comp
|
|
||||||
{
|
|
||||||
unsigned short cmp;
|
|
||||||
unsigned char mtyp, pcol;
|
|
||||||
} opj_jp2_cmap_comp_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
Palette data: table entries, palette columns
|
|
||||||
*/
|
|
||||||
typedef struct opj_jp2_pclr
|
|
||||||
{
|
|
||||||
unsigned int *entries;
|
|
||||||
unsigned char *channel_sign;
|
|
||||||
unsigned char *channel_size;
|
|
||||||
opj_jp2_cmap_comp_t *cmap;
|
|
||||||
unsigned short nr_entries, nr_channels;
|
|
||||||
} opj_jp2_pclr_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
Collector for ICC profile, palette, component mapping, channel description
|
|
||||||
*/
|
|
||||||
typedef struct opj_jp2_color
|
|
||||||
{
|
|
||||||
unsigned char *icc_profile_buf;
|
|
||||||
int icc_profile_len;
|
|
||||||
|
|
||||||
opj_jp2_cdef_t *jp2_cdef;
|
|
||||||
opj_jp2_pclr_t *jp2_pclr;
|
|
||||||
unsigned char jp2_has_colr;
|
|
||||||
} opj_jp2_color_t;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
JP2 component
|
JP2 component
|
||||||
@@ -164,10 +111,9 @@ void jp2_write_jp2h(opj_jp2_t *jp2, opj_cio_t *cio);
|
|||||||
Read the JP2H box - JP2 Header box (used in MJ2)
|
Read the JP2H box - JP2 Header box (used in MJ2)
|
||||||
@param jp2 JP2 handle
|
@param jp2 JP2 handle
|
||||||
@param cio Input buffer stream
|
@param cio Input buffer stream
|
||||||
@param ext Collector for profile, cdef and pclr data
|
|
||||||
@return Returns true if successful, returns false otherwise
|
@return Returns true if successful, returns false otherwise
|
||||||
*/
|
*/
|
||||||
bool jp2_read_jp2h(opj_jp2_t *jp2, opj_cio_t *cio, opj_jp2_color_t *color);
|
bool jp2_read_jp2h(opj_jp2_t *jp2, opj_cio_t *cio);
|
||||||
/**
|
/**
|
||||||
Creates a JP2 decompression structure
|
Creates a JP2 decompression structure
|
||||||
@param cinfo Codec context info
|
@param cinfo Codec context info
|
||||||
|
|||||||
@@ -24,15 +24,14 @@
|
|||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif /* _WIN32 */
|
#endif /* WIN32 */
|
||||||
|
|
||||||
#include "opj_config.h"
|
|
||||||
#include "opj_includes.h"
|
#include "opj_includes.h"
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
#ifdef _WIN32
|
#ifdef WIN32
|
||||||
#ifndef OPJ_STATIC
|
#ifndef OPJ_STATIC
|
||||||
BOOL APIENTRY
|
BOOL APIENTRY
|
||||||
DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
|
DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
|
||||||
@@ -49,13 +48,13 @@ DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
#endif /* OPJ_STATIC */
|
#endif /* OPJ_STATIC */
|
||||||
#endif /* _WIN32 */
|
#endif /* WIN32 */
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
const char* OPJ_CALLCONV opj_version(void) {
|
const char* OPJ_CALLCONV opj_version(void) {
|
||||||
return PACKAGE_VERSION;
|
return OPENJPEG_VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format) {
|
opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format) {
|
||||||
|
|||||||
@@ -32,10 +32,7 @@
|
|||||||
#ifndef OPENJPEG_H
|
#ifndef OPENJPEG_H
|
||||||
#define OPENJPEG_H
|
#define OPENJPEG_H
|
||||||
|
|
||||||
// Linden Labs Secondlife code requires this to be defined.
|
#define OPENJPEG_VERSION "1.4.0.635"
|
||||||
// It was removed in openjpeg 1.4.0 stable release.
|
|
||||||
// --Techwolf Lupindo
|
|
||||||
#define OPENJPEG_VERSION "1.4.0.697"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
==========================================================
|
==========================================================
|
||||||
@@ -43,7 +40,7 @@
|
|||||||
==========================================================
|
==========================================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(OPJ_STATIC) || !defined(_WIN32)
|
#if defined(OPJ_STATIC) || !(defined(WIN32) || defined(__WIN32__))
|
||||||
#define OPJ_API
|
#define OPJ_API
|
||||||
#define OPJ_CALLCONV
|
#define OPJ_CALLCONV
|
||||||
#else
|
#else
|
||||||
@@ -56,12 +53,12 @@ that uses this DLL. This way any other project whose source files include this f
|
|||||||
OPJ_API functions as being imported from a DLL, wheras this DLL sees symbols
|
OPJ_API functions as being imported from a DLL, wheras this DLL sees symbols
|
||||||
defined with this macro as being exported.
|
defined with this macro as being exported.
|
||||||
*/
|
*/
|
||||||
#if defined(OPJ_EXPORTS) || defined(DLL_EXPORT)
|
#ifdef OPJ_EXPORTS
|
||||||
#define OPJ_API __declspec(dllexport)
|
#define OPJ_API __declspec(dllexport)
|
||||||
#else
|
#else
|
||||||
#define OPJ_API __declspec(dllimport)
|
#define OPJ_API __declspec(dllimport)
|
||||||
#endif /* OPJ_EXPORTS */
|
#endif /* OPJ_EXPORTS */
|
||||||
#endif /* !OPJ_STATIC || !_WIN32 */
|
#endif /* !OPJ_STATIC || !WIN32 */
|
||||||
|
|
||||||
#ifndef __cplusplus
|
#ifndef __cplusplus
|
||||||
#if defined(HAVE_STDBOOL_H)
|
#if defined(HAVE_STDBOOL_H)
|
||||||
@@ -538,8 +535,6 @@ typedef struct opj_image_comp {
|
|||||||
int factor;
|
int factor;
|
||||||
/** image component data */
|
/** image component data */
|
||||||
int *data;
|
int *data;
|
||||||
/** image datablock size */
|
|
||||||
int datasize;
|
|
||||||
} opj_image_comp_t;
|
} opj_image_comp_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -560,10 +555,6 @@ typedef struct opj_image {
|
|||||||
OPJ_COLOR_SPACE color_space;
|
OPJ_COLOR_SPACE color_space;
|
||||||
/** image components */
|
/** image components */
|
||||||
opj_image_comp_t *comps;
|
opj_image_comp_t *comps;
|
||||||
/** 'restricted' ICC profile */
|
|
||||||
unsigned char *icc_profile_buf;
|
|
||||||
/** size of ICC profile */
|
|
||||||
int icc_profile_len;
|
|
||||||
} opj_image_t;
|
} opj_image_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
/* create config.h for CMake */
|
|
||||||
#define PACKAGE_VERSION "@PACKAGE_VERSION@"
|
|
||||||
#
|
|
||||||
#cmakedefine HAVE_INTTYPES_H @HAS_INTTYPES_H@
|
|
||||||
#cmakedefine HAVE_MEMORY_H @HAS_MEMORY_H@
|
|
||||||
#cmakedefine HAVE_STDINT_H @HAS_STDINT_H@
|
|
||||||
#cmakedefine HAVE_STDLIB_H @HAS_STDLIB_H@
|
|
||||||
#cmakedefine HAVE_STRINGS_H @HAS_STRINGS_H@
|
|
||||||
#cmakedefine HAVE_STRING_H @HAS_STRING_H@
|
|
||||||
#cmakedefine HAVE_SYS_STAT_H @HAS_SYS_STAT_H@
|
|
||||||
#cmakedefine HAVE_SYS_TYPES_H @HAS_SYS_TYPES_H@
|
|
||||||
#cmakedefine HAVE_UNISTD_H @HAS_UNISTD_H@
|
|
||||||
#cmakedefine HAVE_LIBPNG @HAVE_LIBPNG@
|
|
||||||
#cmakedefine HAVE_PNG_H @HAVE_PNG_H@
|
|
||||||
#cmakedefine HAVE_LIBTIFF @HAVE_LIBTIFF@
|
|
||||||
#cmakedefine HAVE_TIFF_H @HAVE_TIFF_H@
|
|
||||||
#
|
|
||||||
#cmakedefine HAVE_LIBLCMS1 @HAVE_LCMS1_LIB@
|
|
||||||
#cmakedefine HAVE_LIBLCMS2 @HAVE_LCMS2_LIB@
|
|
||||||
#cmakedefine HAVE_LCMS1_H @HAVE_LCMS1_H@
|
|
||||||
#cmakedefine HAVE_LCMS2_H @HAVE_LCMS2_H@
|
|
||||||
#
|
|
||||||
@@ -89,9 +89,6 @@ Most compilers implement their own version of this keyword ...
|
|||||||
/* MSVC and Borland C do not have lrintf */
|
/* MSVC and Borland C do not have lrintf */
|
||||||
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||||
static INLINE long lrintf(float f){
|
static INLINE long lrintf(float f){
|
||||||
#ifdef _M_X64
|
|
||||||
return (long)((f>0.0f) ? (f + 0.5f):(f -0.5f));
|
|
||||||
#else
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
_asm{
|
_asm{
|
||||||
@@ -100,7 +97,6 @@ static INLINE long lrintf(float f){
|
|||||||
};
|
};
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ Allocate memory aligned to a 16 byte boundry
|
|||||||
@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available
|
@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available
|
||||||
*/
|
*/
|
||||||
/* FIXME: These should be set with cmake tests, but we're currently not requiring use of cmake */
|
/* FIXME: These should be set with cmake tests, but we're currently not requiring use of cmake */
|
||||||
#ifdef _WIN32
|
#ifdef WIN32
|
||||||
/* Someone should tell the mingw people that their malloc.h ought to provide _mm_malloc() */
|
/* Someone should tell the mingw people that their malloc.h ought to provide _mm_malloc() */
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#include <mm_malloc.h>
|
#include <mm_malloc.h>
|
||||||
@@ -80,7 +80,7 @@ Allocate memory aligned to a 16 byte boundry
|
|||||||
#define HAVE_MM_MALLOC
|
#define HAVE_MM_MALLOC
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#else /* Not _WIN32 */
|
#else /* Not WIN32 */
|
||||||
#if defined(__sun)
|
#if defined(__sun)
|
||||||
#define HAVE_MEMALIGN
|
#define HAVE_MEMALIGN
|
||||||
/* Linux x86_64 and OSX always align allocations to 16 bytes */
|
/* Linux x86_64 and OSX always align allocations to 16 bytes */
|
||||||
@@ -130,22 +130,22 @@ Allocate memory aligned to a 16 byte boundry
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Reallocate memory blocks.
|
Reallocate memory blocks.
|
||||||
@param m Pointer to previously allocated memory block
|
@param memblock Pointer to previously allocated memory block
|
||||||
@param s New size in bytes
|
@param size New size in bytes
|
||||||
@return Returns a void pointer to the reallocated (and possibly moved) memory block
|
@return Returns a void pointer to the reallocated (and possibly moved) memory block
|
||||||
*/
|
*/
|
||||||
#ifdef ALLOC_PERF_OPT
|
#ifdef ALLOC_PERF_OPT
|
||||||
void * OPJ_CALLCONV opj_realloc(void * m, size_t s);
|
void * OPJ_CALLCONV opj_realloc(void * _Memory, size_t NewSize);
|
||||||
#else
|
#else
|
||||||
#define opj_realloc(m, s) realloc(m, s)
|
#define opj_realloc(m, s) realloc(m, s)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Deallocates or frees a memory block.
|
Deallocates or frees a memory block.
|
||||||
@param m Previously allocated memory block to be freed
|
@param memblock Previously allocated memory block to be freed
|
||||||
*/
|
*/
|
||||||
#ifdef ALLOC_PERF_OPT
|
#ifdef ALLOC_PERF_OPT
|
||||||
void OPJ_CALLCONV opj_free(void * m);
|
void OPJ_CALLCONV opj_free(void * _Memory);
|
||||||
#else
|
#else
|
||||||
#define opj_free(m) free(m)
|
#define opj_free(m) free(m)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -115,10 +115,8 @@ Modify the packet iterator for enabling tile part generation
|
|||||||
@param pi Handle to the packet iterator generated in pi_initialise_encode
|
@param pi Handle to the packet iterator generated in pi_initialise_encode
|
||||||
@param cp Coding parameters
|
@param cp Coding parameters
|
||||||
@param tileno Number that identifies the tile for which to list the packets
|
@param tileno Number that identifies the tile for which to list the packets
|
||||||
@param pino Iterator index for pi
|
|
||||||
@param tpnum Tile part number of the current tile
|
@param tpnum Tile part number of the current tile
|
||||||
@param tppos The position of the tile part flag in the progression order
|
@param tppos The position of the tile part flag in the progression order
|
||||||
@param t2_mode If == 0 In Threshold calculation ,If == 1 Final pass
|
|
||||||
@param cur_totnum_tp The total number of tile parts in the current tile
|
@param cur_totnum_tp The total number of tile parts in the current tile
|
||||||
@return Returns true if an error is detected
|
@return Returns true if an error is detected
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -240,7 +240,6 @@ Encode 1 code-block
|
|||||||
@param stepsize
|
@param stepsize
|
||||||
@param cblksty Code-block style
|
@param cblksty Code-block style
|
||||||
@param numcomps
|
@param numcomps
|
||||||
@param mct
|
|
||||||
@param tile
|
@param tile
|
||||||
*/
|
*/
|
||||||
static void t1_encode_cblk(
|
static void t1_encode_cblk(
|
||||||
@@ -1089,14 +1088,27 @@ static double t1_getwmsedec(
|
|||||||
int numcomps,
|
int numcomps,
|
||||||
int mct)
|
int mct)
|
||||||
{
|
{
|
||||||
double w1, w2, wmsedec;
|
double w1 = 1, w2, wmsedec;
|
||||||
|
|
||||||
|
// Prevent running an MCT on more than 3 components. NB openjpeg v2.0 will support this via
|
||||||
|
// custom MCT tables that can be passed as encode parameters, 1.3 cannot support this as it
|
||||||
|
// uses a static table of 3 entries and there for can only cope with 3 components with out an
|
||||||
|
// array overflow
|
||||||
|
|
||||||
|
if(numcomps==3) {
|
||||||
|
if (qmfbid == 1) {
|
||||||
|
w1 = (numcomps > 1) ? mct_getnorm(compno) : 1.0;
|
||||||
|
} else {
|
||||||
|
w1 = (numcomps > 1) ? mct_getnorm_real(compno) : 1.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (qmfbid == 1) {
|
if (qmfbid == 1) {
|
||||||
w1 = (mct && numcomps==3) ? mct_getnorm(compno) : 1.0;
|
|
||||||
w2 = dwt_getnorm(level, orient);
|
w2 = dwt_getnorm(level, orient);
|
||||||
} else { /* if (qmfbid == 0) */
|
} else { /* if (qmfbid == 0) */
|
||||||
w1 = (mct && numcomps==3) ? mct_getnorm_real(compno) : 1.0;
|
|
||||||
w2 = dwt_getnorm_real(level, orient);
|
w2 = dwt_getnorm_real(level, orient);
|
||||||
}
|
}
|
||||||
|
|
||||||
wmsedec = w1 * w2 * stepsize * (1 << bpno);
|
wmsedec = w1 * w2 * stepsize * (1 << bpno);
|
||||||
wmsedec *= wmsedec * nmsedec / 8192.0;
|
wmsedec *= wmsedec * nmsedec / 8192.0;
|
||||||
|
|
||||||
@@ -1488,7 +1500,7 @@ void t1_encode_cblks(
|
|||||||
} /* compno */
|
} /* compno */
|
||||||
}
|
}
|
||||||
|
|
||||||
bool t1_decode_cblks(
|
void t1_decode_cblks(
|
||||||
opj_t1_t* t1,
|
opj_t1_t* t1,
|
||||||
opj_tcd_tilecomp_t* tilec,
|
opj_tcd_tilecomp_t* tilec,
|
||||||
opj_tccp_t* tccp)
|
opj_tccp_t* tccp)
|
||||||
@@ -1558,17 +1570,6 @@ bool t1_decode_cblks(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { /* if (tccp->qmfbid == 0) */
|
} else { /* if (tccp->qmfbid == 0) */
|
||||||
int chkSize=tilec->datasize - ((y * tile_w)+x);
|
|
||||||
if((chkSize < (cblk_h * cblk_w)) || (chkSize < (((cblk_h -1 ) * tile_w)+cblk_w)))
|
|
||||||
{
|
|
||||||
opj_free(cblk->data);
|
|
||||||
opj_free(cblk->segs);
|
|
||||||
opj_free(precinct->cblks.dec);
|
|
||||||
opj_event_msg(t1->cinfo, EVT_ERROR, "Block does not fit into tile.\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
float* restrict tiledp = (float*) &tilec->data[(y * tile_w) + x];
|
float* restrict tiledp = (float*) &tilec->data[(y * tile_w) + x];
|
||||||
for (j = 0; j < cblk_h; ++j) {
|
for (j = 0; j < cblk_h; ++j) {
|
||||||
float* restrict tiledp2 = tiledp;
|
float* restrict tiledp2 = tiledp;
|
||||||
@@ -1581,7 +1582,6 @@ bool t1_decode_cblks(
|
|||||||
tiledp += tile_w;
|
tiledp += tile_w;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
opj_free(cblk->data);
|
opj_free(cblk->data);
|
||||||
opj_free(cblk->segs);
|
opj_free(cblk->segs);
|
||||||
} /* cblkno */
|
} /* cblkno */
|
||||||
@@ -1589,6 +1589,5 @@ bool t1_decode_cblks(
|
|||||||
} /* precno */
|
} /* precno */
|
||||||
} /* bandno */
|
} /* bandno */
|
||||||
} /* resno */
|
} /* resno */
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -135,10 +135,10 @@ void t1_encode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp);
|
|||||||
/**
|
/**
|
||||||
Decode the code-blocks of a tile
|
Decode the code-blocks of a tile
|
||||||
@param t1 T1 handle
|
@param t1 T1 handle
|
||||||
@param tilec The tile to decode
|
@param tile The tile to decode
|
||||||
@param tccp Tile coding parameters
|
@param tcp Tile coding parameters
|
||||||
*/
|
*/
|
||||||
bool t1_decode_cblks(opj_t1_t* t1, opj_tcd_tilecomp_t* tilec, opj_tccp_t* tccp);
|
void t1_decode_cblks(opj_t1_t* t1, opj_tcd_tilecomp_t* tilec, opj_tccp_t* tccp);
|
||||||
/* ----------------------------------------------------------------------- */
|
/* ----------------------------------------------------------------------- */
|
||||||
/*@}*/
|
/*@}*/
|
||||||
|
|
||||||
|
|||||||
@@ -59,8 +59,7 @@ Encode a packet of a tile to a destination buffer
|
|||||||
*/
|
*/
|
||||||
static int t2_encode_packet(opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi, unsigned char *dest, int len, opj_codestream_info_t *cstr_info, int tileno);
|
static int t2_encode_packet(opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi, unsigned char *dest, int len, opj_codestream_info_t *cstr_info, int tileno);
|
||||||
/**
|
/**
|
||||||
@param cblk
|
@param seg
|
||||||
@param index
|
|
||||||
@param cblksty
|
@param cblksty
|
||||||
@param first
|
@param first
|
||||||
*/
|
*/
|
||||||
@@ -73,7 +72,6 @@ Decode a packet of a tile from a source buffer
|
|||||||
@param tile Tile for which to write the packets
|
@param tile Tile for which to write the packets
|
||||||
@param tcp Tile coding parameters
|
@param tcp Tile coding parameters
|
||||||
@param pi Packet identity
|
@param pi Packet identity
|
||||||
@param pack_info Packet information
|
|
||||||
@return
|
@return
|
||||||
*/
|
*/
|
||||||
static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile,
|
static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile,
|
||||||
@@ -496,7 +494,6 @@ static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_t
|
|||||||
if (tcp->csty & J2K_CP_CSTY_EPH) {
|
if (tcp->csty & J2K_CP_CSTY_EPH) {
|
||||||
if ((*hd) != 0xff || (*(hd + 1) != 0x92)) {
|
if ((*hd) != 0xff || (*(hd + 1) != 0x92)) {
|
||||||
opj_event_msg(t2->cinfo, EVT_ERROR, "Expected EPH marker\n");
|
opj_event_msg(t2->cinfo, EVT_ERROR, "Expected EPH marker\n");
|
||||||
return -999;
|
|
||||||
} else {
|
} else {
|
||||||
hd += 2;
|
hd += 2;
|
||||||
}
|
}
|
||||||
@@ -714,7 +711,7 @@ int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj
|
|||||||
} else {
|
} else {
|
||||||
e = 0;
|
e = 0;
|
||||||
}
|
}
|
||||||
if(e == -999) return -999;
|
|
||||||
/* progression in resolution */
|
/* progression in resolution */
|
||||||
image->comps[pi[pino].compno].resno_decoded =
|
image->comps[pi[pino].compno].resno_decoded =
|
||||||
(e > 0) ?
|
(e > 0) ?
|
||||||
|
|||||||
@@ -67,7 +67,6 @@ Encode the packets of a tile to a destination buffer
|
|||||||
@param cstr_info Codestream information structure
|
@param cstr_info Codestream information structure
|
||||||
@param tpnum Tile part number of the current tile
|
@param tpnum Tile part number of the current tile
|
||||||
@param tppos The position of the tile part flag in the progression order
|
@param tppos The position of the tile part flag in the progression order
|
||||||
@param pino
|
|
||||||
@param t2_mode If == 0 In Threshold calculation ,If == 1 Final pass
|
@param t2_mode If == 0 In Threshold calculation ,If == 1 Final pass
|
||||||
@param cur_totnum_tp The total number of tile parts in the current tile
|
@param cur_totnum_tp The total number of tile parts in the current tile
|
||||||
*/
|
*/
|
||||||
@@ -79,7 +78,6 @@ Decode the packets of a tile from a source buffer
|
|||||||
@param len length of the source buffer
|
@param len length of the source buffer
|
||||||
@param tileno number that identifies the tile for which to decode the packets
|
@param tileno number that identifies the tile for which to decode the packets
|
||||||
@param tile tile for which to decode the packets
|
@param tile tile for which to decode the packets
|
||||||
@param cstr_info Codestream information structure
|
|
||||||
*/
|
*/
|
||||||
int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj_tcd_tile_t *tile, opj_codestream_info_t *cstr_info);
|
int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj_tcd_tile_t *tile, opj_codestream_info_t *cstr_info);
|
||||||
|
|
||||||
|
|||||||
@@ -1376,15 +1376,11 @@ bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, op
|
|||||||
for (compno = 0; compno < tile->numcomps; ++compno) {
|
for (compno = 0; compno < tile->numcomps; ++compno) {
|
||||||
opj_tcd_tilecomp_t* tilec = &tile->comps[compno];
|
opj_tcd_tilecomp_t* tilec = &tile->comps[compno];
|
||||||
/* The +3 is headroom required by the vectorized DWT */
|
/* The +3 is headroom required by the vectorized DWT */
|
||||||
tilec->datasize=(((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0))+3) * sizeof(int);
|
tilec->data = (int*) opj_aligned_malloc((((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0))+3) * sizeof(int));
|
||||||
tilec->data = (int*) opj_aligned_malloc(tilec->datasize);
|
if(tilec->data)
|
||||||
if(!t1_decode_cblks(t1, tilec, &tcd->tcp->tccps[compno]))
|
t1_decode_cblks(t1, tilec, &tcd->tcp->tccps[compno]);
|
||||||
{
|
else
|
||||||
opj_event_msg(tcd->cinfo, EVT_ERROR, "Error decoding tile.\n");
|
opj_event_msg(tcd->cinfo, EVT_ERROR, "tcd_decode: tile size invalid\n");
|
||||||
opj_aligned_free(tilec->data);
|
|
||||||
t1_destroy(t1);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
t1_destroy(t1);
|
t1_destroy(t1);
|
||||||
t1_time = opj_clock() - t1_time;
|
t1_time = opj_clock() - t1_time;
|
||||||
@@ -1407,6 +1403,11 @@ bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, op
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!tilec->data) {
|
||||||
|
opj_event_msg(tcd->cinfo, EVT_ERROR, "Error decoding tile. null data\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
numres2decode = tcd->image->comps[compno].resno_decoded + 1;
|
numres2decode = tcd->image->comps[compno].resno_decoded + 1;
|
||||||
if(numres2decode > 0){
|
if(numres2decode > 0){
|
||||||
if (tcd->tcp->tccps[compno].qmfbid == 1) {
|
if (tcd->tcp->tccps[compno].qmfbid == 1) {
|
||||||
@@ -1456,8 +1457,7 @@ bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, op
|
|||||||
|
|
||||||
int i, j;
|
int i, j;
|
||||||
if(!imagec->data){
|
if(!imagec->data){
|
||||||
imagec->datasize = imagec->w * imagec->h * sizeof(int);
|
imagec->data = (int*) opj_malloc(imagec->w * imagec->h * sizeof(int));
|
||||||
imagec->data = (int*) opj_malloc(imagec->datasize);
|
|
||||||
}
|
}
|
||||||
if(tcd->tcp->tccps[compno].qmfbid == 1) {
|
if(tcd->tcp->tccps[compno].qmfbid == 1) {
|
||||||
for(j = res->y0; j < res->y1; ++j) {
|
for(j = res->y0; j < res->y1; ++j) {
|
||||||
@@ -1468,12 +1468,6 @@ bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, op
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
if((imagec->datasize - (((res->x1) - offset_x) + ((res->y1) - offset_y) * w)) < 1)
|
|
||||||
{
|
|
||||||
opj_event_msg(tcd->cinfo, EVT_ERROR, "tcd_decode: Tile not large enough for data\n");
|
|
||||||
opj_aligned_free(tilec->data);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for(j = res->y0; j < res->y1; ++j) {
|
for(j = res->y0; j < res->y1; ++j) {
|
||||||
for(i = res->x0; i < res->x1; ++i) {
|
for(i = res->x0; i < res->x1; ++i) {
|
||||||
float tmp = ((float*)tilec->data)[i - res->x0 + (j - res->y0) * tw];
|
float tmp = ((float*)tilec->data)[i - res->x0 + (j - res->y0) * tw];
|
||||||
|
|||||||
@@ -142,7 +142,6 @@ typedef struct opj_tcd_tilecomp {
|
|||||||
int numresolutions; /* number of resolutions level */
|
int numresolutions; /* number of resolutions level */
|
||||||
opj_tcd_resolution_t *resolutions; /* resolutions information */
|
opj_tcd_resolution_t *resolutions; /* resolutions information */
|
||||||
int *data; /* data of the component */
|
int *data; /* data of the component */
|
||||||
int datasize; /* size of datablock */
|
|
||||||
int numpix; /* add fixed_quality */
|
int numpix; /* add fixed_quality */
|
||||||
} opj_tcd_tilecomp_t;
|
} opj_tcd_tilecomp_t;
|
||||||
|
|
||||||
@@ -269,7 +268,6 @@ Decode a tile from a buffer into a raw image
|
|||||||
@param src Source buffer
|
@param src Source buffer
|
||||||
@param len Length of source buffer
|
@param len Length of source buffer
|
||||||
@param tileno Number that identifies one of the tiles to be decoded
|
@param tileno Number that identifies one of the tiles to be decoded
|
||||||
@param cstr_info Codestream information structure
|
|
||||||
*/
|
*/
|
||||||
bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, opj_codestream_info_t *cstr_info);
|
bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, opj_codestream_info_t *cstr_info);
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user