Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libjni-mrsid / include / base / lti_sceneBuffer.h @ 3539

History | View | Annotate | Download (19.8 KB)

1
/* $Id: lti_sceneBuffer.h 3539 2006-01-09 12:23:20Z nacho $ */
2
/* //////////////////////////////////////////////////////////////////////////
3
//                                                                         //
4
// This code is Copyright (c) 2004 LizardTech, Inc, 1008 Western Avenue,   //
5
// Suite 200, Seattle, WA 98104.  Unauthorized use or distribution         //
6
// prohibited.  Access to and use of this code is permitted only under     //
7
// license from LizardTech, Inc.  Portions of the code are protected by    //
8
// US and foreign patents and other filings. All Rights Reserved.          //
9
//                                                                         //
10
////////////////////////////////////////////////////////////////////////// */
11
/* PUBLIC */
12

    
13
#ifndef LTI_SCENEBUFFER_H
14
#define LTI_SCENEBUFFER_H
15

    
16
// lt_lib_base
17
#include "lt_base.h"
18

    
19
#if defined(LT_COMPILER_MS)
20
        #pragma warning(push,4)
21
#endif
22

    
23
LT_BEGIN_NAMESPACE(LizardTech)
24

    
25
class LTIPixel;
26
class LTIOStreamInf;
27

    
28
/**
29
 * class to hold data passed between image stages
30
 *
31
 * This class holds a buffer of data which is used as the target of decode
32
 * operations in LTIImageStage.
33
 *
34
 * The data within the buffer is always represented as an array of bytes in
35
 * BSQ (band-sequential) format.  Each band is stored separately, so that the
36
 * underlying data is an array of N pointers, each array element being a
37
 * buffer for one band of the image.
38
 *
39
 * The dimensions of the buffer are set in the constructor.  The \b total
40
 * number of rows and columns represents the actual extent of the data array
41
 * in memory.  However, it is often desirable to only expose a subset of the
42
 * full rectangle, e.g. to access a large buffer in a stripwise fashion or to
43
 * overlay a small image into a large buffer.  This \b window may also be set
44
 * via the constructor, by providing a second set of row/column dimensions
45
 * and giving an offset for the upper-left position of the window.
46
 *
47
 * If the data pointer passed to the constructor is NULL, the class will
48
 * internally allocate the required memory (and retain ownership of it).
49
 *
50
 * Functions are provided to access that data within the buffer in a variety
51
 * of ways, relative to both the total buffer and the exposed window within
52
 * it.  You may also construct a buffer which is relative to another buffer.
53
 *
54
 * For convenience, a number of functions are also provided which allow the
55
 * user to copy data to and from an LTISceneBuffer object, using a variety of
56
 * formats.  For example, there are functions to import and export the data
57
 * in the buffer to BIP (band-interleaved) format.
58
 *
59
 * @note The pixel properties of the LTISceneBuffer must exactly match the
60
 * pixel properties of the image being decoded.
61
 */
62
class LTISceneBuffer
63
{
64
public:
65
   /**
66
    * @name Constructors and destructor
67
    */
68
   /*@{*/
69

    
70
   /**
71
    * constructor with default window
72
    *
73
    * Constructs an LTISceneBuffer with the window set to the total region of
74
    * the buffer.
75
    *
76
    * The \c data parameter may be NULL, in which case the memory will be
77
    * allocated internally.
78
    *
79
    * @param  pixelProps    pixel type to be used in the buffer
80
    * @param  totalNumCols  width of the buffer 
81
    * @param  totalNumRows  height of the buffer 
82
    * @param  data          pointer to the data array (may be NULL) 
83
    */
84
   LTISceneBuffer(const LTIPixel& pixelProps,
85
                  lt_uint32 totalNumCols,
86
                  lt_uint32 totalNumRows,
87
                  void** data);
88

    
89
   /**
90
    * constructor with explicit window
91
    *
92
    * Constructs an LTISceneBuffer with the window set to the given size and
93
    * positioned at the given offset.  The offset is given relative to the
94
    * total region, and the window must lie entirely within the region.
95
    *
96
    * The \c data parameter may be NULL, in which case the memory will be
97
    * allocated internally.
98
    *
99
    * @param  pixelProps     pixel type to be used in the buffer 
100
    * @param  totalNumCols   width of the buffer 
101
    * @param  totalNumRows   height of the buffer 
102
    * @param  colOffset      x-position of the window 
103
    * @param  rowOffset      y-position of the window 
104
    * @param  windowNumCols  width of the window 
105
    * @param  windowNumRows  height of the window 
106
    * @param  data           pointer to the data array (may be NULL) 
107
    */
108
   LTISceneBuffer(const LTIPixel& pixelProps,
109
                  lt_uint32 totalNumCols,
110
                  lt_uint32 totalNumRows,
111
                  lt_uint32 colOffset,
112
                  lt_uint32 rowOffset,
113
                  lt_uint32 windowNumCols,
114
                  lt_uint32 windowNumRows,
115
                  void** data);
116

    
117
   /**
118
    * constructor to overlay existing LTISceneBuffer
119
    *
120
    * Constructs an LTISceneBuffer which is a window into the given existing
121
    * LTISceneBuffer object.  The window of the new buffer is set to cover the
122
    * full window of the original buffer, starting at the given offset
123
    * (which is relative to the window of the original buffer).
124
    *
125
    * @param  original   the existing buffer, to be overlaid 
126
    * @param  colOffset  x-position of the new window 
127
    * @param  rowOffset  y-position of the new window 
128
    */
129
   LTISceneBuffer(const LTISceneBuffer& original,
130
                  lt_uint32 colOffset,
131
                  lt_uint32 rowOffset);
132

    
133
   /**
134
    * constructor to overlay existing LTISceneBuffer
135
    *
136
    * Constructs an LTISceneBuffer which is a window into the given existing
137
    * LTISceneBuffer object.  The window of the new buffer is set to start at
138
    * the given offset (which is relative to the window of the original
139
    * buffer).  The dimensions of the new window are passed in, and the new
140
    * window must not extend beyond the dimensions of the original buffer.
141
    *
142
    * @param  original   the existing buffer, to be overlaid 
143
    * @param  colOffset  x-position of the new window 
144
    * @param  rowOffset  y-position of the new window 
145
    * @param  windowNumCols  width of the window 
146
    * @param  windowNumRows  height of the window 
147
    */
148
   // exposes only a window of a different bsq buffer; window may not
149
   // extend outside of parent window; offset is relative to parent
150
   // window
151
   LTISceneBuffer(const LTISceneBuffer& original,
152
                  lt_uint32 colOffset,
153
                  lt_uint32 rowOffset,
154
                  lt_uint32 windowNumCols,
155
                  lt_uint32 windowNumRows);
156

    
157
   /** destructor */
158
   ~LTISceneBuffer();
159

    
160
   /*@}*/
161

    
162

    
163
   /**
164
    * @name Buffer property accessors
165
    */
166
   /*@{*/
167
   
168
   /**
169
   * get width of (entire) buffer
170
   *
171
   * Returns the total width of the buffer.
172
   *
173
   * @return the total width, in pixels
174
   */
175
   lt_int32 getTotalNumCols() const;
176

    
177
   /**
178
   * get height of (entire) buffer
179
   *
180
   * Returns the total height of the buffer.
181
   *
182
   * @return the total height, in pixels
183
   */
184
   lt_int32 getTotalNumRows() const;
185

    
186
   /**
187
   * get x-position of window
188
   *
189
   * Returns the x-position of the exposed window of the buffer.
190
   *
191
   * @return the x-position, relative to the whole buffer
192
   */
193
   lt_int32 getWindowColOffset() const;
194

    
195
   /**
196
   * get y-position of window
197
   *
198
   * Returns the y-position of the exposed window of the buffer.
199
   *
200
   * @return the y-position, relative to the whole buffer
201
   */
202
   lt_int32 getWindowRowOffset() const;
203

    
204
   /**
205
   * get width of exposed window
206
   *
207
   * Returns the width of the exposed window of the buffer.
208
   *
209
   * @return the window width, in pixels
210
   */
211
   lt_int32 getWindowNumCols() const;
212

    
213
   /**
214
   * get height of exposed window
215
   *
216
   * Returns the height of the exposed window of the buffer.
217
   *
218
   * @return the window height, in pixels
219
   */
220
   lt_int32 getWindowNumRows() const;
221

    
222
   /**
223
   * get size of (total) buffer
224
   *
225
   * Returns the total size of the buffer, in pixels.
226
   *
227
   * This is equal to getTotalNumCols() * getTotalNumRows().
228
   *
229
   * @return size of buffer
230
   */
231
   lt_int32 getTotalNumPixels() const;
232

    
233
   /**
234
   * get size of exposed window
235
   *
236
   * Returns the total size of the window of the buffer, in pixels.
237
   *
238
   * This is equal to getWindowNumCols() * getWindowNumRows().
239
   *
240
   * @return size of window in buffer
241
   */
242
   lt_int32 getWindowNumPixels() const;
243

    
244
   /**
245
   * get pixel type of buffer
246
   *
247
   * Returns the pixel type of the buffer.
248
   *
249
   * @return the pixel type
250
   */
251
   const LTIPixel& getPixelProps() const;
252

    
253
   /**
254
   * get number of bands
255
   *
256
   * Returns the number of bands of the pixel of the imager.
257
   *
258
   * This is the same as calling getPixelProps().getNumBands().
259
   *
260
   * @return the number of bands
261
   */
262
   lt_uint16 getNumBands() const;
263

    
264
   /*@}*/
265

    
266
   
267
   /**
268
    * @name Data buffer accessors
269
    */
270
   /*@{*/
271

    
272
   /**
273
    * get pointer to total buffer (for all bands)
274
    *
275
    * This function returns a pointer to the array of data buffers, one per
276
    * band.  This returns the "base" pointer for the total region, regardless
277
    * of the window setting.
278
    *
279
    * @return  a pointer to the array of data buffers
280
    */
281
   void** getTotalBSQData() const;
282

    
283
   /**
284
    * get pointer to total buffer (for 1 band)
285
    *
286
    * This function returns a pointer to the data buffer for the given band.
287
    * This returns the "base" pointer for the total region, regardless of the
288
    * window setting.
289
    *
290
    * @param   band  the band to access 
291
    * @return  a pointer to the data buffer
292
    */
293
   void* getTotalBandData(lt_uint16 band) const;
294

    
295
   /**
296
    * get pointer to window data (for all bands)
297
    *
298
    * This function returns a pointer to the array of data buffers, one per
299
    * band.  The buffer pointers are set to the start of the window within
300
    * the total buffer.
301
    *
302
    * @return  a pointer to the array of data buffers
303
    */
304
   void** getWindowBSQData() const;
305

    
306
   /**
307
    * get pointer to window data (for 1 band)
308
    *
309
    * This function returns a pointer to the data buffer for the given band.
310
    * The buffer pointer is set to the start of the window within
311
    * the total buffer.
312
    *
313
    * @param   band  the band to access 
314
    * @return  a pointer to the array of data buffers
315
    */
316
   void* getWindowBandData(lt_uint16 band) const;
317

    
318
   /**
319
    * get pointer to sample (total buffer)
320
    *
321
    * This function returns a pointer to the data for the given band of the
322
    * specified pixel.  The offset is relative to the total buffer.
323
    *
324
    * @param   x     the x-position of the pixel 
325
    * @param   y     the y-position of the pixel 
326
    * @param   band  the band to access 
327
    * @return  a pointer to the sample
328
    */
329
   void* getTotalSample(lt_uint32 x, lt_uint32 y, lt_uint16 band) const;
330

    
331
   /**
332
    * get pointer to sample (windowed)
333
    *
334
    * This function returns a pointer to the data for the given band of the
335
    * specified pixel.  The offset is relative to the window into the buffer.
336
    *
337
    * @param   x     the x-position of the pixel 
338
    * @param   y     the y-position of the pixel 
339
    * @param   band  the band to access 
340
    * @return  a pointer to the sample
341
    */
342
   void* getWindowSample(lt_uint32 x, lt_uint32 y, lt_uint16 band) const;
343
   /*@}*/
344

    
345

    
346
   /**
347
    * query pixel position
348
    *
349
    * This function returns true if and only if the given position lies
350
    * within the exposed window of the buffer.  (The position is relative
351
    * to the total buffer.)
352
    *
353
    * @param   x     the x-position of the pixel 
354
    * @param   y     the y-position of the pixel 
355
    */
356
   bool LTISceneBuffer::inWindow(lt_uint32 x, lt_uint32 y) const;
357

    
358

    
359
   /**
360
    * @name Import functions
361
    *
362
    * These functions provide an easy way to copy data from a variety of
363
    * layouts into an LTISceneBuffer object, in an efficient manner.
364
    *
365
    * The copying is performed relative to the exposed window of the buffer.
366
    */
367
   /*@{*/
368

    
369
   /**
370
    * import from another LTISceneBuffer, respecting NoData
371
    *
372
    * This function copies data from one source LTISceneBuffer object into
373
    * another destination LTISceneBuffer object.  If the \c nodata parameter
374
    * is set, any pixel in the source that matches the nodata pixel will not
375
    * be copied to the corresponding destination pixel position.
376
    *
377
    * @param   sourceData   the data to be imported 
378
    * @param   nodataPixel  source pixel will not be copied if matches; may be NULL 
379
    * @return  status code indicating success or failure
380
    */
381
   LT_STATUS importData(const LTISceneBuffer& sourceData,
382
                        const LTIPixel* nodataPixel);
383

    
384
   /**
385
    * import from another LTISceneBuffer, respecting approximate NoData
386
    *
387
    * This function copies data from one source LTISceneBuffer object into
388
    * another destination LTISceneBuffer object.  If the \c nodata parameter
389
    * is set, any pixel in the source that matches the nodata pixel will not
390
    * be copied to the corresponding destination pixel position.
391
    *
392
    * @param   sourceData   the data to be imported 
393
    * @param   nodataPixel  source pixel will not be copied if matches; may be NULL 
394
    * @param   mag          scene magnification 
395
    * @return  status code indicating success or failure
396
    */
397
   LT_STATUS importDataFuzzyNoData(const LTISceneBuffer& sourceData,
398
                                   const LTIPixel *nodataPixel,
399
                                   double mag);
400

    
401

    
402
   /**
403
    * import from memory (BSQ)
404
    *
405
    * This function copies data from a buffer in memory.  The source pointer
406
    * is assumed to be organized as an array of pointers to BSQ buffers, one
407
    * per band.
408
    *
409
    * @param   data  the source data
410
    * @return  status code indicating success or failure
411
    */
412
   LT_STATUS importDataBSQ(void** data);
413

    
414
   /**
415
    * import from memory (BSQ)
416
    *
417
    * This function copies data from a buffer in memory.  The source pointer
418
    * is assumed to be organized as one large buffer in BSQ format.
419
    *
420
    * @param   data  the source data
421
    * @return  status code indicating success or failure
422
    */
423
   LT_STATUS importDataBSQ(void* data);
424

    
425
   /**
426
    * import from memory (BIP)
427
    *
428
    * This function copies data from a buffer in memory.  The source pointer
429
    * is assumed to be organized as one large buffer in BIP format.
430
    *
431
    * @param   data  the source data
432
    * @return  status code indicating success or failure
433
    */
434
   LT_STATUS importDataBIP(void* data);
435

    
436
   /**
437
    * import from stream (BSQ)
438
    *
439
    * This function copies data from a buffer contained in the given stream.
440
    * The data is assumed to be organized as one large buffer in BSQ format.
441
    *
442
    * @param   stream  the source data
443
    * @return  status code indicating success or failure
444
    */
445
   LT_STATUS importDataBSQ(LTIOStreamInf& stream);
446

    
447
   /**
448
    * import from stream (BIP)
449
    *
450
    * This function copies data from a buffer contained in the given stream.
451
    * The data is assumed to be organized as one large buffer in BIP format.
452
    *
453
    * @param   stream  the source data
454
    * @return  status code indicating success or failure
455
    */
456
   LT_STATUS importDataBIP(LTIOStreamInf& stream);
457
   /*@}*/
458

    
459

    
460
   /**
461
    * @name Export functions
462
    *
463
    * These functions provide an easy way to copy data from an LTISceneBuffer
464
    * object to a variety of layouts, in an efficient manner.
465
    *
466
    * The copying is performed relative to the exposed window of the buffer.
467
    */
468
   /*@{*/
469

    
470
   /**
471
    * export to memory (BSQ)
472
    *
473
    * This function copies data to a buffer in memory.  The destination
474
    * pointer is assumed to be organized as an array of pointers to BSQ
475
    * buffers, one per band.
476
    *
477
    * If the \c data parameter is NULL, the function will allocate it
478
    * (but not retain ownership).
479
    *
480
    * @param   data  the destination data (may be NULL) [in/out]
481
    * @return  status code indicating success or failure
482
    */
483
   LT_STATUS exportDataBSQ(void**& data) const;
484

    
485
   /**
486
    * export to memory (BSQ)
487
    *
488
    * This function copies data to a buffer in memory.  The destination
489
    * pointer is assumed to be organized as one large buffer in BSQ
490
    * format.
491
    *
492
    * If the \c data parameter is NULL, the function will allocate it
493
    * (but not retain ownership).
494
    *
495
    * @param   data  the destination data (may be NULL) [in/out]
496
    * @return  status code indicating success or failure
497
    */
498
   LT_STATUS exportDataBSQ(void*& data) const;
499

    
500
   /**
501
    * export to memory (BIP)
502
    *
503
    * This function copies data to a buffer in memory.  The destination
504
    * pointer is assumed to be organized as one large buffer in BIP
505
    * format.
506
    *
507
    * If the \c data parameter is NULL, the function will allocate it
508
    * (but not retain ownership).
509
    *
510
    * @param   data  the destination data (may be NULL) [in/out]
511
    * @return  status code indicating success or failure
512
    */
513

    
514
   LT_STATUS exportDataBIP(void*& data) const;
515

    
516
   /**
517
    * export to stream (BSQ)
518
    *
519
    * This function copies data to a stream.  The destination is organized as
520
    * one large buffer in BSQ format.
521
    *
522
    * @param   stream  the destination stream 
523
    * @return  status code indicating success or failure
524
    */
525
   LT_STATUS exportDataBSQ(LTIOStreamInf& stream) const;
526

    
527
   /**
528
    * export to stream (BIP)
529
    *
530
    * This function copies data to a stream.  The destination is organized as
531
    * one large buffer in BIP format.
532
    *
533
    * @param   stream  the destination stream 
534
    * @return  status code indicating success or failure
535
    */
536
   LT_STATUS exportDataBIP(LTIOStreamInf& stream) const;
537

    
538
   /**
539
    * export to (arbitrary) memory
540
    *
541
    * This function copies data to a buffer.  The layout of the destination
542
    * is determined by the input parameters.
543
    *
544
    * For example, assuming RGB/uint8 data and WxH pixels:
545
    *
546
    * \li BIP format: pixelBytes=3, rowBytes=W*3, bandBytes=1
547
    * \li BIL: pixelBytes=1, rowBytes=W*3, bandBytes=W*1
548
    * \li BSQ: pixelBytes=1, rowBytes=W*1, bandBytes=W*H*1
549
    *
550
    * @param   data        the destination buffer (may not be NULL) 
551
    * @param   pixelBytes  width of pixel, in bytes (e.g. distance from "red" to "red")
552
    * @param   rowBytes    width of buffer, in bytes
553
    * @param   bandBytes   distance from sample to the next, in bytes (e.g. distance from "red" to "blue")
554
    * @return  status code indicating success or failure
555
    */
556
   LT_STATUS exportData(void* data,
557
                        lt_uint32 pixelBytes,
558
                        lt_uint32 rowBytes,
559
                        lt_uint32 bandBytes) const;
560
   /*@}*/
561

    
562
   void byteSwap();
563

    
564
   /**
565
    * compute alignment constraint
566
    *
567
    * This utility function returns a value which is equal to or greater than
568
    * the given value, when aligned to the given constraint.  This is useful
569
    * for determining proper row widths for certain applications.
570
    *
571
    * For example, given the value 99 and an alignment of 4, the function
572
    * will return 100.  Given a value of 128 and an alignment of 8, the
573
    * function will return 128.
574
    *
575
    * @param   value          the nominal buffer width
576
    * @param   byteAlignment  the alignment required
577
    * @return  the aligned width
578
    */
579
   static lt_uint32 addAlignment(lt_uint32 value, lt_uint32 byteAlignment);
580

    
581
private:
582
   void init(const LTIPixel& pixelProps,
583
             lt_uint32 totalWidth,
584
             lt_uint32 totalHeight,
585
             lt_uint32 xOffset,
586
             lt_uint32 yOffset,
587
             lt_uint32 windowWidth,
588
             lt_uint32 windowHeight,
589
             void** data);
590

    
591
   void** m_data;
592
   void** m_windowData;
593
   bool m_ownsData;
594

    
595
   mutable void** m_tmpBands; // only used by import/export functions
596
   
597
   lt_int32* m_sampleSizes; // size of each sample, in bytes
598

    
599
   LTIPixel* m_pixelProps;
600
   lt_uint16 m_numBands;
601

    
602
   lt_uint32 m_totalNumCols;
603
   lt_uint32 m_totalNumRows;
604
   lt_uint32 m_windowColOffset;
605
   lt_uint32 m_windowRowOffset;
606
   lt_uint32 m_windowNumCols;
607
   lt_uint32 m_windowNumRows;
608

    
609
   // nope
610
   LTISceneBuffer(const LTISceneBuffer&);
611
   LTISceneBuffer& operator=(const LTISceneBuffer&);
612
   bool operator==(const LTISceneBuffer&) const;
613
   bool operator!=(const LTISceneBuffer&) const;
614
};
615

    
616

    
617
LT_END_NAMESPACE(LizardTech)
618

    
619
#if defined(LT_COMPILER_MS)
620
        #pragma warning(pop)
621
#endif
622

    
623
#endif // LTI_SCENEBUFFER_H