Statistics
| Revision:

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

History | View | Annotate | Download (21.6 KB)

1
/* $Id: lti_image.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_IMAGE_H
14
#define LTI_IMAGE_H
15

    
16
// lt_lib_mrsid_core
17
#include "lti_types.h"
18

    
19

    
20
LT_BEGIN_NAMESPACE(LizardTech)
21

    
22
#if defined(LT_COMPILER_MS)
23
   #pragma warning(push,4)
24
#endif
25

    
26

    
27
class LTIPixel;
28
class LTIMetadataDatabase;
29
class LTIGeoCoord;
30
class LTIPixelLookupTable;
31

    
32

    
33
/**
34
 * abstract class representing an image
35
 *
36
 * The LTIImage abstract class represents the basic properties of an image,
37
 * including dimensions, data type, background color, etc.   
38
 *
39
 * LTIImage does not support extraction of pixels (decoding); that
40
 * functionality is provided by the derived class LTIImageStage.
41
 */
42
class LTIImage
43
{
44
public:
45
   /**
46
    * constructor
47
    *
48
    * Constructs an LTIImage object with no data members (image properties)
49
    * set.
50
    *
51
    * The initialize() method should be called immediately after the object
52
    * is constructed.
53
    */
54
   LTIImage();
55

    
56
   /**
57
    * destructor
58
    */
59
   virtual ~LTIImage();
60

    
61
   /**
62
    * initialize the image object
63
    *
64
    * Derived classes should override this function.  This function must 
65
    * do the following (in order):
66
    *
67
    * \li call the initialize() function of the parent class
68
    * \li call the LTIImage::setPixelProps() function
69
    *     to set the required datatype, colorspace, and number of bands
70
    * \li call the LTIImage::setDimensions() function
71
    *     to set the required image width and height
72
    * \li call any optional "set" functions in LTIImage
73
    *     to set the additional image properties for the derived image type
74
    *
75
    * Status codes must be checked and handled appropriately after each of
76
    * these operations.
77
    *
78
    * This function is to be called by users immediately after the object is
79
    * constructed.
80
    *
81
   * @return status code indicating success or failure
82
    */
83
   virtual LT_STATUS initialize();
84

    
85
   /**
86
    * get image width
87
    *
88
    * This function returns the width of the image, in pixels.
89
    *
90
    * @return the image width
91
    */
92
   virtual lt_uint32 getWidth() const;
93

    
94
   /**
95
    * get image height
96
    *
97
    * This function returns the height of the image, in pixels.
98
    *
99
    * @return the image height
100
    */
101
   virtual lt_uint32 getHeight() const;
102
   
103
   /**
104
    * get image width and height at given magnification
105
    *
106
    * This function returns the width and height of the image, in pixels,
107
    * relative to the given magnification.
108
    *
109
    * @param  mag    magnification to determine width at 
110
    * @param  width  the image width at the magnification 
111
    * @param  height the image height at the magnification 
112
    * @return status code indicating success or failure
113
    */
114
   virtual LT_STATUS getDimsAtMag(double mag,
115
                                  lt_uint32& width,
116
                                  lt_uint32& height) const;
117

    
118
   /**
119
    * get number of bands
120
    *
121
    * This function returns the number of bands (colors) in the image.  This
122
    * value is closely related to the colorspace of the image.
123
    *
124
    * This function is equivalent to getPixelProps().getNumBands().
125
    *
126
    * @return the number of bands in the image
127
    */
128
   virtual lt_uint16 getNumBands() const;
129

    
130
   /**
131
    * get colorspace
132
    *
133
    * This function returns the colorspace of the image, e.g. RGB or greyscale.
134
    *
135
    * This function is equivalent to getPixelProps().getColorSpace().
136
    *
137
    * @return the colorspace of the image
138
    */
139
   virtual LTIColorSpace getColorSpace() const;
140

    
141
   /**
142
    * get data type
143
    *
144
    * This function returns the data type of the samples in the image, e.g.
145
    * unsigned byte or 32-bit float.
146
    *
147
    * This function is equivalent to getPixelProps().getDataType().
148
    *
149
    * @return the datatype of the image
150
    */
151
   virtual LTIDataType getDataType() const;
152

    
153
   /**
154
    * get the pixel properties of the image
155
    *
156
    * This function returns an object which describes the basic properties
157
    * of a pixel in the image.
158
    *
159
    * @return the pixel properties of the image
160
    */
161
   virtual const LTIPixel& getPixelProps() const;
162

    
163
   /**
164
    * get the values of the background pixel
165
    *
166
    * This function returns a pointer to an object containing the
167
    * values of the background pixel of the image.  If the pointer
168
    * is NULL, no background color has been set for the image.
169
    *
170
    * @return pointer to the background pixel 
171
    */
172
   virtual const LTIPixel* getBackgroundPixel() const;
173

    
174
   /**
175
    * get the values of the "no data" (transparency) pixel
176
    *
177
    * This function returns a pointer to an object containing the
178
    * values of the no data pixel of the image.  If the pointer
179
    * is NULL, no transparency color has been set for the image.
180
    *
181
    * @return pointer to the no data pixel 
182
    */
183
   virtual const LTIPixel* getNoDataPixel() const;
184

    
185
   /**
186
    * get the color lookup table, if any
187
    *
188
    * This function returns a pointer the color lookup table, used for
189
    * indexed or palletized images.  Will return NULL if no table
190
    * is used.
191
    *
192
    * @return pointer to the pixel lookup table
193
    */
194
   virtual const LTIPixelLookupTable* getPixelLookupTable() const;
195

    
196
   /**
197
    * get the minimum dynamic range value of image
198
    *
199
    * This function returns the pixels of minimum value of the 
200
    * dynamic range of the image.
201
    *
202
    * @return  pixel object with the minimum dynamic range values
203
    */
204
   virtual const LTIPixel& getMinDynamicRange() const;
205

    
206
   /**
207
    * get the maximum dynamic range value of image
208
    *
209
    * This function returns the pixels of maximum value of the 
210
    * dynamic range of the image.
211
    *
212
    * @return  pixel object with the maximum dynamic range values
213
    */
214
   virtual const LTIPixel& getMaxDynamicRange() const;
215

    
216
   /**
217
    * check if the range is "complete" or not
218
    *
219
    * This function returns true if the dynamic range min/max values for the
220
    * image correspond to the full range of the underlying datatype.
221
    *
222
    * @return  true if range spans the datatype's range
223
    */
224
   bool isNaturalDynamicRange() const;
225
   
226
   /**
227
    * get the geographic coordinates of the image
228
    *
229
    * This function returns the geographic coordinates of the image.
230
    *
231
    * Note that if the image has no explicit geographic coordinate information,
232
    * e.g. stored within the metadata of a file, the geographic coordinates
233
    * are implicitly set (upperleft is (0,-height), resolution is (1,-1))
234
    *
235
    * @return a pointer to an object containing the geographic coordinates
236
    */
237
   virtual const LTIGeoCoord& getGeoCoord() const;
238

    
239
   /**
240
    * is geo information "real" or not
241
    *
242
    * This function returns true if the geo information is implicit, i.e.
243
    * the source image did not have native geo coord info.
244
    *
245
    * @return true if and only if the geo information is not "real"
246
    */
247
   virtual bool isGeoCoordImplicit() const;
248

    
249
   /**
250
    * get the metadata associated with the image
251
    *
252
    * This function returns a reference to the object containing the
253
    * metadata associated with the image.
254
    *
255
    * @return a reference to the metadata database
256
    */
257
   virtual const LTIMetadataDatabase& getMetadata() const;
258

    
259
   /**
260
    * get a modifiable reference to the metadata associated with the image
261
    *
262
    * This function returns a reference to the object containing the
263
    * metadata associated with the image.  This function returns
264
    * a non-const reference, so it may be used by derived classes to
265
    * set metadata on the image.
266
    *
267
    * @return a reference to the metadata database
268
    */
269
   virtual LTIMetadataDatabase& getMetadataRef() const;
270

    
271
   /**
272
    * get the minimum magnification
273
    *
274
    * This function returns the minimum magnification
275
    * of the image.  Images that do not support "zooming out" will return
276
    * 1.0; images that contain "overviews", e.g. MrSID, will return a
277
    * value greater than 1.0.
278
    *
279
    * @return the minimum magnification
280
    */
281
   virtual double getMinMagnification() const;
282

    
283
   /**
284
    * get the maximum magnification
285
    *
286
    * This function returns the maximum magnification
287
    * of the image.  Images that do not support "zooming in" will return
288
    * 1.0; images that support "res-up", e.g. MrSID, will return a
289
    * value less than 1.0.
290
    *
291
    * @return the maximum magnification
292
    */
293
   virtual double getMaxMagnification() const;
294

    
295
   /**
296
    * get the physical (disk) size of the image
297
    *
298
    * Returns the number of bytes in the actual file (or stream) to the extent
299
    * possible and practical.  Note this value may be substantially different
300
    * than the "nominal" image size returned by getNominalImageSize(), e.g.
301
    * due to compression or sparse mosaics.
302
    *
303
    * This number should not be considered an exact representation:
304
    * \li if the actual value cannot be known, e.g. for streamed data, a value of 0
305
    *     will be returned
306
    * \li the returned value may or may not include bytes due to subsidiary files, e.g.
307
    *     BBB headers or World files
308
    * \li for "filter" image classes that perform some operation on an underlying image,
309
    *     the value returned is typically just the value of the underlying image
310
    * \li for "mosaic" image classes that wrap one or more underlying image
311
    *     classes, the value returned is typically the sum of the child images
312
    *
313
    * @return the physical size of the image, in bytes
314
    */
315
   virtual lt_int64 getPhysicalFileSize() const = 0;
316

    
317
   /**
318
    * get the nominal size of the image
319
    *
320
    * Returns number of bytes of actual data in the image, e.g. as if the image were
321
    * a raw file.  This value is simply the product of:
322
    * \li image width,
323
    * \li image height,
324
    * \li samples per pixel, and
325
    * \li bytes per sample.
326
    *
327
    * Note this value may be substantially different
328
    * than the "physical" image size returned by getPhysicalFileSize(), e.g.
329
    * due to compression or sparse mosaics.
330
    *
331
    * @return the nominal size of the image, in bytes
332
    */
333
   lt_int64 getNominalImageSize() const;
334

    
335
   /**
336
    * get the "name" of the image
337
    *
338
    * Returns a string representing the "name" of the image.  The name
339
    * corresponds roughly to the underlying file used, and should only
340
    * be used for debugging purposes.
341
    *
342
    * @return the name of the image
343
    */
344
   virtual const lt_utf8* getName() const;
345

    
346
   /**
347
    * get position of a named point
348
    *
349
    * Returns the (x,y) position of the given named point.
350
    *
351
    * @param  position  the position to be returned 
352
    * @param  x         the x-position of the point 
353
    * @param  y         the y-position of the point 
354
    */
355
   void getGeoPoint(LTIPosition position, double& x, double& y) const;
356

    
357
   /**
358
    * return new background pixel
359
    *
360
    * Creates and returns a new pixel of the correct background color for the
361
    * image.  If no background color has been set, a new black pixel will be
362
    * returned (unless the image is CMYK, in which case a white pixel will be
363
    * returned).
364
    *
365
    * The caller takes ownership of the returned pixel.
366
    *
367
    * @return a new background pixel
368
    */
369
   LTIPixel* createBackgroundPixel() const;
370

    
371
   /**
372
    * @name Projection functions
373
    */
374
   /*@{*/
375

    
376
  /**
377
    * project a value to a given magnification
378
    *
379
    * Given a value, such as a point, compute and return the value when
380
    * projected to the given magnification.
381
    *
382
    * @param  upperLeft     the value to be scaled  
383
    * @param  mag           the amount to scale by  
384
    * @param  newUpperLeft  the scaled value 
385
    * @return status indicating success or failure
386
    */
387
   virtual LT_STATUS projectPointAtMag(double upperLeft,
388
                                       double mag,
389
                                       double& newUpperLeft) const;
390

    
391
   /**
392
    * project a dimension to a given magnification
393
    *
394
    * Given a value, such as a width, compute and return the value when
395
    * projected to the given magnification.
396
    *
397
    * @param  dim     the value to be scaled  
398
    * @param  mag     the amount to scale by  
399
    * @param  newDim  the scaled value 
400
    * @return status indicating success or failure
401
    */
402
   virtual LT_STATUS projectDimAtMag(double dim,
403
                                     double mag,
404
                                     double& newDim) const;
405

    
406
   /*@}*/
407

    
408
   /**
409
    * check if image supports "random access" decoding
410
    *
411
    * Some formats, notably JPEG, do not support "selective" decoding.
412
    * That is, they require that scenes being decoding must march
413
    * in order down the scanlines of the image.  Formats like TIFF
414
    * and MrSID, however, are "selective": any scene can be requested
415
    * at any time.
416
    *
417
    * @return true if and only if the image supports arbitrary scene requests
418
    */
419
   virtual bool isSelective() const;
420
   
421
   /**
422
    * set standard metadata fields
423
    *
424
    * This function is used to populate the standard metadata fields for the
425
    * image, e.g. WIDTH, HEIGHT, COLORSPACE, etc.
426
    *
427
    * @return status code indicating success or failure
428
    */
429
   LT_STATUS setClassicalMetadata();
430

    
431
protected:
432
   /**
433
    * set pixel properties of the image
434
    *
435
    * This function is used to set the pixel properties of the image, namely
436
    * the datatype, colorspace, and number of bands.
437
    *
438
    * Derived classes are \em required to call this function from within their
439
    * initialize() method.
440
    *
441
    * @param pixelProps  the basic pixel properties of the image (number of
442
    *                    bands, colorspace, datatype)
443
    * @return status code indicating success or failure
444
    */
445
   LT_STATUS setPixelProps(const LTIPixel& pixelProps);
446

    
447
   /**
448
    * set width and height of the image
449
    *
450
    * This function is used to set the dimensions (width and height) of the image.
451
    *
452
    * Derived classes are \em required to call this function from within their
453
    * initialize() method.
454
    *
455
    * @param  width       the image width, in pixels
456
    * @param  height      the image height, in pixels
457
    * @return status code indicating success or failure
458
    */
459
   LT_STATUS setDimensions(lt_uint32 width,
460
                           lt_uint32 height);
461

    
462
   /**
463
    * set the background color of the image
464
    *
465
    * This function is used to set the background color of the image.
466
    *
467
    * Derived classes may choose to call this function from within their
468
    * initialize() method.  If the background color is not set, or if NULL
469
    * is passed in, a background color of black (sample values of 0) will
470
    * be used.  (Exception: for CMYK images, the background is set to white.)
471
    *
472
    * @param backgroundPixel  the data for the background color
473
    * @return status code indicating success or failure
474
    */
475
   LT_STATUS setBackgroundPixel(const LTIPixel* backgroundPixel);
476

    
477
   /**
478
    * set the "no data" (transparency) color of the image
479
    *
480
    * This function is used to set the "no data" or transparency color of the
481
    * image.
482
    *
483
    * Derived classes may choose to call this function from within their
484
    * initialize() method.  If the transparency color is not set, or if NULL
485
    * is passed in, the image will be assumed to have no transparent pixels.
486
    *
487
    * @param nodataPixel  the data for the transparency color
488
    * @return status code indicating success or failure
489
    */
490
   LT_STATUS setNoDataPixel(const LTIPixel* nodataPixel);
491

    
492
   /**
493
    * set the color lookup table
494
    *
495
    * This function is used to set the color used lookup table, used
496
    * for indexed color (palletized) images.
497
    *
498
    * Derived classes may choose to call this function from within their
499
    * initialize() method.  If the lookup table is not set, or if NULL
500
    * is passed in, the image will be assumed to have no lookup table.
501
    *
502
    * The LTIImageReader makes a local copy of the lookup table.
503
    *
504
    * @param  pixelLookupTable  pointer to the lookup table (or NULL)
505
    * @return status code indicating success or failure
506
    */
507
   LT_STATUS setPixelLookupTable(const LTIPixelLookupTable* pixelLookupTable);
508

    
509
   /**
510
    * set the dynamic range of the image
511
    *
512
    * This function is used to set the dynamic range of the image.  The
513
    * dynamic range consists of the minimum and maximum value for a given
514
    * sample.
515
    *
516
    * If both the minimum and maximum are NULL, the natural
517
    * range of the sample datatype will be used.
518
    *
519
    * Derived classes may choose to call this function from within their
520
    * initialize() method.  If the dynamic range is not set, the natural
521
    * minimum and maximum of the datatype of the sample is used.
522
    *
523
    * @param drmin       the minimum dynamic range value
524
    * @param drmax       the maximum dynamic range value
525
    * @return status code indicating success or failure
526
    */
527
   LT_STATUS setDynamicRange(const LTIPixel& drmin,
528
                             const LTIPixel& drmax);
529

    
530
   /**
531
    * set the dynamic range of the image
532
    *
533
    * This function is used to set the dynamic range of the image.  The
534
    * dynamic range consists of the minimum and maximum value for a given
535
    * sample.  This function sets these values to the natural
536
    * range of the sample datatype.
537
    *
538
    * Derived classes may choose to call this function from within their
539
    * initialize() method.  If the dynamic range is not set, the natural
540
    * minimum and maximum of the datatype of the sample is used.
541
    *
542
    * @return status code indicating success or failure
543
    */
544
   LT_STATUS setDefaultDynamicRange();
545

    
546
   /**
547
    * set the minimum and maximum magnifications of the image properties
548
    *
549
    * This function is used to set the minimum and maximum magnifications
550
    * of the image.
551
    *
552
    * Derived classes may choose to call this function from within their
553
    * initialize() method.  If the minimum and maximum magnifications are not
554
    * set, values of 1.0 are used (indicating the image may not be scaled
555
    * larger or smaller).
556
    *
557
    * @param minMag  the minimum magnification of the image
558
    * @param maxMag  the maximum magnification of the image
559
    * @return status code indicating success or failure
560
    */
561
   LT_STATUS setMagnification(double minMag,
562
                              double maxMag);
563

    
564
   /**
565
    * set the geographic coordinates of the image
566
    *
567
    * This function is used to set the geographic coordinates of the image.
568
    *
569
    * Derived classes may choose to call this function from within their
570
    * initialize() method.  If the geographic coordinates are not set, the
571
    * default position is assumed.
572
    *
573
    * @param geoCoord    the geographic coordinate information
574
    * @return status code indicating success or failure
575
    */
576
   LT_STATUS setGeoCoord(const LTIGeoCoord& geoCoord);
577

    
578
   /**
579
    * set the geographic coordinates of the image
580
    *
581
    * This function is used to set the geographic coordinates of the image to
582
    * a reasonable default, when there are no other geographic coordinates to
583
    * use.
584
    *
585
    * The default coordinates used are:
586
    * \li upperleft: (0.0, height-1.0)
587
    * \li resolution: (1.0, -1.0)
588
    * \li rotation: (0.0, 0.0)
589
    *
590
    * Calling this function will cause isGeoCoordImplicit() to return true.
591
    *
592
    * @return status code indicating success or failure
593
    */
594
   LT_STATUS setDefaultGeoCoord();
595

    
596
   /**
597
    * set the properties of an image based on another image
598
    *
599
    * This function is used to set all the properties of an image
600
    * to be the same as those of another image.
601
    *
602
    * This function can be used by image filter classes, as a convenience
603
    * function instead of explicitly calling all the various "set" functions.
604
    *
605
    * @param  image  the source image properties to use for this image
606
    * @return status code indicating success or failure
607
    */
608
   LT_STATUS setAllProperties(const LTIImage& image);
609

    
610
   /**
611
    * set the "name" of the image
612
    *
613
    * Sets a string representing the "name" of the image.  The name
614
    * should correspond roughly to the underlying file used, and should only
615
    * be used for debugging purposes.
616
    *
617
    * @param  name  the name of this image
618
    * @return status code indicating success or failure
619
    */
620
   virtual LT_STATUS setName(const lt_utf8* name);
621

    
622
   /**
623
    * set image to support "random access"
624
    *
625
    * This function is used to indicate the image supports "selective"
626
    * decoding.  See isSelective() for details.
627
    *
628
    * By default, all images support selective decoding.
629
    *
630
    * Derived classes may choose to call this function from within their
631
    * initialize() method.
632
    *
633
    * @param  enable  set to true if and only if the image supports selective encoding
634
    */
635
   void setIsSelective(bool enable);
636

    
637
   LT_STATUS inferPrecisionFromMetadata(LTIDataType,lt_uint8&);
638

    
639
private:
640
   lt_uint32 m_width;
641
   lt_uint32 m_height;
642
   LTIPixel* m_pixelProps;
643
   LTIPixel* m_backgroundPixel;
644
   LTIPixel* m_nodataPixel;
645
   LTIPixel* m_drminPixel;
646
   LTIPixel* m_drmaxPixel;
647
   double m_minMag;
648
   double m_maxMag;
649
   LTIGeoCoord* m_geoCoord;
650
   LTIMetadataDatabase* m_metadata;
651
   LTIPixelLookupTable* m_pixelLookupTable;
652
   lt_utf8* m_name;
653
   bool m_isSelective;
654
   bool m_geoCoordImplicit;
655

    
656
   // nope
657
   LTIImage(LTIImage&);
658
   LTIImage& operator=(const LTIImage&);
659
};
660

    
661

    
662

    
663
LT_END_NAMESPACE(LizardTech)
664

    
665
#if defined(LT_COMPILER_MS)
666
        #pragma warning(pop)
667
#endif
668

    
669
#endif // LTI_IMAGE_H