Path: blob/master/3rdparty/libjasper/jasper/jas_seq.h
16337 views
/*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* Sequence/Matrix Library65*66* $Id: jas_seq.h,v 1.2 2008-05-26 09:41:51 vp153 Exp $67*/6869#ifndef JAS_SEQ_H70#define JAS_SEQ_H7172/******************************************************************************\73* Includes.74\******************************************************************************/7576#include <jasper/jas_config.h>7778#include <jasper/jas_stream.h>79#include <jasper/jas_types.h>8081#ifdef __cplusplus82extern "C" {83#endif8485/******************************************************************************\86* Constants.87\******************************************************************************/8889/* This matrix is a reference to another matrix. */90#define JAS_MATRIX_REF 0x00019192/******************************************************************************\93* Types.94\******************************************************************************/9596/* An element in a sequence. */97typedef int_fast32_t jas_seqent_t;9899/* An element in a matrix. */100typedef int_fast32_t jas_matent_t;101102/* Matrix. */103104typedef struct {105106/* Additional state information. */107int flags_;108109/* The starting horizontal index. */110int_fast32_t xstart_;111112/* The starting vertical index. */113int_fast32_t ystart_;114115/* The ending horizontal index. */116int_fast32_t xend_;117118/* The ending vertical index. */119int_fast32_t yend_;120121/* The number of rows in the matrix. */122int_fast32_t numrows_;123124/* The number of columns in the matrix. */125int_fast32_t numcols_;126127/* Pointers to the start of each row. */128jas_seqent_t **rows_;129130/* The allocated size of the rows array. */131int_fast32_t maxrows_;132133/* The matrix data buffer. */134jas_seqent_t *data_;135136/* The allocated size of the data array. */137int_fast32_t datasize_;138139} jas_matrix_t;140141typedef jas_matrix_t jas_seq2d_t;142typedef jas_matrix_t jas_seq_t;143144/******************************************************************************\145* Functions/macros for matrix class.146\******************************************************************************/147148/* Get the number of rows. */149#define jas_matrix_numrows(matrix) \150((matrix)->numrows_)151152/* Get the number of columns. */153#define jas_matrix_numcols(matrix) \154((matrix)->numcols_)155156/* Get a matrix element. */157#define jas_matrix_get(matrix, i, j) \158((matrix)->rows_[i][j])159160/* Set a matrix element. */161#define jas_matrix_set(matrix, i, j, v) \162((matrix)->rows_[i][j] = (v))163164/* Get an element from a matrix that is known to be a row or column vector. */165#define jas_matrix_getv(matrix, i) \166(((matrix)->numrows_ == 1) ? ((matrix)->rows_[0][i]) : \167((matrix)->rows_[i][0]))168169/* Set an element in a matrix that is known to be a row or column vector. */170#define jas_matrix_setv(matrix, i, v) \171(((matrix)->numrows_ == 1) ? ((matrix)->rows_[0][i] = (v)) : \172((matrix)->rows_[i][0] = (v)))173174/* Get the address of an element in a matrix. */175#define jas_matrix_getref(matrix, i, j) \176(&(matrix)->rows_[i][j])177178#define jas_matrix_getvref(matrix, i) \179(((matrix)->numrows_ > 1) ? jas_matrix_getref(matrix, i, 0) : jas_matrix_getref(matrix, 0, i))180181#define jas_matrix_length(matrix) \182(max((matrix)->numrows_, (matrix)->numcols_))183184/* Create a matrix with the specified dimensions. */185jas_matrix_t *jas_matrix_create(int numrows, int numcols);186187/* Destroy a matrix. */188void jas_matrix_destroy(jas_matrix_t *matrix);189190/* Resize a matrix. The previous contents of the matrix are lost. */191int jas_matrix_resize(jas_matrix_t *matrix, int numrows, int numcols);192193int jas_matrix_output(jas_matrix_t *matrix, FILE *out);194195/* Create a matrix that references part of another matrix. */196void jas_matrix_bindsub(jas_matrix_t *mat0, jas_matrix_t *mat1, int r0, int c0,197int r1, int c1);198199/* Create a matrix that is a reference to a row of another matrix. */200#define jas_matrix_bindrow(mat0, mat1, r) \201(jas_matrix_bindsub((mat0), (mat1), (r), 0, (r), (mat1)->numcols_ - 1))202203/* Create a matrix that is a reference to a column of another matrix. */204#define jas_matrix_bindcol(mat0, mat1, c) \205(jas_matrix_bindsub((mat0), (mat1), 0, (c), (mat1)->numrows_ - 1, (c)))206207/* Clip the values of matrix elements to the specified range. */208void jas_matrix_clip(jas_matrix_t *matrix, jas_seqent_t minval,209jas_seqent_t maxval);210211/* Arithmetic shift left of all elements in a matrix. */212void jas_matrix_asl(jas_matrix_t *matrix, int n);213214/* Arithmetic shift right of all elements in a matrix. */215void jas_matrix_asr(jas_matrix_t *matrix, int n);216217/* Almost-but-not-quite arithmetic shift right of all elements in a matrix. */218void jas_matrix_divpow2(jas_matrix_t *matrix, int n);219220/* Set all elements of a matrix to the specified value. */221void jas_matrix_setall(jas_matrix_t *matrix, jas_seqent_t val);222223/* The spacing between rows of a matrix. */224#define jas_matrix_rowstep(matrix) \225(((matrix)->numrows_ > 1) ? ((matrix)->rows_[1] - (matrix)->rows_[0]) : (0))226227/* The spacing between columns of a matrix. */228#define jas_matrix_step(matrix) \229(((matrix)->numrows_ > 1) ? (jas_matrix_rowstep(matrix)) : (1))230231/* Compare two matrices for equality. */232int jas_matrix_cmp(jas_matrix_t *mat0, jas_matrix_t *mat1);233234jas_matrix_t *jas_matrix_copy(jas_matrix_t *x);235236jas_matrix_t *jas_matrix_input(FILE *);237238/******************************************************************************\239* Functions/macros for 2-D sequence class.240\******************************************************************************/241242jas_seq2d_t *jas_seq2d_copy(jas_seq2d_t *x);243244jas_matrix_t *jas_seq2d_create(int xstart, int ystart, int xend, int yend);245246#define jas_seq2d_destroy(s) \247jas_matrix_destroy(s)248249#define jas_seq2d_xstart(s) \250((s)->xstart_)251#define jas_seq2d_ystart(s) \252((s)->ystart_)253#define jas_seq2d_xend(s) \254((s)->xend_)255#define jas_seq2d_yend(s) \256((s)->yend_)257#define jas_seq2d_getref(s, x, y) \258(jas_matrix_getref(s, (y) - (s)->ystart_, (x) - (s)->xstart_))259#define jas_seq2d_get(s, x, y) \260(jas_matrix_get(s, (y) - (s)->ystart_, (x) - (s)->xstart_))261#define jas_seq2d_rowstep(s) \262jas_matrix_rowstep(s)263#define jas_seq2d_width(s) \264((s)->xend_ - (s)->xstart_)265#define jas_seq2d_height(s) \266((s)->yend_ - (s)->ystart_)267#define jas_seq2d_setshift(s, x, y) \268((s)->xstart_ = (x), (s)->ystart_ = (y), \269(s)->xend_ = (s)->xstart_ + (s)->numcols_, \270(s)->yend_ = (s)->ystart_ + (s)->numrows_)271272void jas_seq2d_bindsub(jas_matrix_t *s, jas_matrix_t *s1, int xstart,273int ystart, int xend, int yend);274275/******************************************************************************\276* Functions/macros for 1-D sequence class.277\******************************************************************************/278279#define jas_seq_create(start, end) \280(jas_seq2d_create(start, 0, end, 1))281282#define jas_seq_destroy(seq) \283(jas_seq2d_destroy(seq))284285#define jas_seq_set(seq, i, v) \286((seq)->rows_[0][(i) - (seq)->xstart_] = (v))287#define jas_seq_getref(seq, i) \288(&(seq)->rows_[0][(i) - (seq)->xstart_])289#define jas_seq_get(seq, i) \290((seq)->rows_[0][(i) - (seq)->xstart_])291#define jas_seq_start(seq) \292((seq)->xstart_)293#define jas_seq_end(seq) \294((seq)->xend_)295296#ifdef __cplusplus297}298#endif299300#endif301302303