Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libjni-ecwcompress / include / include-sdk / NCSJPCBuffer.h @ 12522

History | View | Annotate | Download (18.8 KB)

1
/********************************************************
2
** Copyright 2003 Earth Resource Mapping Ltd.
3
** This document contains proprietary source code of
4
** Earth Resource Mapping Ltd, and can only be used under
5
** one of the three licenses as described in the 
6
** license.txt file supplied with this distribution. 
7
** See separate license.txt file for license details 
8
** and conditions.
9
**
10
** This software is covered by US patent #6,442,298,
11
** #6,102,897 and #6,633,688.  Rights to use these patents 
12
** is included in the license agreements.
13
**
14
** FILE:     $Archive: /NCS/Source/include/NCSJPCBuffer.h $
15
** CREATED:  14/03/2003 3:27:34 PM
16
** AUTHOR:   Simon Cope
17
** PURPOSE:  CNCSJPCBuffer class header
18
** EDITS:    [xx] ddMmmyy NAME COMMENTS
19
 *******************************************************/
20

    
21
#ifndef NCSJPCBUFFER_H
22
#define NCSJPCBUFFER_H
23

    
24
#ifndef NCSJPCRECT_H
25
#include "NCSJPCRect.h"
26
#endif // NCSJPCRECT_H
27

    
28
#ifndef NCSMISC_H
29
#include "NCSMisc.h"
30
#endif
31
#ifndef NCSECWCLIENT_H
32
#include "NCSECWClient.h"
33
#endif
34
#ifndef NCSMEMPOOL_H
35
#include "NCSMemPool.h"
36
#endif // NCSMEMPOOL_H
37

    
38
#include <vector>
39

    
40
        /**
41
         * CNCSJPCBuffer class - the base JPC scanline buffer.
42
         * 
43
         * @author       Simon Cope
44
         * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
45
         */        
