⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jas_cm.c

📁 DIGITAL IMAGERY is pervasive in our world today. Consequently, standards for the efficient represen
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * Copyright (c) 2002-2003 Michael David Adams. * All rights reserved. *//* __START_OF_JASPER_LICENSE__ *  * JasPer Software License *  * IMAGE POWER JPEG-2000 PUBLIC LICENSE * ************************************ *  * GRANT: *  * Permission is hereby granted, free of charge, to any person (the "User") * obtaining a copy of this software and associated documentation, to deal * in the JasPer Software without restriction, including without limitation * the right to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the JasPer Software (in source and binary forms), * and to permit persons to whom the JasPer Software is furnished to do so, * provided further that the License Conditions below are met. *  * License Conditions * ****************** *  * A.  Redistributions of source code must retain the above copyright notice, * and this list of conditions, and the following disclaimer. *  * B.  Redistributions in binary form must reproduce the above copyright * notice, and this list of conditions, and the following disclaimer in * the documentation and/or other materials provided with the distribution. *  * C.  Neither the name of Image Power, Inc. nor any other contributor * (including, but not limited to, the University of British Columbia and * Michael David Adams) may be used to endorse or promote products derived * from this software without specific prior written permission. *  * D.  User agrees that it shall not commence any action against Image Power, * Inc., the University of British Columbia, Michael David Adams, or any * other contributors (collectively "Licensors") for infringement of any * intellectual property rights ("IPR") held by the User in respect of any * technology that User owns or has a right to license or sublicense and * which is an element required in order to claim compliance with ISO/IEC * 15444-1 (i.e., JPEG-2000 Part 1).  "IPR" means all intellectual property * rights worldwide arising under statutory or common law, and whether * or not perfected, including, without limitation, all (i) patents and * patent applications owned or licensable by User; (ii) rights associated * with works of authorship including copyrights, copyright applications, * copyright registrations, mask work rights, mask work applications, * mask work registrations; (iii) rights relating to the protection of * trade secrets and confidential information; (iv) any right analogous * to those set forth in subsections (i), (ii), or (iii) and any other * proprietary rights relating to intangible property (other than trademark, * trade dress, or service mark rights); and (v) divisions, continuations, * renewals, reissues and extensions of the foregoing (as and to the extent * applicable) now existing, hereafter filed, issued or acquired. *  * E.  If User commences an infringement action against any Licensor(s) then * such Licensor(s) shall have the right to terminate User's license and * all sublicenses that have been granted hereunder by User to other parties. *  * F.  This software is for use only in hardware or software products that * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1).  No license * or right to this Software is granted for products that do not comply * with ISO/IEC 15444-1.  The JPEG-2000 Part 1 standard can be purchased * from the ISO. *  * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER * THIS DISCLAIMER.  THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING.  THOSE INTENDING * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE * IS WITH THE USER.  SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, * REPAIR OR CORRECTION.  UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY * OF SUCH DAMAGES.  THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE * ("HIGH RISK ACTIVITIES").  LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.  USER WILL NOT * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE * NOTICE SPECIFIED IN THIS SECTION. *  * __END_OF_JASPER_LICENSE__ *//* * Color Management * * $Id$ */#include <jasper/jas_config.h>#include <math.h>#include <stdlib.h>#include <assert.h>#include <jasper/jas_cm.h>#include <jasper/jas_icc.h>#include <jasper/jas_init.h>#include <jasper/jas_stream.h>#include <jasper/jas_malloc.h>#include <jasper/jas_math.h>static jas_cmprof_t *jas_cmprof_create(void);static void jas_cmshapmatlut_cleanup(jas_cmshapmatlut_t *);static jas_cmreal_t jas_cmshapmatlut_lookup(jas_cmshapmatlut_t *lut, jas_cmreal_t x);static void jas_cmpxform_destroy(jas_cmpxform_t *pxform);static jas_cmpxform_t *jas_cmpxform_copy(jas_cmpxform_t *pxform);static void jas_cmshapmat_destroy(jas_cmpxform_t *pxform);static int jas_cmshapmat_apply(jas_cmpxform_t *pxform, jas_cmreal_t *in,  jas_cmreal_t *out, int cnt);static int jas_cmputint(long **bufptr, int sgnd, int prec, long val);static int jas_cmgetint(long **bufptr, int sgnd, int prec, long *val);static int jas_cmpxformseq_append(jas_cmpxformseq_t *pxformseq,  jas_cmpxformseq_t *othpxformseq);static int jas_cmpxformseq_appendcnvt(jas_cmpxformseq_t *pxformseq,  int, int);static int jas_cmpxformseq_resize(jas_cmpxformseq_t *pxformseq, int n);static int mono(jas_iccprof_t *prof, int op, jas_cmpxformseq_t **pxformseq);static int triclr(jas_iccprof_t *prof, int op, jas_cmpxformseq_t **retpxformseq);static void jas_cmpxformseq_destroy(jas_cmpxformseq_t *pxformseq);static int jas_cmpxformseq_delete(jas_cmpxformseq_t *pxformseq, int i);static jas_cmpxformseq_t *jas_cmpxformseq_create(void);static jas_cmpxformseq_t *jas_cmpxformseq_copy(jas_cmpxformseq_t *pxformseq);static int jas_cmshapmat_invmat(jas_cmreal_t out[3][4], jas_cmreal_t in[3][4]);static int jas_cmpxformseq_insertpxform(jas_cmpxformseq_t *pxformseq,  int i, jas_cmpxform_t *pxform);#define	SEQFWD(intent)	(intent)#define	SEQREV(intent)	(4 + (intent))#define	SEQSIM(intent)	(8 + (intent))#define	SEQGAM		12#define fwdpxformseq(prof, intent) \  (((prof)->pxformseqs[SEQFWD(intent)]) ? \  ((prof)->pxformseqs[SEQFWD(intent)]) : \  ((prof)->pxformseqs[SEQFWD(0)]))#define revpxformseq(prof, intent) \  (((prof)->pxformseqs[SEQREV(intent)]) ? \  ((prof)->pxformseqs[SEQREV(intent)]) : \  ((prof)->pxformseqs[SEQREV(0)]))#define simpxformseq(prof, intent) \  (((prof)->pxformseqs[SEQSIM(intent)]) ? \  ((prof)->pxformseqs[SEQSIM(intent)]) : \  ((prof)->pxformseqs[SEQSIM(0)]))#define gampxformseq(prof)	((prof)->pxformseqs[SEQGAM])static int icctoclrspc(int iccclrspc, int refflag);static jas_cmpxform_t *jas_cmpxform_create0(void);static jas_cmpxform_t *jas_cmpxform_createshapmat(void);static void jas_cmshapmatlut_init(jas_cmshapmatlut_t *lut);static int jas_cmshapmatlut_set(jas_cmshapmatlut_t *lut, jas_icccurv_t *curv);static jas_cmpxformops_t shapmat_ops = {jas_cmshapmat_destroy, jas_cmshapmat_apply, 0};static jas_cmprof_t *jas_cmprof_createsycc(void);/******************************************************************************\* Color profile class.\******************************************************************************/jas_cmprof_t *jas_cmprof_createfromclrspc(int clrspc){	jas_iccprof_t *iccprof;	jas_cmprof_t *prof;	iccprof = 0;	prof = 0;	switch (clrspc) {	case JAS_CLRSPC_SYCBCR:		if (!(prof = jas_cmprof_createsycc()))			goto error;		break;	default:		if (!(iccprof = jas_iccprof_createfromclrspc(clrspc)))			goto error;		if (!(prof = jas_cmprof_createfromiccprof(iccprof)))			goto error;		jas_iccprof_destroy(iccprof);		if (!jas_clrspc_isgeneric(clrspc))			prof->clrspc = clrspc;		break;	}	return prof;error:	if (iccprof)		jas_iccprof_destroy(iccprof);	return 0;}static jas_cmprof_t *jas_cmprof_createsycc(){	jas_cmprof_t *prof;	jas_cmpxform_t *fwdpxform;	jas_cmpxform_t *revpxform;	jas_cmshapmat_t *fwdshapmat;	jas_cmshapmat_t *revshapmat;	int i;	int j;	if (!(prof = jas_cmprof_createfromclrspc(JAS_CLRSPC_SRGB)))		goto error;	prof->clrspc = JAS_CLRSPC_SYCBCR;	assert(prof->numchans == 3 && prof->numrefchans == 3);	assert(prof->refclrspc == JAS_CLRSPC_CIEXYZ);	if (!(fwdpxform = jas_cmpxform_createshapmat()))		goto error;	fwdpxform->numinchans = 3;	fwdpxform->numoutchans = 3;	fwdshapmat = &fwdpxform->data.shapmat;	fwdshapmat->mono = 0;	fwdshapmat->order = 0;	fwdshapmat->useluts = 0;	fwdshapmat->usemat = 1;	fwdshapmat->mat[0][0] = 1.0;	fwdshapmat->mat[0][1] = 0.0;	fwdshapmat->mat[0][2] = 1.402;	fwdshapmat->mat[1][0] = 1.0;	fwdshapmat->mat[1][1] = -0.34413;	fwdshapmat->mat[1][2] = -0.71414;	fwdshapmat->mat[2][0] = 1.0;	fwdshapmat->mat[2][1] = 1.772;	fwdshapmat->mat[2][2] = 0.0;	fwdshapmat->mat[0][3] = -0.5 * (1.402);	fwdshapmat->mat[1][3] = -0.5 * (-0.34413 - 0.71414);	fwdshapmat->mat[2][3] = -0.5 * (1.772);	if (!(revpxform = jas_cmpxform_createshapmat()))		goto error;	revpxform->numinchans = 3;	revpxform->numoutchans = 3;	revshapmat = &revpxform->data.shapmat;	revshapmat->mono = 0;	revshapmat->order = 1;	revshapmat->useluts = 0;	revshapmat->usemat = 1;	jas_cmshapmat_invmat(revshapmat->mat, fwdshapmat->mat);	for (i = 0; i < JAS_CMXFORM_NUMINTENTS; ++i) {		j = SEQFWD(i);		if (prof->pxformseqs[j]) {			if (jas_cmpxformseq_insertpxform(prof->pxformseqs[j], 0,			  fwdpxform))				goto error;		}		j = SEQREV(i);		if (prof->pxformseqs[j]) {			if (jas_cmpxformseq_insertpxform(prof->pxformseqs[j],			  -1, revpxform))				goto error;		}	}	jas_cmpxform_destroy(fwdpxform);	jas_cmpxform_destroy(revpxform);	return prof;error:	return 0;}jas_cmprof_t *jas_cmprof_createfromiccprof(jas_iccprof_t *iccprof){	jas_cmprof_t *prof;	jas_icchdr_t icchdr;	jas_cmpxformseq_t *fwdpxformseq;	jas_cmpxformseq_t *revpxformseq;	if (!(prof = jas_cmprof_create()))		goto error;	jas_iccprof_gethdr(iccprof, &icchdr);	if (!(prof->iccprof = jas_iccprof_copy(iccprof)))		goto error;	prof->clrspc = icctoclrspc(icchdr.colorspc, 0);	prof->refclrspc = icctoclrspc(icchdr.refcolorspc, 1);	prof->numchans = jas_clrspc_numchans(prof->clrspc);	prof->numrefchans = jas_clrspc_numchans(prof->refclrspc);	if (prof->numchans == 1) {		if (mono(prof->iccprof, 0, &fwdpxformseq))			goto error;		if (mono(prof->iccprof, 1, &revpxformseq))			goto error;	} else if (prof->numchans == 3) {		if (triclr(prof->iccprof, 0, &fwdpxformseq))			goto error;		if (triclr(prof->iccprof, 1, &revpxformseq))			goto error;	}	prof->pxformseqs[SEQFWD(0)] = fwdpxformseq;	prof->pxformseqs[SEQREV(0)] = revpxformseq;#if 0	if (prof->numchans > 1) {		lut(prof->iccprof, 0, PER, &pxformseq);		pxformseqs_set(prof, SEQFWD(PER), pxformseq);		lut(prof->iccprof, 1, PER, &pxformseq);		pxformseqs_set(prof, SEQREV(PER), pxformseq);		lut(prof->iccprof, 0, CLR, &pxformseq);		pxformseqs_set(prof, SEQREV(CLR), pxformseq);		lut(prof->iccprof, 1, CLR, &pxformseq);		pxformseqs_set(prof, SEQREV(CLR), pxformseq);		lut(prof->iccprof, 0, SAT, &pxformseq);		pxformseqs_set(prof, SEQREV(SAT), pxformseq);		lut(prof->iccprof, 1, SAT, &pxformseq);		pxformseqs_set(prof, SEQREV(SAT), pxformseq);	}#endif	return prof;error:	return 0;}static jas_cmprof_t *jas_cmprof_create(){	int i;	jas_cmprof_t *prof;	if (!(prof = jas_malloc(sizeof(jas_cmprof_t))))		return 0;	memset(prof, 0, sizeof(jas_cmprof_t));	prof->iccprof = 0;	for (i = 0; i < JAS_CMPROF_NUMPXFORMSEQS; ++i)		prof->pxformseqs[i] = 0;	return prof;}void jas_cmprof_destroy(jas_cmprof_t *prof){ 	int i;	for (i = 0; i < JAS_CMPROF_NUMPXFORMSEQS; ++i) {		if (prof->pxformseqs[i]) {			jas_cmpxformseq_destroy(prof->pxformseqs[i]);			prof->pxformseqs[i] = 0;		}	}	if (prof->iccprof)		jas_iccprof_destroy(prof->iccprof);	jas_free(prof);}jas_cmprof_t *jas_cmprof_copy(jas_cmprof_t *prof){	jas_cmprof_t *newprof;	int i;	if (!(newprof = jas_cmprof_create()))		goto error;	newprof->clrspc = prof->clrspc;	newprof->numchans = prof->numchans;	newprof->refclrspc = prof->refclrspc;	newprof->numrefchans = prof->numrefchans;	newprof->iccprof = jas_iccprof_copy(prof->iccprof);	for (i = 0; i < JAS_CMPROF_NUMPXFORMSEQS; ++i) {		if (prof->pxformseqs[i]) {			if (!(newprof->pxformseqs[i] = jas_cmpxformseq_copy(prof->pxformseqs[i])))				goto error;		}	}	return newprof;error:	return 0;}/******************************************************************************\* Transform class.\******************************************************************************/jas_cmxform_t *jas_cmxform_create(jas_cmprof_t *inprof, jas_cmprof_t *outprof,  jas_cmprof_t *prfprof, int op, int intent, int optimize){	jas_cmxform_t *xform;	jas_cmpxformseq_t *inpxformseq;	jas_cmpxformseq_t *outpxformseq;	jas_cmpxformseq_t *altoutpxformseq;	jas_cmpxformseq_t *prfpxformseq;	int prfintent;	/* Avoid compiler warnings about unused parameters. */	optimize = 0;	prfintent = intent;	if (!(xform = jas_malloc(sizeof(jas_cmxform_t))))		goto error;	if (!(xform->pxformseq = jas_cmpxformseq_create()))		goto error;	switch (op) {	case JAS_CMXFORM_OP_FWD:		inpxformseq = fwdpxformseq(inprof, intent);		outpxformseq = revpxformseq(outprof, intent);		if (!inpxformseq || !outpxformseq)			goto error;		if (jas_cmpxformseq_append(xform->pxformseq, inpxformseq) ||		  jas_cmpxformseq_appendcnvt(xform->pxformseq,		  inprof->refclrspc, outprof->refclrspc) ||		  jas_cmpxformseq_append(xform->pxformseq, outpxformseq))			goto error;		xform->numinchans = jas_clrspc_numchans(inprof->clrspc);		xform->numoutchans = jas_clrspc_numchans(outprof->clrspc);		break;	case JAS_CMXFORM_OP_REV:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -