Hoyt's FORK of DemoIccMAX 2.1.17.hoyt
Documentation for Hoyt's FORK of DemoIccMAX
Loading...
Searching...
No Matches
IccSparseMatrix.h
Go to the documentation of this file.
1/** @file
2File: IccSparseMatrix.h
3
4Contains: Header for implementation of Sparse Matrices
5
6Version: V1
7
8Copyright: (c) see ICC Software License
9*/
10
11/*
12* The ICC Software License, Version 0.2
13*
14*
15* Copyright (c) 2012 The International Color Consortium. All rights
16* reserved.
17*
18* Redistribution and use in source and binary forms, with or without
19* modification, are permitted provided that the following conditions
20* are met:
21*
22* 1. Redistributions of source code must retain the above copyright
23* notice, this list of conditions and the following disclaimer.
24*
25* 2. Redistributions in binary form must reproduce the above copyright
26* notice, this list of conditions and the following disclaimer in
27* the documentation and/or other materials provided with the
28* distribution.
29*
30* 3. In the absence of prior written permission, the names "ICC" and "The
31* International Color Consortium" must not be used to imply that the
32* ICC organization endorses or promotes products derived from this
33* software.
34*
35*
36* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39* DISCLAIMED. IN NO EVENT SHALL THE INTERNATIONAL COLOR CONSORTIUM OR
40* ITS CONTRIBUTING MEMBERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47* SUCH DAMAGE.
48* ====================================================================
49*
50* This software consists of voluntary contributions made by many
51* individuals on behalf of the The International Color Consortium.
52*
53*
54* Membership in the ICC is encouraged when this software is used for
55* commercial purposes.
56*
57*
58* For more information on The International Color Consortium, please
59* see <http://www.color.org/>.
60*
61*
62*/
63
64//////////////////////////////////////////////////////////////////////
65// HISTORY:
66//
67// -Dec 30, 2012
68// Initial Sparse Matrix development
69//
70//////////////////////////////////////////////////////////////////////
71
72#ifndef _ICCSPARSEMATRIX_H
73#define _ICCSPARSEMATRIX_H
74
75#include "IccDefs.h"
76#include "IccUtil.h"
77
78
80{
81public:
83 virtual void init(void *pData)=0;
84
85 virtual icFloatNumber get(int index) const=0;
86 virtual void set(int index, icFloatNumber value)=0;
87
88 virtual icUInt8Number size() const=0;
89 virtual icUInt8Number *getPtr(int index=0) const=0;
90};
91
92template <class T>
94{
95public:
97 void init(void *pData) {m_pData = (T*)pData;}
98
99 virtual icUInt8Number size() const { return sizeof(T); }
100 virtual icUInt8Number *getPtr(int index) const {return (icUInt8Number*)(&m_pData[index]); }
101
102protected:
104};
105
106class CIccSparseMatrixUInt8 : public CIccSparseMatrixEntry<icUInt8Number>
107{
108public:
110
111 virtual icFloatNumber get(int index) const {return (icFloatNumber)m_pData[index]/255.0f;}
112 virtual void set(int index, icFloatNumber value) {m_pData[index] = value<0.0 ? 0 : (value > 1.0 ? 255 : (icUInt8Number)(value*255.0f+0.5f));}
113
114};
115
116class CIccSparseMatrixUInt16 : public CIccSparseMatrixEntry<icUInt16Number>
117{
118public:
120
121 virtual icFloatNumber get(int index) const {return (icFloatNumber)m_pData[index]/65535.0f;}
122 virtual void set(int index, icFloatNumber value) {m_pData[index] = value<0.0 ? 0 : (value > 1.0 ? 65535 : (icUInt8Number)(value*65535.0f+0.5f));}
123
124};
125
126class CIccSparseMatrixFloat16 : public CIccSparseMatrixEntry<icFloat16Number>
127{
128public:
130
131 virtual icFloatNumber get(int index) const {return icF16toF(m_pData[index]);}
132 virtual void set(int index, icFloatNumber value) {m_pData[index] = icFtoF16(value);}
133};
134
135class CIccSparseMatrixFloat32 : public CIccSparseMatrixEntry<icFloat32Number>
136{
137public:
139
140 virtual icFloatNumber get(int index) const {return (icFloatNumber)m_pData[index];}
141 virtual void set(int index, icFloatNumber value) {m_pData[index] = (icFloat32Number)value;}
142};
143
145{
146public:
148
149 virtual icFloatNumber get(int index) const {return m_pData[index];}
150 virtual void set(int index, icFloatNumber value) {m_pData[index] = value;}
151};
152
154{
155public:
156 CIccSparseMatrix(void *pMatrix=NULL, icUInt32Number nSize=0, icSparseMatrixType nType=icSparseMatrixFloatNum, bool bInitFromData=false);
158
159 virtual ~CIccSparseMatrix(void);
160
161 CIccSparseMatrix &operator=(const CIccSparseMatrix &mtx);
162
163 icUInt16Number Rows() const { return m_nRows; }
164 icUInt16Number Cols() const { return m_nCols; }
165
166 void Reset(void *pMatrix, icUInt32Number nSize, icSparseMatrixType nType, bool bInitFromData=true);
167 bool Init(icUInt16Number nRows, icUInt16Number nCols, bool bSetData=false);
168 void Clear();
169 bool Copy(const CIccSparseMatrix &mtx);
170 bool FillFromFullMatrix(icFloatNumber *pData);
171
172 bool MultiplyVector(icFloatNumber *pResult, const icFloatNumber *pVector) const;
173 bool Interp(icFloatNumber d1, const CIccSparseMatrix &mtx1, icFloatNumber d2, const CIccSparseMatrix &mtx2);
174 bool Union(const CIccSparseMatrix &mtx1, const CIccSparseMatrix &mtx2);
175
176 bool IsValid();
177
178 icUInt16Number GetNumEntries() const {return m_RowStart ? m_RowStart[m_nRows] : 0;}
179 icUInt16Number* GetRowStart() const { return m_RowStart; }
180 icUInt16Number GetRowOffset(icUInt16Number nRow=0) { return m_RowStart[nRow]; }
181
182 icUInt16Number* GetColumnsForRow(icUInt16Number nRow=0) const { return &m_ColumnIndices[m_RowStart[nRow]]; }
183 icUInt16Number GetNumRowColumns(icUInt16Number nRow) const { return (icUInt16Number)(m_RowStart[nRow+1] - m_RowStart[nRow]); }
184 IIccSparseMatrixEntry* GetData() const { return m_Data; }
185
186 icUInt32Number GetMaxEntries() { return m_nMaxEntries; }
187
188 static icUInt32Number MaxEntries(icUInt32Number nMemSize, icUInt16Number nRows, icUInt8Number nTypeSize);
189 static icUInt32Number MaxEntries(icUInt32Number nMemSize, icUInt16Number nRows, icSparseMatrixType nType) {return MaxEntries(nMemSize, nRows, EntrySize(nType));}
190 static icUInt32Number MemSize(icUInt32Number nMaxEntries, icUInt16Number nRows, icUInt8Number nTypeSize);
191 static icUInt32Number MemSize(icUInt32Number nMaxEntries, icUInt16Number nRows, icSparseMatrixType nType) {return MemSize(nMaxEntries, nRows, EntrySize(nType));}
192 static icUInt8Number EntrySize(icSparseMatrixType nType);
193
194protected:
198
201
204
206
208};
209
210
211
212#endif //_ICCSPARSEMATRIX_H
File: IccDefs.h
float icFloatNumber
All floating point operations/variables in IccProfLib use the icFloatNumber data type.
Definition IccDefs.h:100
#define ICCPROFLIB_API
icFloat16Number icFtoF16(icFloat32Number num)
Definition IccUtil.cpp:673
icFloatNumber icF16toF(icFloat16Number num)
Definition IccUtil.cpp:629
File: IccUtil.h.
unsigned int icUInt32Number
T * m_pData
void init(void *pData)
virtual icUInt8Number * getPtr(int index) const
CIccSparseMatrixEntry()
virtual icUInt8Number size() const
virtual void set(int index, icFloatNumber value)
virtual icFloatNumber get(int index) const
virtual icFloatNumber get(int index) const
virtual void set(int index, icFloatNumber value)
virtual icFloatNumber get(int index) const
virtual void set(int index, icFloatNumber value)
icUInt16Number GetNumRowColumns(icUInt16Number nRow) const
icUInt16Number GetRowOffset(icUInt16Number nRow=0)
icUInt16Number * GetColumnsForRow(icUInt16Number nRow=0) const
icUInt16Number * m_ColumnIndices
IIccSparseMatrixEntry * GetData() const
icUInt16Number Cols() const
IIccSparseMatrixEntry * m_Data
icUInt32Number GetMaxEntries()
icUInt8Number * m_pMatrix
icUInt16Number Rows() const
icUInt16Number m_nCols
icUInt16Number * GetRowStart() const
icSparseMatrixType m_nType
static icUInt32Number MaxEntries(icUInt32Number nMemSize, icUInt16Number nRows, icSparseMatrixType nType)
icUInt32Number m_nRawSize
icUInt16Number GetNumEntries() const
icUInt32Number m_nMaxEntries
icUInt16Number m_nRows
icUInt16Number * m_RowStart
static icUInt32Number MemSize(icUInt32Number nMaxEntries, icUInt16Number nRows, icSparseMatrixType nType)
virtual icFloatNumber get(int index) const
virtual void set(int index, icFloatNumber value)
virtual void set(int index, icFloatNumber value)
virtual icFloatNumber get(int index) const
virtual void set(int index, icFloatNumber value)=0
virtual icFloatNumber get(int index) const =0
virtual ~IIccSparseMatrixEntry()
virtual void init(void *pData)=0
virtual icUInt8Number size() const =0
virtual icUInt8Number * getPtr(int index=0) const =0
unsigned char icUInt8Number
Number definitions.
float icFloat32Number
icSparseMatrixType
unsigned short icUInt16Number
#define icSparseMatrixFloatNum
Convenience Enum Definition - Not defined in ICC specification.