46
class NCSJPC_EXPORT_ALL CNCSJPCBuffer: public CNCSJPCRect {
47
public:
48
                /** Maximum UINT8 value */
49
        static const UINT32 MAXUINT8;
50
                /** Maximum UINT16 value */
51
        static const UINT32 MAXUINT16;
52
                /** Maximum UINT32 value */
53
        static const UINT32 MAXUINT32;
54
                /** Minimum UINT8 value */
55
        static const UINT32 MINUINT8;
56
                /** Minimum UINT16 value */
57
        static const UINT32 MINUINT16;
58
                /** Minimum UINT32 value */
59
        static const UINT32 MINUINT32;
60

    
61
                /** Maximum INT8 value */
62
        static const UINT32 MAXINT8;
63
                /** Maximum INT16 value */
64
        static const UINT32 MAXINT16;
65
                /** Maximum INT32 value */
66
        static const UINT32 MAXINT32;
67
                /** Minimum INT8 value */
68
        static const INT32 MININT8;
69
                /** Minimum INT16 value */
70
        static const INT32 MININT16;
71
                /** Minimum INT32 value */
72
        static const INT32 MININT32;
73
        
74
        /**
75
         * SystemInfo class - Some basic system capabilities we care about.
76
         * 
77
         * @author       Simon Cope
78
         * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
79
         */        
80
        class NCSJPC_EXPORT_ALL SystemInfo {
81
        public:
82
                        /** MMX Is present */
83
                bool        m_bMMXPresent;
84
                        /** SSE is present */
85
                bool        m_bSSEPresent;
86
                        /** SSE2 is present */
87
                bool        m_bSSE2Present;
88
                        /** 3DNow is present */
89
                bool        m_b3DNowPresent;
90
                        /** Bytes of physical memory on system */
91
                UINT64  m_nPhysicalMemBytes;
92
                        /** Default constructor */
93
                SystemInfo();
94
                        /** Current timestamp in US */
95
                static NCSTimeStampUs GetTime();
96
#ifdef WIN32
97
        private:
98
                        /** high-resolution Timer frequency */
99
                static LARGE_INTEGER sm_iFrequency;
100
#endif
101
        };
102
                /** SystemInfo instance */
103
        static SystemInfo        sm_SystemInfo;
104
                /** Buffer copy US */
105
        static NCSTimeStampUs        sm_usCopy;
106
                /** buffer copy bytes */
107
        static UINT64                        sm_nCopyBytes;
108
                /** buffer clear US */
109
        static NCSTimeStampUs        sm_usClear;
110
                /** buffer clear bytes */
111
        static UINT64                        sm_nClearBytes;
112
                /** buffer Alloc US */
113
        static NCSTimeStampUs        sm_usAlloc;
114
                /** Current buffer alloc bytes */
115
        static UINT64                        sm_nAllocBytes;
116
                /** buffer free US */
117
        static NCSTimeStampUs        sm_usFree;
118
        
119
        typedef enum {
120
                        /** s16 integer buffer type */
121
                BT_INT16                = NCSCT_INT16,
122
                        /** s32 integer buffer type */
123
                BT_INT32                = NCSCT_INT32,
124
                        /** IEEE4 single precision float buffer type */
125
                BT_IEEE4                = NCSCT_IEEE4
126
        } Type;
127

    
128
                /** FLAG: This buffer owns resources */
129
        static const UINT32 AT_OWNER;        
130
                /** FLAG: A child node returned the buffer and will free it later */
131
        static const UINT32 AT_CHILD;        
132
                /** Buffer is locked and can't be assigned to. */
133
        static const UINT32 AT_LOCKED;        
134

    
135
        /**
136
         * CNCSJPCBufferPool class - a rotating pool of buffers 
137
         * 
138
         * @author       Simon Cope
139
         * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
140
         */        
141
        class CNCSJPCBufferPool {
142
        public:
143
                        /** NCS memory pool */
144
                NCSPool        *m_pPool;
145
                        /** Size */
146
                UINT32 m_nSize;
147

    
148
                        /** Constructor */
149
                CNCSJPCBufferPool();
150
                        /** Destructor */
151
                ~CNCSJPCBufferPool();
152
                        /** Set the CodeBlock size */
153
                void SetCBSize(Type eType, UINT32 nWidth, UINT32 nHeight);
154
                        /** Alloc a buffer from the pool */
155
                void *Alloc();
156
                        /** Return a buffer to the pool */
157
                void Free(void *p);
158
        };
159

    
160
                /** Buffer type */
161
        Type        m_eType;
162
                /** buffer flags */
163
        UINT32        m_Flags;
164

    
165
                /** Actual buffer pointer */
166
        void        *m_pBuffer;
167
                /** Pool - optional */
168
        CNCSJPCBufferPool        *m_pPool;
169

    
170
                /** Buffer step size to next line */
171
        int                m_nStep;
172

    
173
                /** Default constructor, initialises members */
174
        CNCSJPCBuffer();
175
                /** Copy constructor */
176
        CNCSJPCBuffer::CNCSJPCBuffer( const class CNCSJPCBuffer& src );
177
                /** constructor, specify rect values */
178
        CNCSJPCBuffer(UINT32 nWidth, Type eType);
179
                /** constructor, specify rect values */
180
        CNCSJPCBuffer(UINT32 nWidth, UINT32 nHeight, Type eType);
181
                /** constructor, specify rect values */
182
        CNCSJPCBuffer(INT32 nX0, INT32 nY0, INT32 nX1, INT32 nY1, Type eType);
183
                /** constructor, specify rect values */
184
        CNCSJPCBuffer(INT32 nX0, INT32 nY0, UINT32 nWidth, UINT32 nHeight, Type eType);
185
                /** Virtual destructor */
186
        virtual ~CNCSJPCBuffer();
187
        
188
                /** Assignment operator */
189
        class CNCSJPCBuffer& CNCSJPCBuffer::operator=( const class CNCSJPCBuffer& src );
190

    
191
                /** Alloc a buffer the specified width and type */
192
        bool Alloc(UINT32 nWidth, Type eType);
193
                /** Alloc a buffer the specified width, height and type */
194
        bool Alloc(UINT32 nWidth, UINT32 nHeight, Type eType);
195
                /** Alloc a buffer with the specified TL, BR and type */
196
        bool Alloc(INT32 nX0, INT32 nY0, INT32 nX1, INT32 nY1, Type eType);
197
                /** Alloc a buffer with the specified TL, width, height and type */
198
        bool Alloc(INT32 nX0, INT32 nY0, UINT32 nWidth, UINT32 nHeight, Type eType);
199
                /** Free the buffer */
200
        void Free();
201

    
202
                /** Assign a buffer to this buffer */
203
        bool Assign(Type eType, void *pPtr, INT32 nStep = 0, bool bFree = true);
204
                /** Assign a buffer to this buffer */
205
        bool Assign(UINT32 nWidth, Type eType, void *pPtr, INT32 nStep = 0, bool bFree = true);
206
                /** Assign a buffer to this buffer */
207
        bool Assign(UINT32 nWidth, UINT32 nHeight, Type eType, void *pPtr, INT32 nStep = 0, bool bFree = true);
208
                /** Assign a buffer to this buffer */
209
        bool Assign(INT32 nX0, INT32 nY0, INT32 nX1, INT32 nY1, Type eType, void *pPtr, INT32 nStep = 0, bool bFree = true);
210
                /** Assign a buffer to this buffer */
211
        bool Assign(INT32 nX0, INT32 nY0, UINT32 nWidth, UINT32 nHeight, Type eType, void *pPtr, INT32 nStep = 0, bool bFree = true);
212
                /** Release this buffer */
213
        void Release();
214

    
215
                /** Set flags */
216
        void SetFlag(UINT32 Flag) { m_Flags |= Flag; };
217
                /** Unset flags */
218
        void UnSetFlags(UINT32 Flags) { m_Flags &= ~Flags; };
219
                /** Get flags */
220
        UINT32 GetFlags() { return(m_Flags); };
221
                /** test flags */
222
        bool TestFlags(UINT32 Flag) { return((m_Flags & Flag) ? true : false); };
223

    
224
                /** 
225
                 * Return the size of a buffer in bytes (default 1 cell).
226
                 * @param                eType                Type of buffer
227
                 * @param                nWidth                Number of pixels in buffer.
228
                 * @return      UINT32                calculated buffer size in bytes.
229
                 */
230
        static NCS_INLINE UINT32 Size(Type eType, UINT32 nWidth = 1, UINT32 nHeight = 1) {
231
                        UINT32 nLineSize = 0;
232
                        switch(eType) {
233
                                case BT_INT16:
234
                                                nLineSize = sizeof(INT16) * nWidth;
235
                                        break;
236
                                case BT_INT32:
237
                                                nLineSize = sizeof(INT32) * nWidth;
238
                                        break;
239
                                case BT_IEEE4:
240
                                                nLineSize = sizeof(IEEE4) * nWidth;
241
                                        break;
242
                        }
243
                        
244
                        if(nHeight != 1 && nLineSize % 32) {
245
                                // Pad scanlines to 32 byte multiples for performance
246
                                // when the buffer is > 1 line high 
247
                                nLineSize = (1 + nLineSize / 32) * 32;
248
                        }
249
                        return(nLineSize * nHeight);
250
                }
251
                /** Get buffer step in cells */
252
        NCS_INLINE UINT32 GetStep() { return(m_nStep); };
253
                /** Get buffer step in bytes */
254
        NCS_INLINE UINT32 GetStepBytes() { return(m_nStep * Size(m_eType)); };
255
                /** get buffer type */
256
        NCS_INLINE Type GetType() { return(m_eType); };
257
                /** get pointer to start of buffer (0,0) */
258
        NCS_INLINE void *GetPtr() { return(m_pBuffer); };
259
                /**        get pointer to buffer at (x,y) */
260
        NCS_INLINE void *GetPtr(INT32 x, INT32 y) { return((UINT8*)m_pBuffer + (y - GetY0()) * (INT32)GetStepBytes() + (x - GetX0()) * (INT32)Size(GetType())); };
261

    
262
                /** 
263
                 * Return the size of the Wavelet Tranform border for the specified pipeline type.
264
                 * @param                eType                Type of buffer
265
                 * @return      UINT32                Width/Height of border in CELLS.
266
                 */
267
        static NCS_INLINE UINT32 Border(Type eType) {
268
                        switch(eType) {
269
                                case BT_INT16:
270
                                case BT_INT32:
271
                                                return(1);
272
                                        break;
273
                                case BT_IEEE4:
274
                                                return(2);
275
                                        break;
276
                        }
277
                        return(0);
278
                }
279

    
280
                /** Clear buffer to 0 */
281
        void Clear();
282
                /** 
283
                 * Convert a line to a line of type T.
284
                 * @param                pDst                Pointer to Destination buffer
285
                 * @return      bool                true on succes, else false.
286
                 */
287
        template <class T> bool Convert(T *pDst, UINT8 nStep = 1) {
288
                        if(m_pBuffer && pDst) {
289
                                UINT32 x = 0;
290
                                UINT32 nWidth = GetWidth();
291

    
292
                                if(nStep == 1) {
293
                                        // Single band
294
                                        switch(GetType()) {
295
                                                case CNCSJPCBuffer::BT_INT16:
296
                                                                for(x = 0; x < nWidth; x++) {
297
                                                                        pDst[x] = (T)((INT16*)m_pBuffer)[x];
298
                                                                }
299
                                                        break;
300
                                                case CNCSJPCBuffer::BT_INT32:
301
                                                                for(x = 0; x < nWidth; x++) {
302
                                                                        pDst[x] = (T)((INT32*)m_pBuffer)[x];
303
                                                                }
304
                                                        break;
305
                                                case CNCSJPCBuffer::BT_IEEE4:
306
                                                                FLT_TO_INT_INIT();
307
                                                                        for(x = 0; x < nWidth; x++) {
308
                                                                                pDst[x] = (T)NCSfloatToInt32_RM(((IEEE4*)m_pBuffer)[x]);
309
                                        //                                        pDst[x] = (T)NCSFloor(((IEEE4*)m_pBuffer)[x]);
310
                                                                        }
311
                                                                FLT_TO_INT_FINI();
312
                                                        break;
313
                                        }
314
                                } else if(nStep == 3) {
315
                                        // 3 band - eg RGB
316
                                        switch(GetType()) {
317
                                                case CNCSJPCBuffer::BT_INT16:
318
                                                                for(x = 0; x < nWidth; x++) {
319
                                                                        pDst[x * 3] = (T)((INT16*)m_pBuffer)[x];
320
                                                                }
321
                                                        break;
322
                                                case CNCSJPCBuffer::BT_INT32:
323
                                                                for(x = 0; x < nWidth; x++) {
324
                                                                        pDst[x * 3] = (T)((INT32*)m_pBuffer)[x];
325
                                                                }
326
                                                        break;
327
                                                case CNCSJPCBuffer::BT_IEEE4:
328
                                                                FLT_TO_INT_INIT();
329
                                                                        for(x = 0; x < nWidth; x++) {
330
                                                                                pDst[x*3] = (T)NCSfloatToInt32_RM(((IEEE4*)m_pBuffer)[x]);
331
                                                                        }
332
                                                                FLT_TO_INT_FINI();
333
                                                        break;
334
                                        }
335
                                } else if(nStep == 4) {
336
                                        // 4 band, eg RGBA
337
                                        switch(GetType()) {
338
                                                case CNCSJPCBuffer::BT_INT16:
339
                                                                for(x = 0; x < nWidth; x++) {
340
                                                                        pDst[x * 4] = (T)((INT16*)m_pBuffer)[x];
341
                                                                }
342
                                                        break;
343
                                                case CNCSJPCBuffer::BT_INT32:
344
                                                                for(x = 0; x < nWidth; x++) {
345
                                                                        pDst[x * 4] = (T)((INT32*)m_pBuffer)[x];
346
                                                                }
347
                                                        break;
348
                                                case CNCSJPCBuffer::BT_IEEE4:
349
                                                                FLT_TO_INT_INIT();
350
                                                                        for(x = 0; x < nWidth; x++) {
351
                                                                                pDst[x*4] = (T)NCSfloatToInt32_RM(((IEEE4*)m_pBuffer)[x]);
352
                                                                        }
353
                                                                FLT_TO_INT_FINI();
354
                                        }
355
                                } else {
356
                                        switch(GetType()) {
357
                                                case CNCSJPCBuffer::BT_INT16:
358
                                                                for(x = 0; x < nWidth; x++) {
359
                                                                        pDst[x * nStep] = (T)((INT16*)m_pBuffer)[x];
360
                                                                }
361
                                                        break;
362
                                                case CNCSJPCBuffer::BT_INT32:
363
                                                                for(x = 0; x < nWidth; x++) {
364
                                                                        pDst[x * nStep] = (T)((INT32*)m_pBuffer)[x];
365
                                                                }
366
                                                        break;
367
                                                case CNCSJPCBuffer::BT_IEEE4:
368
                                                                FLT_TO_INT_INIT();
369
                                                                        for(x = 0; x < nWidth; x++) {
370
                                                                                pDst[x*nStep] = (T)NCSfloatToInt32_RM(((IEEE4*)m_pBuffer)[x]);
371
                                                                        }
372
                                                                FLT_TO_INT_FINI();
373
                                                        break;
374
                                        }
375
                                }
376
                                return(true);
377
                        }
378
                        return(false);
379
                }
380
                /** 
381
                 * Convert a line to a line of type T.
382
                 * @param                pDst                Pointer to Destination buffer
383
                 * @return      bool                true on succes, else false.
384
                 */
385
        template <class T> bool ConvertFLT(T *pDst, UINT8 nStep = 1) {
386
                        if(m_pBuffer && pDst) {
387
                                UINT32 x = 0;
388
                                UINT32 nWidth = GetWidth();
389

    
390
                                if(nStep == 1) {
391
                                        // Single band
392
                                        switch(GetType()) {
393
                                                case CNCSJPCBuffer::BT_INT16:
394
                                                                for(x = 0; x < nWidth; x++) {
395
                                                                        pDst[x] = (T)((INT16*)m_pBuffer)[x];
396
                                                                }
397
                                                        break;
398
                                                case CNCSJPCBuffer::BT_INT32:
399
                                                                for(x = 0; x < nWidth; x++) {
400
                                                                        pDst[x] = (T)((INT32*)m_pBuffer)[x];
401
                                                                }
402
                                                        break;
403
                                                case CNCSJPCBuffer::BT_IEEE4:
404
                                                                for(x = 0; x < nWidth; x++) {
405
                                                                        pDst[x] = (T)((IEEE4*)m_pBuffer)[x];
406
                                                                }
407
                                                        break;
408
                                        }
409
                                } else if(nStep == 3) {
410
                                        // 3 band - eg RGB
411
                                        switch(GetType()) {
412
                                                case CNCSJPCBuffer::BT_INT16:
413
                                                                for(x = 0; x < nWidth; x++) {
414
                                                                        pDst[x * 3] = (T)((INT16*)m_pBuffer)[x];
415
                                                                }
416
                                                        break;
417
                                                case CNCSJPCBuffer::BT_INT32:
418
                                                                for(x = 0; x < nWidth; x++) {
419
                                                                        pDst[x * 3] = (T)((INT32*)m_pBuffer)[x];
420
                                                                }
421
                                                        break;
422
                                                case CNCSJPCBuffer::BT_IEEE4:
423
                                                                for(x = 0; x < nWidth; x++) {
424
                                                                        pDst[x * 3] = (T)((IEEE4*)m_pBuffer)[x];
425
                                                                }
426
                                                        break;
427
                                        }
428
                                } else if(nStep == 4) {
429
                                        // 4 band, eg RGBA
430
                                        switch(GetType()) {
431
                                                case CNCSJPCBuffer::BT_INT16:
432
                                                                for(x = 0; x < nWidth; x++) {
433
                                                                        pDst[x * 4] = (T)((INT16*)m_pBuffer)[x];
434
                                                                }
435
                                                        break;
436
                                                case CNCSJPCBuffer::BT_INT32:
437
                                                                for(x = 0; x < nWidth; x++) {
438
                                                                        pDst[x * 4] = (T)((INT32*)m_pBuffer)[x];
439
                                                                }
440
                                                        break;
441
                                                case CNCSJPCBuffer::BT_IEEE4:
442
                                                                for(x = 0; x < nWidth; x++) {
443
                                                                        pDst[x * 4] = (T)((IEEE4*)m_pBuffer)[x];
444
                                                                }
445
                                                        break;
446
                                        }
447
                                } else {
448
                                        switch(GetType()) {
449
                                                case CNCSJPCBuffer::BT_INT16:
450
                                                                for(x = 0; x < nWidth; x++) {
451
                                                                        pDst[x * nStep] = (T)((INT16*)m_pBuffer)[x];
452
                                                                }
453
                                                        break;
454
                                                case CNCSJPCBuffer::BT_INT32:
455
                                                                for(x = 0; x < nWidth; x++) {
456
                                                                        pDst[x * nStep] = (T)((INT32*)m_pBuffer)[x];
457
                                                                }
458
                                                        break;
459
                                                case CNCSJPCBuffer::BT_IEEE4:
460
                                                                for(x = 0; x < nWidth; x++) {
461
                                                                        pDst[x * nStep] = (T)((IEEE4*)m_pBuffer)[x];
462
                                                                }
463
                                                        break;
464
                                        }
465
                                }
466
                                return(true);
467
                        }
468
                        return(false);
469
                }
470
                /** 
471
                 * Read buffer to a type T.
472
                 * @param                pDst                Pointer to Destination buffer
473
                 * @return      bool                true on succes, else false.
474
                 */
475
        template <class T> bool Read(T *pDst, UINT8 nStep = 1) {
476
                        for(UINT32 y = 0; y < GetHeight(); y++) {
477
                                Convert(pDst, nStep);
478
                        }
479
                        return(true);
480
                }
481
                /** 
482
                 * Read buffer to a (IEEE4/IEEE8) type T.
483
                 * @param                pDst                Pointer to Destination buffer
484
                 * @return      bool                true on succes, else false.
485
                 */
486
        template <class T> bool ReadFLT(T *pDst, UINT8 nStep = 1) {
487
                        for(UINT32 y = 0; y < GetHeight(); y++) {
488
                                ConvertFLT(pDst, nStep);
489
                        }
490
                        return(true);
491
                }
492

    
493
                /** Read value(s) from the buffer at the specified position, size */
494
        NCS_INLINE bool Read(void *pValue, INT32 nX, INT32 nY = 0, UINT32 nWidth = 1, UINT32 nHeight = 1, UINT32 nStep = 1) {
495
                        UINT32 x, y;
496
                        switch(m_eType) {
497
                                case BT_INT16:
498
                                                for(y = 0; y < nHeight; y++) {
499
                                                        for(x = 0; x < nWidth; x++) {
500
                                                                *((INT16*)pValue + nStep * y + x) = *((INT16*)m_pBuffer + m_nStep * ((nY - m_Y0) + y) + (nX - m_X0) + x);
501
                                                        }
502
                                                }
503
                                        break;
504
                                case BT_INT32:
505
                                                for(y = 0; y < nHeight; y++) {
506
                                                        for(x = 0; x < nWidth; x++) {
507
                                                                *((INT32*)pValue + nStep * y + x) = *((INT32*)m_pBuffer + m_nStep * ((nY - m_Y0) + y) + (nX - m_X0) + x);
508
                                                        }
509
                                                }
510
                                        break;
511
                                case BT_IEEE4:
512
                                                for(y = 0; y < nHeight; y++) {
513
                                                        for(x = 0; x < nWidth; x++) {
514
                                                                *((IEEE4*)pValue + nStep * y + x) = *((IEEE4*)m_pBuffer + m_nStep * ((nY - m_Y0) + y) + (nX - m_X0) + x);
515
                                                        }
516
                                                }
517
                                        break;
518
                        }
519
                        return(true);
520
                }
521
                /** Read from the buffer to the destination buffer, copying only the intersecting area */
522
        NCS_INLINE bool Read(CNCSJPCBuffer *pDst) {
523
                        CNCSJPCRect r(NCSMax(GetX0(), pDst->GetX0()),
524
                                                  NCSMax(GetY0(), pDst->GetY0()),
525
                                                  NCSMin(GetX1(), pDst->GetX1()),
526
                                                  NCSMin(GetY1(), pDst->GetY1()));
527
                        if(pDst->GetType() == GetType()) {
528
                                return(Copy(r.GetWidth(), r.GetHeight(), 
529
                                        (UINT8*)pDst->GetPtr() + (r.GetY0() - pDst->GetY0()) * pDst->GetStepBytes() + Size(m_eType, r.GetX0() - pDst->GetX0()), 
530
                                        pDst->GetStepBytes(), 
531
                                        (UINT8*)GetPtr() + (r.GetY0() - GetY0()) * GetStepBytes() + Size(m_eType, r.GetX0() - GetX0()), 
532
                                        GetStepBytes(), 
533
                                        m_eType));
534
                        } else {
535
                                for(UINT32 y = 0; y < r.GetHeight(); y++) {
536
                                        CNCSJPCBuffer tmp;
537
                                        tmp.Assign(r.GetX0(), r.GetY0(), r.GetWidth(), r.GetHeight(), GetType(), (UINT8*)GetPtr() + (y + r.GetY0() - GetY0()) * GetStepBytes() + Size(m_eType, r.GetX0() - GetX0()));
538
                                        switch(pDst->GetType()) {
539
                                                case BT_INT16:
540
                                                                tmp.Convert((INT16*)((UINT8*)pDst->GetPtr() + (y + r.GetY0() - pDst->GetY0()) * pDst->GetStepBytes() + Size(m_eType, r.GetX0() - pDst->GetX0())));
541
                                                        break;
542
                                                case BT_INT32:
543
                                                                tmp.Convert((INT32*)((UINT8*)pDst->GetPtr() + (y + r.GetY0() - pDst->GetY0()) * pDst->GetStepBytes() + Size(m_eType, r.GetX0() - pDst->GetX0())));
544
                                                        break;
545
                                                case BT_IEEE4:
546
                                                                tmp.ConvertFLT((IEEE4*)((UINT8*)pDst->GetPtr() + (y + r.GetY0() - pDst->GetY0()) * pDst->GetStepBytes() + Size(m_eType, r.GetX0() - pDst->GetX0())));
547
                                                        break;
548
                                        }
549
                                        tmp.Release();
550
                                }
551
                        }
552
                        return(true);
553
                }
554

    
555
                /** 
556
                 * Clip valus in the buffer to the specified range.
557
                 * @param                nMin                Min value
558
                 * @param                nMax                Max value
559
                 * @return      bool                true on success, else false & error set.
560
                 */
561
        bool Clip(INT32 nMin, INT32 nMax);
562
                /** 
563
                 * Clip valus in a buffer to the specified range.
564
                 * @param                fMin                Min value
565
                 * @param                fMax                Max value
566
                 * @return      bool                true on success, else false & error set.
567
                 */
568
        bool Clip(IEEE4 fMin, IEEE4 fMax);
569
                /** 
570
                 * Add a constant value to the buffer.
571
                 * @param                nValue                Constant value to add
572
                 * @param                nScale                Scale factor, *= NCS2Pow(-nScale)
573
                 * @return      bool                true on succes, else false.
574
                 */
575
        bool Add(const INT32 nValue, INT16 nScale = 0);
576
                /** 
577
                 * Add a constant value to the line.
578
                 * @param                fValue                Constant value to add
579
                 * @param                nScale                Scale factor, *= fScale
580
                 * @return      bool                true on succes, else false.
581
                 */
582
        bool Add(const IEEE4 fValue, INT16 nScale = 0);
583
                /** 
584
                 * Change bit depth (data range) of a buffer
585
                 * @param                nCurrentBits        Current bit depth
586
                 * @param                nNewBits                New bit depth
587
                 * @return      bool                true on succes, else false.
588
                 */
589
        bool OffsetShift(const INT32 nValue, UINT8 nCurrentBits, UINT8 nNewBits);
590
                /** 
591
                 * Copy from one pointer to another (may overlap).
592
                 * @param                nWidth                Width in pixels.
593
                 * @param                nHeight                Height in pixels.
594
                 * @param                pDst                Dest buffer
595
                 * @param                nDstStep        Dest buffer step size
596
                 * @param                pSrc                Src buffer
597
                 * @param                nSrcStep        Src buffer step size
598
                 * @param                eType                Buffer Type
599
                 * @return      bool                true on success, else false & error set.
600
                 */
601
        static bool Copy(UINT32 nWidth, UINT32 nHeight, void *pDst, INT32 nDstStep, const void *pSrc, INT32 nSrcStep, Type eType);
602

    
603
protected:
604

    
605
private:
606
        static CNCSJPCBufferPool sm_Pool;
607

    
608
        bool Alloc();
609
};
610

    
611
typedef std::vector<CNCSJPCBuffer> CNCSJPCBufferVector;
612

    
613
class NCSJPC_EXPORT_ALL CNCSJPCBufferCache {
614
public:
615
        virtual ~CNCSJPCBufferCache() {};
616
        virtual void SetBuffers(UINT32 nBuffers);
617
        virtual CNCSJPCBuffer *GetBuffer(UINT32 nBuffer);
618
        virtual CNCSJPCBuffer *FindBuffer(UINT32 &nBuffer, CNCSJPCRect &r, bool &bFound, CNCSJPCBuffer::Type eType);
619
private:
620
        CNCSJPCBufferVector m_Buffers;
621
};
622

    
623
#endif // !NCSJPCBUFFER_H