zjf
2023-03-06 392b76515f40376b6d36f40a114850ef63650384
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
/////////////////////////////////////////////////////////////////////////////// 
// Copyright (C) 2002-2016, Open Design Alliance (the "Alliance"). 
// All rights reserved. 
// 
// This software and its documentation and related materials are owned by 
// the Alliance. The software may only be incorporated into application 
// programs owned by members of the Alliance, subject to a signed 
// Membership Agreement and Supplemental Software License Agreement with the
// Alliance. The structure and organization of this software are the valuable  
// trade secrets of the Alliance and its suppliers. The software is also 
// protected by copyright law and international treaty provisions. Application  
// programs incorporating this software must include the following statement 
// with their copyright notices:
//   
//   This application incorporates Teigha(R) software pursuant to a license 
//   agreement with Open Design Alliance.
//   Teigha(R) Copyright (C) 2002-2016 by Open Design Alliance. 
//   All rights reserved.
//
// By use of this software, its documentation or related materials, you 
// acknowledge and accept the above terms.
///////////////////////////////////////////////////////////////////////////////
 
#ifndef _OD_ODGIRASTERIMAGE_H_
#define _OD_ODGIRASTERIMAGE_H_
 
#include "RxObject.h"
 
#include "TD_PackPush.h"
 
/** \details
    This class represents a raster image within the Teigha vectorization framework.
    Library: TD_Gi
    <group OdGi_Classes> 
*/
class FIRSTDLL_EXPORT OdGiRasterImage : public OdRxObject
{
public:
  ODRX_DECLARE_MEMBERS(OdGiRasterImage);
 
  enum Units
  {
    kNone = 0,
    kMillimeter,
    kCentimeter,
    kMeter,
    kKilometer,
    kInch,
    kFoot,
    kYard,
    kMile,
    kMicroinches,
    kMils,
    kAngstroms,
    kNanometers,
    kMicrons,
    kDecimeters,
    kDekameters,
    kHectometers,
    kGigameters,
    kAstronomical,
    kLightYears,
    kParsecs     
  };
 
  enum ImageSource
  {
    kUndefinedSource = -1, // Flag not set (unknown source)
    kFromDwg         = 0,  // Raster image loaded from raster image definition
    kFromOleObject   = 1,  // Raster image generated from ole data source
    kFromRender      = 2,  // Raster image generated from rendering
 
    kFromUnderlay    = 10, // Raster image is part of underlay
    kFromImageBGRA32 = 11, // Raster image wraps OdGiImageBGRA32 image
 
    // Aliases
    kFromPdfUnderlay = kFromOleObject, // Raster image generated from PdfUnderlay
    kFromFile        = kFromDwg        // Raster image generated from disk file
  };
 
  enum TransparencyMode
  {
    kTransparencyDef  = -1, // Default for native raster image (alpha 0 - transparent, 1-255 opaque)
    kTransparencyOff  = 0,  // Alpha ignored for 32bpp formats
    kTransparency1Bit = 1,  // Alpha 0-254 transparent, 255 opaque
    kTransparency8Bit = 2   // Complete alpha level support for 32bpp formats
  };
 
