/*1* Copyright (c) 1999-2000 Image Power, Inc. and the University of2* British Columbia.3* Copyright (c) 2001-2002 Michael David Adams.4* All rights reserved.5*/67/* __START_OF_JASPER_LICENSE__8*9* JasPer License Version 2.010*11* Copyright (c) 2001-2006 Michael David Adams12* Copyright (c) 1999-2000 Image Power, Inc.13* Copyright (c) 1999-2000 The University of British Columbia14*15* All rights reserved.16*17* Permission is hereby granted, free of charge, to any person (the18* "User") obtaining a copy of this software and associated documentation19* files (the "Software"), to deal in the Software without restriction,20* including without limitation the rights to use, copy, modify, merge,21* publish, distribute, and/or sell copies of the Software, and to permit22* persons to whom the Software is furnished to do so, subject to the23* following conditions:24*25* 1. The above copyright notices and this permission notice (which26* includes the disclaimer below) shall be included in all copies or27* substantial portions of the Software.28*29* 2. The name of a copyright holder shall not be used to endorse or30* promote products derived from the Software without specific prior31* written permission.32*33* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS34* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER35* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS36* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING37* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A38* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO39* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL40* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING41* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,42* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION43* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE44* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE45* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.46* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS47* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL48* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS49* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE50* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE51* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL52* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,53* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL54* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH55* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,56* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH57* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY58* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.59*60* __END_OF_JASPER_LICENSE__61*/6263/*64* $Id: jpc_t1cod.h,v 1.2 2008-05-26 09:40:52 vp153 Exp $65*/6667#ifndef JPC_T1COD_H68#define JPC_T1COD_H6970/******************************************************************************\71* Includes.72\******************************************************************************/7374#include "jasper/jas_fix.h"75#include "jasper/jas_math.h"7677#include "jpc_mqcod.h"78#include "jpc_tsfb.h"7980/******************************************************************************\81* Constants.82\******************************************************************************/8384/* The number of bits used to index into various lookup tables. */85#define JPC_NMSEDEC_BITS 786#define JPC_NMSEDEC_FRACBITS (JPC_NMSEDEC_BITS - 1)8788/*89* Segment types.90*/9192/* Invalid. */93#define JPC_SEG_INVALID 094/* MQ. */95#define JPC_SEG_MQ 196/* Raw. */97#define JPC_SEG_RAW 29899/* The nominal word size. */100#define JPC_PREC 32101102/* Tier-1 coding pass types. */103#define JPC_SIGPASS 0 /* significance */104#define JPC_REFPASS 1 /* refinement */105#define JPC_CLNPASS 2 /* cleanup */106107/*108* Per-sample state information for tier-1 coding.109*/110111/* The northeast neighbour has been found to be significant. */112#define JPC_NESIG 0x0001113/* The southeast neighbour has been found to be significant. */114#define JPC_SESIG 0x0002115/* The southwest neighbour has been found to be significant. */116#define JPC_SWSIG 0x0004117/* The northwest neighbour has been found to be significant. */118#define JPC_NWSIG 0x0008119/* The north neighbour has been found to be significant. */120#define JPC_NSIG 0x0010121/* The east neighbour has been found to be significant. */122#define JPC_ESIG 0x0020123/* The south neighbour has been found to be significant. */124#define JPC_SSIG 0x0040125/* The west neighbour has been found to be significant. */126#define JPC_WSIG 0x0080127/* The significance mask for 8-connected neighbours. */128#define JPC_OTHSIGMSK \129(JPC_NSIG | JPC_NESIG | JPC_ESIG | JPC_SESIG | JPC_SSIG | JPC_SWSIG | JPC_WSIG | JPC_NWSIG)130/* The significance mask for 4-connected neighbours. */131#define JPC_PRIMSIGMSK (JPC_NSIG | JPC_ESIG | JPC_SSIG | JPC_WSIG)132133/* The north neighbour is negative in value. */134#define JPC_NSGN 0x0100135/* The east neighbour is negative in value. */136#define JPC_ESGN 0x0200137/* The south neighbour is negative in value. */138#define JPC_SSGN 0x0400139/* The west neighbour is negative in value. */140#define JPC_WSGN 0x0800141/* The sign mask for 4-connected neighbours. */142#define JPC_SGNMSK (JPC_NSGN | JPC_ESGN | JPC_SSGN | JPC_WSGN)143144/* This sample has been found to be significant. */145#define JPC_SIG 0x1000146/* The sample has been refined. */147#define JPC_REFINE 0x2000148/* This sample has been processed during the significance pass. */149#define JPC_VISIT 0x4000150151/* The number of aggregation contexts. */152#define JPC_NUMAGGCTXS 1153/* The number of zero coding contexts. */154#define JPC_NUMZCCTXS 9155/* The number of magnitude contexts. */156#define JPC_NUMMAGCTXS 3157/* The number of sign coding contexts. */158#define JPC_NUMSCCTXS 5159/* The number of uniform contexts. */160#define JPC_NUMUCTXS 1161162/* The context ID for the first aggregation context. */163#define JPC_AGGCTXNO 0164/* The context ID for the first zero coding context. */165#define JPC_ZCCTXNO (JPC_AGGCTXNO + JPC_NUMAGGCTXS)166/* The context ID for the first magnitude context. */167#define JPC_MAGCTXNO (JPC_ZCCTXNO + JPC_NUMZCCTXS)168/* The context ID for the first sign coding context. */169#define JPC_SCCTXNO (JPC_MAGCTXNO + JPC_NUMMAGCTXS)170/* The context ID for the first uniform context. */171#define JPC_UCTXNO (JPC_SCCTXNO + JPC_NUMSCCTXS)172/* The total number of contexts. */173#define JPC_NUMCTXS (JPC_UCTXNO + JPC_NUMUCTXS)174175/******************************************************************************\176* External data.177\******************************************************************************/178179/* These lookup tables are used by various macros/functions. */180/* Do not access these lookup tables directly. */181extern int jpc_zcctxnolut[];182extern int jpc_spblut[];183extern int jpc_scctxnolut[];184extern int jpc_magctxnolut[];185extern jpc_fix_t jpc_refnmsedec[];186extern jpc_fix_t jpc_signmsedec[];187extern jpc_fix_t jpc_refnmsedec0[];188extern jpc_fix_t jpc_signmsedec0[];189190/* The initial settings for the MQ contexts. */191extern jpc_mqctx_t jpc_mqctxs[];192193/******************************************************************************\194* Functions and macros.195\******************************************************************************/196197/* Initialize the MQ contexts. */198void jpc_initctxs(jpc_mqctx_t *ctxs);199200/* Get the zero coding context. */201int jpc_getzcctxno(int f, int orient);202#define JPC_GETZCCTXNO(f, orient) \203(jpc_zcctxnolut[((orient) << 8) | ((f) & JPC_OTHSIGMSK)])204205/* Get the sign prediction bit. */206int jpc_getspb(int f);207#define JPC_GETSPB(f) \208(jpc_spblut[((f) & (JPC_PRIMSIGMSK | JPC_SGNMSK)) >> 4])209210/* Get the sign coding context. */211int jpc_getscctxno(int f);212#define JPC_GETSCCTXNO(f) \213(jpc_scctxnolut[((f) & (JPC_PRIMSIGMSK | JPC_SGNMSK)) >> 4])214215/* Get the magnitude context. */216int jpc_getmagctxno(int f);217#define JPC_GETMAGCTXNO(f) \218(jpc_magctxnolut[((f) & JPC_OTHSIGMSK) | ((((f) & JPC_REFINE) != 0) << 11)])219220/* Get the normalized MSE reduction for significance passes. */221#define JPC_GETSIGNMSEDEC(x, bitpos) jpc_getsignmsedec_macro(x, bitpos)222jpc_fix_t jpc_getsignmsedec_func(jpc_fix_t x, int bitpos);223#define jpc_getsignmsedec_macro(x, bitpos) \224((bitpos > JPC_NMSEDEC_FRACBITS) ? jpc_signmsedec[JPC_ASR(x, bitpos - JPC_NMSEDEC_FRACBITS) & JAS_ONES(JPC_NMSEDEC_BITS)] : \225(jpc_signmsedec0[JPC_ASR(x, bitpos - JPC_NMSEDEC_FRACBITS) & JAS_ONES(JPC_NMSEDEC_BITS)]))226227/* Get the normalized MSE reduction for refinement passes. */228#define JPC_GETREFNMSEDEC(x, bitpos) jpc_getrefnmsedec_macro(x, bitpos)229jpc_fix_t jpc_refsignmsedec_func(jpc_fix_t x, int bitpos);230#define jpc_getrefnmsedec_macro(x, bitpos) \231((bitpos > JPC_NMSEDEC_FRACBITS) ? jpc_refnmsedec[JPC_ASR(x, bitpos - JPC_NMSEDEC_FRACBITS) & JAS_ONES(JPC_NMSEDEC_BITS)] : \232(jpc_refnmsedec0[JPC_ASR(x, bitpos - JPC_NMSEDEC_FRACBITS) & JAS_ONES(JPC_NMSEDEC_BITS)]))233234/* Arithmetic shift right (with ability to shift left also). */235#define JPC_ASR(x, n) \236(((n) >= 0) ? ((x) >> (n)) : ((x) << (-(n))))237238/* Update the per-sample state information. */239#define JPC_UPDATEFLAGS4(fp, rowstep, s, vcausalflag) \240{ \241register jpc_fix_t *np = (fp) - (rowstep); \242register jpc_fix_t *sp = (fp) + (rowstep); \243if ((vcausalflag)) { \244sp[-1] |= JPC_NESIG; \245sp[1] |= JPC_NWSIG; \246if (s) { \247*sp |= JPC_NSIG | JPC_NSGN; \248(fp)[-1] |= JPC_ESIG | JPC_ESGN; \249(fp)[1] |= JPC_WSIG | JPC_WSGN; \250} else { \251*sp |= JPC_NSIG; \252(fp)[-1] |= JPC_ESIG; \253(fp)[1] |= JPC_WSIG; \254} \255} else { \256np[-1] |= JPC_SESIG; \257np[1] |= JPC_SWSIG; \258sp[-1] |= JPC_NESIG; \259sp[1] |= JPC_NWSIG; \260if (s) { \261*np |= JPC_SSIG | JPC_SSGN; \262*sp |= JPC_NSIG | JPC_NSGN; \263(fp)[-1] |= JPC_ESIG | JPC_ESGN; \264(fp)[1] |= JPC_WSIG | JPC_WSGN; \265} else { \266*np |= JPC_SSIG; \267*sp |= JPC_NSIG; \268(fp)[-1] |= JPC_ESIG; \269(fp)[1] |= JPC_WSIG; \270} \271} \272}273274/* Initialize the lookup tables used by the codec. */275void jpc_initluts(void);276277/* Get the nominal gain associated with a particular band. */278int JPC_NOMINALGAIN(int qmfbid, int numlvls, int lvlno, int orient);279280/* Get the coding pass type. */281int JPC_PASSTYPE(int passno);282283/* Get the segment type. */284int JPC_SEGTYPE(int passno, int firstpassno, int bypass);285286/* Get the number of coding passess in the segment. */287int JPC_SEGPASSCNT(int passno, int firstpassno, int numpasses, int bypass,288int termall);289290/* Is the coding pass terminated? */291int JPC_ISTERMINATED(int passno, int firstpassno, int numpasses, int termall,292int lazy);293294#endif295296297