  typedef struct tagPixelFormatInfo
  {
    OdUInt8 redOffset;
    OdUInt8 numRedBits;
    OdUInt8 greenOffset;
    OdUInt8 numGreenBits;
    OdUInt8 blueOffset;
    OdUInt8 numBlueBits;
    OdUInt8 alphaOffset;
    OdUInt8 numAlphaBits;
    OdUInt8 bitsPerPixel;
 
    bool operator ==(const struct tagPixelFormatInfo& other) const
    {
      return (redOffset == other.redOffset) && (greenOffset == other.greenOffset) &&
        (blueOffset == other.blueOffset) && (alphaOffset == other.alphaOffset) && (bitsPerPixel == other.bitsPerPixel) &&
        (numRedBits == other.numRedBits) && (numGreenBits == other.numGreenBits) && (numBlueBits == other.numBlueBits) &&
        (numAlphaBits == other.numAlphaBits);
    }
 
    tagPixelFormatInfo()
      : redOffset(0)
      , numRedBits(0)
      , greenOffset(0)
      , numGreenBits(0)
      , blueOffset(0)
      , numBlueBits(0)
      , alphaOffset(0)
      , numAlphaBits(0)
      , bitsPerPixel(0)
    {}
 
    /** \details
      Returns true if and only if the pixel format of this RasterImage object is RGB.
    */
    bool isRGB() const
    {
      return bitsPerPixel == 24 && 
        redOffset == 0 && greenOffset == 8 && blueOffset == 16 && numRedBits == 8 && numGreenBits == 8 && numBlueBits == 8;
    }
 
    /** \details
      Sets the pixel format of this RasterImage object to RGB.
      \note
      No palette conversion is performed.
    */
    void setRGB()
    {
      bitsPerPixel = 24;
      redOffset    = 0;
      greenOffset  = 8;
      blueOffset   = 16;
      numRedBits   = 8;
      numGreenBits = 8;
      numBlueBits  = 8;
    }
 
    /** \details
      Returns true if and only if the pixel format of this RasterImage object is BGR.
    */
    bool isBGR() const
    {
      return bitsPerPixel == 24 && 
        redOffset == 16 && greenOffset == 8 && blueOffset == 0 && numRedBits == 8 && numGreenBits == 8 && numBlueBits == 8;
    }
 
    /** \details
      Sets the pixel format the pixel format of this RasterImage object to BGR.
      \note
      No palette conversion is performed.
    */
    void setBGR()
    {
      bitsPerPixel = 24;
      redOffset    = 16;
      greenOffset  = 8;
      blueOffset   = 0;
      numRedBits   = 8;
      numGreenBits = 8;
      numBlueBits  = 8;
    }
 
    /** \details
      Returns true if and only if the pixel format of this RasterImage object is 16 bit BGR.
    */
    bool is16bitBGR() const
    {
      return bitsPerPixel == 16 && 
        redOffset == 10 && greenOffset == 5 && blueOffset == 0 && numRedBits == 5 && numGreenBits == 5 && numBlueBits == 5;
    }
 
    /** \details
      Sets the pixel format of this RasterImage object to 16 bit BGR.
      \note
      No palette conversion is performed.
    */
    void set16bitBGR()
    {
      bitsPerPixel = 16;
      redOffset    = 10;
      greenOffset  = 5;
      blueOffset   = 0;
      numRedBits   = 5;
      numGreenBits = 5;
      numBlueBits  = 5;
    }
 
    /** \details
      Returns true if and only if the pixel format of this RasterImage object is RGBA.
    */
    bool isRGBA() const
    {
      return bitsPerPixel == 32 && alphaOffset == 24 && numAlphaBits == 8 &&
        redOffset == 0 && greenOffset == 8 && blueOffset == 16 && numRedBits == 8 && numGreenBits == 8 && numBlueBits == 8;
    }
 
    /** \details
      Sets the pixel format of this RasterImage object to RGBA.
      \note
      No palette conversion is performed.
    */
    void setRGBA()
    {
      bitsPerPixel = 32;
      alphaOffset  = 24;
      numAlphaBits = 8;
      redOffset    = 0;
      greenOffset  = 8;
      blueOffset   = 16;
      numRedBits   = 8;
      numGreenBits = 8;
      numBlueBits  = 8;
    }
 
    /** \details
      Returns true if and only if the pixel format of this RasterImage object is BGRA.
    */
    bool isBGRA() const
    {
      return bitsPerPixel == 32 && alphaOffset == 24 && numAlphaBits == 8 &&
        redOffset == 16 && greenOffset == 8 && blueOffset == 0 && numRedBits == 8 && numGreenBits == 8 && numBlueBits == 8;
    }
 
    /** \details
      Sets the pixel format of this RasterImage object to BGRA.
      \note
      No palette conversion is performed.
    */
    void setBGRA()
    {
      bitsPerPixel = 32;
      alphaOffset  = 24;
      numAlphaBits = 8;
      redOffset    = 16;
      greenOffset  = 8;
      blueOffset   = 0;
      numRedBits   = 8;
      numGreenBits = 8;
      numBlueBits  = 8;
    }
  } PixelFormatInfo;
 
  /** \details
    Returns the image width in pixels of this RasterImage object.
  */
  virtual OdUInt32 pixelWidth() const = 0;
 
  /** \details
    Returns the image height in pixels of this RasterImage object.
  */
  virtual OdUInt32 pixelHeight() const = 0;
 
  /** \details
    Returns the default image resolution in pixels per unit of this RasterImage object.
 
    \param xPelsPerUnit [out]  Receives the pixels per unit value (x direction).
    \param yPelsPerUnit [out]  Receives the pixels per unit value (y direction).
 
    \remarks
    If the returned value is kNone, then xPelsPerUnit and yPelsPerUnit are not set.
  */
   virtual Units defaultResolution(double& xPelsPerUnit, double& yPelsPerUnit) const;
 
  /** \details
    Returns the number of bits per pixel used for colors by this RasterImage object.
  */
  virtual OdUInt32 colorDepth() const = 0;
 
  /** \details
    Returns the number of colors in the palette of this RasterImage object.
  */
  virtual OdUInt32 numColors() const = 0;
 
  /** \details
    Returns the index of transparent color in the image.
    \remarks
    If there is no transparent color, -1 should be returned.
    
    \note
    The default implementation of this function returns -1.
  */
  virtual int transparentColor() const;
 
  /** \details
    Returns the color for the specified index, from the palette of this RasterImage object.
    \param colorIndex [in]  Color index.
  */
  virtual ODCOLORREF color(OdUInt32 colorIndex) const = 0;
 
  /** \details
    Returns the size (in bytes) of the palette data of this RasterImage object.
  */
  virtual OdUInt32 paletteDataSize() const = 0;
 
  /** \details
    Returns the palette in BMP format of this RasterImage object.
    \param bytes [out]  Receives the palette data.
    
    \note
    It is up to the caller to allocate sufficient memory for the palette data.
  */
  virtual void paletteData(OdUInt8* bytes) const = 0;
 
  /** \details
    Returns the scan line size of this RasterImage object.
    
    \remarks
    This function returns the number of bytes between the beginning of scan line N and
    the beginning of scan line N+1 (taking into account any padding that is added to the 
    end of the scan line).
  */
  virtual OdUInt32 scanLineSize() const;
 
  /** \details
    Returns the specified set of scanlines in BMP format from this RasterImage object,
    or the pixel data in BMP format for this RasterImage object.
 
    \param scnLines [out]  Receives the scan line data.
    \param firstScanline [in]  Index of first scanline to retrieve.
    \param numLines [in]  Number of scanlines to retrieve.
 
    \remarks
 
    * The number of accessible scanlines is equal to value returned by pixelHeight().
    * The number of accessible bytes in a scanline is equal to the value returned by scanLineSize().
    * The scanline returned by firstScanline == 0 is the first scanline in the image.
    * The scanline returned by firstScanline == (pixelHeight() - 1) is the last scanline in the image.
 
    \note
    It us up to the caller to allocate sufficient memory for the scan line data.
 
    \note
    Implementation of this function with no arguments is optional; NULL can be returned 
    if it is inconvenient to implement. The caller must take 
    into account that the return value can be NULL.
  */
  virtual const OdUInt8* scanLines() const = 0;
  virtual void scanLines(OdUInt8* scnLines, OdUInt32 firstScanline, OdUInt32 numLines = 1) const = 0;
 
  /** \details
    Returns the pixel format for this RasterImage object.
    
    \note
    This function returns the pixel format of the palette,
    unless there is no palette, in which case it returns
    the pixel format of the image itself.
  */
  virtual PixelFormatInfo pixelFormat() const = 0;
 
  /** \details
    Returns the scan lines alignment, in bytes, for this RasterImage object.
    Example:
    scanLinesAlignment() returns 4 for Windows BMP.
  */
  virtual OdUInt32 scanLinesAlignment() const = 0;
 
  /** \details
    Returns image source.
  */
  virtual ImageSource imageSource() const;
 
  /** \details
    Returns transparency mode for 32bpp formats.
  */
  virtual TransparencyMode transparencyMode() const;
 
  /** \details
    Sets image source. Returns image with new image source.
    \param source [in]  New image source value.
  */
  OdSmartPtr<OdGiRasterImage> changeImageSource(ImageSource source);
 
  /** \details
    Sets transparency mode for 32bpp formats. Returns image with new transparency mode.
    \param mode [in]  New transparency mode.
  */
  OdSmartPtr<OdGiRasterImage> changeTransparencyMode(TransparencyMode mode);
 
  /** \details
    Returns the size of a single scan line in BMP format for this RasterImage object.
    \param pixelWidth [in]  Image width in pixels.
    \param colorDepth [in]  Number of bits per pixel.
  */
  static OdUInt32 calcBMPScanLineSize(OdUInt32 pixelWidth, int colorDepth);
 
  /** \details
    Returns the 32 bit mask for requested number of color bits and offset.
    \param numColorBits [in]  Number of color bits.
    \param colorOffset [in]  Offset of color bits.
  */
  static OdUInt32 calcColorMask(OdUInt8 numColorBits, OdUInt8 colorOffset = 0);
 
  /** \details
    Converts this raster image as specified.
    \param convertPaletteToRGB [in]  Color is converted to RGB if and only if true.
    \param brightness [in]  Image brightness [0 .. 100].
    \param fade [in]  Image fade value [0 .. 100].
    \param backgroundColor [in]  Background color.
    \param flipX [in]  Image is flipped about X-axis if and only if true.
    \param flipY [in]  Image is flipped about Y-axis if and only if true.
    \param rotate90 [in]  Image is rotated 90° if and only if true.
    \param pDestDesc [in]  Pointer to an OdGiRasterImageDesc object to receive the image parameters.
    \param transparency [in]  Image is transparent if true.
    \remarks
    Returns a SmartPointer to the converted image.
  */
  OdSmartPtr<OdGiRasterImage> convert(bool convertPaletteToRGB,
    double brightness = 50.0, double contrast = 50.0, double fade = 0.0, ODCOLORREF backgroundColor = 0,
    bool flipX = false, bool flipY = false, bool rotate90 = false,
    const OdGiRasterImage* pDestDesc = 0,
    bool transparency = false) const;
 
  /** \details
    Crops this raster image by rectangle.
    The format of returned raster image is identical to format of source raster image
 
    \param x [in] X-coordinate of start point
    \paramy [in] Y-coordinate of start point
    \paramwidth [in] Width of the crop rectangle
    \paramheight [in] Height of the crop rectangle
    \remarks 
    All arguments are in pixels
  */
  virtual OdSmartPtr<OdGiRasterImage> crop(OdUInt32 x, OdUInt32 y, OdUInt32 width, OdUInt32 height) const;
 
  /** \details
    Returns user-end implementation of raster image.
    \remarks
    If doesn't overrided by user-end raster image implementation always returns null.
  */
  virtual void *imp() const;
};
 
typedef OdSmartPtr<OdGiRasterImage> OdGiRasterImagePtr;
 
/** \details
    This interface simply extends GiRasterImage to set image source and transparency mode values.
    If raster image could be casted to this interface, values will be setted within this interface,
    elsewhere raster image wrapper will be created to reset this values.
    Library: TD_Gi
    <group OdGi_Classes> 
*/
class FIRSTDLL_EXPORT OdGiRasterImageParam : public OdGiRasterImage
{
public:
  ODRX_DECLARE_MEMBERS(OdGiRasterImageParam);
 
  enum ParamType
  {
    kImageSource      = (1 << 0),
    kTransparencyMode = (1 << 1)
  };
 
  /** \details
    Returns ParamType bitflags with which parameters are supported by this interface.
  */
  virtual OdUInt32 supportedParams() const = 0;
 
  /** \details
    Sets image source.
    \param source [in]  New image source value.
  */
  virtual void setImageSource(ImageSource source) { }
 
  /** \details
    Sets image transparency mode.
    \param mode [in]  New transparency mode value.
  */
  virtual void setTransparencyMode(TransparencyMode mode) { }
};
 
typedef OdSmartPtr<OdGiRasterImageParam> OdGiRasterImageParamPtr;
 
#include "TD_PackPop.h"
 
#endif //#ifndef _OD_ODGIRASTERIMAGE_H_