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
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
/////////////////////////////////////////////////////////////////////////////// 
// 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_GI_RASTER_WRAPPERS__
#define __OD_GI_RASTER_WRAPPERS__
 
#include "Gi/GiExport.h"
#include "Gi/GiRasterImage.h"
#include "Gi/GiImage.h"
#include "UInt8Array.h"
 
#include "TD_PackPush.h"
 
/** \details
    This class is a dummy implementation of the OdGiRasterImage interface.
 
    \remarks
    This class is intended to be used to preset image parameters for 
    OdDbRasterImageDef objects without the actual loading of raster image files.
 
    Library: TD_Gi
    <group OdGi_Classes>
*/
class ODGI_EXPORT OdGiRasterImageDesc : public OdGiRasterImageParam
{
  OdUInt32                          m_pixelWidth, m_pixelHeight, m_colorDepth, m_palSize, m_alignment;
  OdGiRasterImage::PixelFormatInfo  m_pixFmt;
  Units                             m_units;
  double                            m_xPelsPerUnit, m_yPelsPerUnit;
  OdUInt8*                          m_pPal;
  OdGiRasterImage::ImageSource      m_imageSource;
  OdGiRasterImage::TransparencyMode m_transparencyMode;
public:
  OdGiRasterImageDesc();
  virtual ~OdGiRasterImageDesc();
 
  /** \details
    Creates an OdGiRasterImage object with the specified parameters. 
    \param pixelWidth [in]  Image width in pixels.
    \param pixelHeight [in]  Image height in pixels.
    \param colorDepth [in]  Number of bits per pixel used for colors.
    \param units [in]  Units / pixel.
    \param xPelsPerUnit [in]  Pixels per unit value ( x direction ).
    \param yPelsPerUnit [in]  Pixels per unit value ( y direction ).
    \param pSourceImage [in]  Source raster image to copy parameters from.
    \remarks
    Returns a SmartPointer to the newly created object.
  */
  static OdGiRasterImagePtr createObject(OdUInt32 pixelWidth, OdUInt32 pixelHeight, Units units = kNone, double xPelsPerUnit = 0.0, double yPelsPerUnit = 0.0);
  static OdGiRasterImagePtr createObject(OdUInt32 pixelWidth, OdUInt32 pixelHeight, OdUInt32 colorDepth, Units units = kNone, double xPelsPerUnit = 0.0, double yPelsPerUnit = 0.0);
  static OdGiRasterImagePtr createObject(const OdGiRasterImage *pSourceImage);
 
  /** \details
    Copy parameters from original OdGiRasterImage object.
    \param pSourceImage [in]  Pointer to the original image object.
  */
  void setFrom(const OdGiRasterImage *pSourceImage);
 
  OdRxObjectPtr clone() const;
  void copyFrom(const OdRxObject *pSource);
 
  OdUInt32 pixelWidth() const;
  OdUInt32 pixelHeight() const;
  OdUInt32 colorDepth() const;
  OdUInt32 numColors() const;
  ODCOLORREF color(OdUInt32 colorIndex) const;
  OdUInt32 paletteDataSize() const;
  void paletteData(OdUInt8* bytes) const;
  OdUInt32 scanLineSize() const;
  const OdUInt8* scanLines() const;
  void scanLines(OdUInt8* scnLines, OdUInt32 firstScanline, OdUInt32 numLines = 1) const;
  PixelFormatInfo pixelFormat() const;
  OdUInt32 scanLinesAlignment() const;
  Units defaultResolution(double& xPelsPerUnit, double& yPelsPerUnit) const;
 
  /** \details
    Sets the image width in pixels of this RasterImageDesc object.
    \param pixelWidth [in]  Pixel width.
  */
  void setPixelWidth(OdUInt32 pixelWidth);
  /** \details
    Sets the image height in pixels of this RasterImageDesc object.
    \param pixelHeight [in]  Pixel height.
  */
  void setPixelHeight(OdUInt32 pixelHeight);
 
  /** \details
    Sets the number of bits per pixel used for colors by this RasterImageDesc object.
    \param colorDepth [in]  Color depth.
  */
  void setColorDepth(OdUInt32 colorDepth);
 
  OdGiRasterImage::PixelFormatInfo& pixelFormat();
 
  /** \details
    Sets the palette in BMP format for this RasterImageDesc object.
    \param paletteData [in]  Palette data.
    \param paletteSize [in]  Palette size in bytes.
  */
  void setPalette(OdUInt32 paletteSize, OdUInt8* paletteData);
 
  /** \details
    Sets the scan lines alignment, in bytes, for this RasterImage object.
    \param alignment [in]  Scan line alignment.
    Example:
    Alignment is 4 for Windows BMP.
  */
  void setScanLinesAlignment(OdUInt32 alignment);
 
  /** \details
    Sets the default raster image resolution for this RasterImage object.
    \param units [in]  Units / pixel.
    \param xPelsPerUnit [in]  Pixels per unit value ( x direction ).
    \param yPelsPerUnit [in]  Pixels per unit value ( y direction ).
  */
  void setDefaultResolution(Units units, double xPelsPerUnit, double yPelsPerUnit);
 
  OdUInt32 supportedParams() const;
  OdGiRasterImage::ImageSource imageSource() const;
  void setImageSource(OdGiRasterImage::ImageSource source);
  OdGiRasterImage::TransparencyMode transparencyMode() const;
  void setTransparencyMode(OdGiRasterImage::TransparencyMode mode);
};
 
class OdGiImageBGRA32;
 
/** \details
    Emulates OdGiImageBGRA32 within OdGiRasterImage interface.
    \remarks
    Stores only pointer to original image, not a SmartPointer, so deletion of original image before
    this class may cause access violation error.
    Library: TD_Gi
    <group OdGi_Classes>
*/
class ODGI_EXPORT OdGiRasterImageBGRA32 : public OdGiRasterImageParam
{
protected:
  OdGiImageBGRA32 *m_pBGRAImage;
  OdGiRasterImage::TransparencyMode m_transparencyMode;
public:
  OdGiRasterImageBGRA32();
  virtual ~OdGiRasterImageBGRA32();
  
  /** \details
    Creates an OdGiRasterImage object with the specified parameters.
    \param pImage [in]  Input BGRA32 image.
    \param transparencyMode [in]  Transparency mode.
    \remarks
    Returns a SmartPointer to the newly created object.
  */
  static OdGiRasterImagePtr createObject(OdGiImageBGRA32 *pImage, OdGiRasterImage::TransparencyMode transparencyMode = OdGiRasterImage::kTransparency8Bit);
 
  OdUInt32 pixelWidth() const;
  OdUInt32 pixelHeight() const;
  OdUInt32 colorDepth() const;
  OdUInt32 numColors() const;
  ODCOLORREF color(OdUInt32 colorIndex) const;
  OdUInt32 paletteDataSize() const;
  void paletteData(OdUInt8* bytes) const;
  OdUInt32 scanLineSize() const;
  const OdUInt8* scanLines() const;
  void scanLines(OdUInt8* scnLines, OdUInt32 firstScanline, OdUInt32 numLines = 1) const;
  OdGiRasterImage::PixelFormatInfo pixelFormat() const;
  OdUInt32 scanLinesAlignment() const;
  OdGiRasterImage::Units defaultResolution(double& xPelsPerUnit, double& yPelsPerUnit) const;
  OdUInt32 supportedParams() const;
  OdGiRasterImage::ImageSource imageSource() const;
  OdGiRasterImage::TransparencyMode transparencyMode() const;
  void setTransparencyMode(OdGiRasterImage::TransparencyMode mode);
 
  OdRxObjectPtr clone() const;
  void copyFrom(const OdRxObject *pSource);
};
 
/** \details
    Extends OdGiRasterImageBGRA32 class to keep a copy of OdGiImageBGRA32 inside.
    Library: TD_Gi
    <group OdGi_Classes>
*/
class ODGI_EXPORT OdGiRasterImageBGRA32Holder : public OdGiRasterImageBGRA32
{
protected:
  OdGiImageBGRA32 m_ImageCopy;
public:
  OdGiRasterImageBGRA32Holder();
  ~OdGiRasterImageBGRA32Holder();
  
  /** \details
    Creates an OdGiRasterImage object with the specified parameters.
    \param pImage [in]  Input BGRA32 image.
    \param transparencyMode [in]  Transparency mode.
    \remarks
    Returns a SmartPointer to the newly created object.
  */
  static OdGiRasterImagePtr createObject(OdGiImageBGRA32 *pImage, OdGiRasterImage::TransparencyMode transparencyMode = OdGiRasterImage::kTransparency8Bit);
 
  OdRxObjectPtr clone() const;
  void copyFrom(const OdRxObject *pSource);
};
 
/** \details
    Extends OdGiRasterImageBGRA32 class to keep a copy of OdGiImageBGRA32 and pixels inside.
    Library: TD_Gi
    <group OdGi_Classes>
*/
class ODGI_EXPORT OdGiRasterImageBGRA32Copy : public OdGiRasterImageBGRA32Holder
{
private:
  OdGiPixelBGRA32Array m_pxArray;
public:
  OdGiRasterImageBGRA32Copy();
  ~OdGiRasterImageBGRA32Copy();
  
  /** \details
    Creates an OdGiRasterImage object with the specified parameters.
    \param pImage [in]  Input BGRA32 image.
    \param transparencyMode [in]  Transparency mode.
    \remarks
    Returns a SmartPointer to the newly created object.
  */
  static OdGiRasterImagePtr createObject(OdGiImageBGRA32 *pImage, OdGiRasterImage::TransparencyMode transparencyMode = OdGiRasterImage::kTransparency8Bit);
 
  OdRxObjectPtr clone() const;
  void copyFrom(const OdRxObject *pSource);
};
 
/** \details
    This class stores full copy of original raster image data.
    Library: TD_Gi
    <group OdGi_Classes>
*/
class ODGI_EXPORT OdGiRasterImageHolder : public OdGiRasterImageParam
{
  OdUInt32                          m_pixelWidth, m_pixelHeight, m_colorDepth, m_alignment;
  OdGiRasterImage::PixelFormatInfo  m_pixFmt;
  Units                             m_units;
  double                            m_xPelsPerUnit, m_yPelsPerUnit;
  OdGiRasterImage::ImageSource      m_imageSource;
  OdGiRasterImage::TransparencyMode m_transparencyMode;
  int                               m_transparentColor;
  OdUInt8Array                      m_palData;
  OdUInt8Array                      m_pixData;
public:
  OdGiRasterImageHolder();
  virtual ~OdGiRasterImageHolder();
 
  /** \details
    Store data from original OdGiRasterImage object.
    \param pOrig [in]  Pointer to the original image object.
  */
  void setFrom(const OdGiRasterImage* pOrig);
 
  /** \details
    Creates an OdGiRasterImage object from original OdGiRasterImage object.
    \param pImage [in]  Pointer to the original image object.
    \remarks
    Returns a SmartPointer to the newly created object.
  */
  static OdGiRasterImagePtr createObject(const OdGiRasterImage* pImage);
 
  OdUInt32 pixelWidth() const;
  OdUInt32 pixelHeight() const;
  Units defaultResolution(double& xPelsPerUnit, double& yPelsPerUnit) const;
  OdUInt32 colorDepth() const;
  OdUInt32 numColors() const;
  ODCOLORREF color(OdUInt32 colorIndex) const;
  OdUInt32 paletteDataSize() const;
  void paletteData(OdUInt8* bytes) const;
  OdUInt32 scanLineSize() const;
  void scanLines(OdUInt8* scnLines, OdUInt32 firstScanline, OdUInt32 numLines = 1) const;
  const OdUInt8* scanLines() const;
  PixelFormatInfo pixelFormat() const;
  OdUInt32 scanLinesAlignment() const;
  int transparentColor() const;
  ImageSource imageSource() const;
  TransparencyMode transparencyMode() const;
  OdUInt32 supportedParams() const;
  void setImageSource(ImageSource source);
  void setTransparencyMode(TransparencyMode mode);
 
  OdRxObjectPtr clone() const;
  void copyFrom(const OdRxObject *pSource);
};
 
/** \details
    This class is the base class for raster image transformer objects.
 
    Library: TD_Gi
 
    \remarks
    Transforming an image does not effect the orignal.
 
    The default methods for this class do nothing but return the
    corresponding values from the original object.
 
    <group OdGi_Classes>
*/
class ODGI_EXPORT OdGiRasterImageWrapper : public OdGiRasterImageParam
{
  OdGiRasterImagePtr m_pOrig;
public:
  OdGiRasterImageWrapper();
  virtual ~OdGiRasterImageWrapper();
 
  /** \details
    Sets the original OdGiRasterImage object associated with this RasterImageWrapper object.
    \param pOrig [in]  Pointer to the original image object.
  */
  void setOriginal(const OdGiRasterImage* pOrig);
  const OdGiRasterImage *original() const;
  OdGiRasterImagePtr cloneOriginal() const;
 
  OdUInt32 pixelWidth() const;
  OdUInt32 pixelHeight() const;
  Units defaultResolution(double& xPelsPerUnit, double& yPelsPerUnit) const;
  OdUInt32 colorDepth() const;
  OdUInt32 numColors() const;
  ODCOLORREF color(OdUInt32 colorIndex) const;
  OdUInt32 paletteDataSize() const;
  void paletteData(OdUInt8* bytes) const;
  OdUInt32 scanLineSize() const;
  void scanLines(OdUInt8* scnLines, OdUInt32 firstScanline, OdUInt32 numLines = 1) const;
  const OdUInt8* scanLines() const;
  PixelFormatInfo pixelFormat() const;
  OdUInt32 scanLinesAlignment() const;
  int transparentColor() const;
  ImageSource imageSource() const;
  TransparencyMode transparencyMode() const;
  OdUInt32 supportedParams() const;
  void setImageSource(ImageSource source);
  void setTransparencyMode(TransparencyMode mode);
  void* imp() const;
 
  OdRxObjectPtr clone() const;
  void copyFrom(const OdRxObject *pSource);
};
 
/** \details
    This raster image transformer class transforms OdGiRasterImage objects to Bitonal images.
 
    Library: TD_Gi
 
    \remarks
    Transforming an image does not effect the orignal.
 
    <group OdGi_Classes>
*/
class ODGI_EXPORT OdGiBitonalRasterTransformer : public OdGiRasterImageWrapper
{
  RGBQUAD m_palette[2];
  int m_transpColor;
public:
  OdGiBitonalRasterTransformer();
  virtual ~OdGiBitonalRasterTransformer();
 
  /** \param foregroundColor [in]  Foreground color.
    \param backgroundColor [in]  Background color.
    \param transparent [in]  Image is transparent if and only if true.
  */
  void setOriginal(const OdGiRasterImage* pOrig, ODCOLORREF foregroundColor, ODCOLORREF backgroundColor, bool transparent);
  OdUInt32 numColors() const;
  ODCOLORREF color(OdUInt32 colorIndex) const;
  OdUInt32 paletteDataSize() const;
  void paletteData(OdUInt8* bytes) const;
  PixelFormatInfo pixelFormat() const;
  int transparentColor() const;
 
  OdRxObjectPtr clone() const;
  void copyFrom(const OdRxObject *pSource);
};
 
/** \details
    This raster image transformer class mirrors image upside down.
 
    Library: TD_Gi
 
    \remarks
    Transforming an image does not effect the orignal.
 
    <group OdGi_Classes>
*/
class ODGI_EXPORT OdGiUpsideDownRasterTransformer : public OdGiRasterImageWrapper
{
public:
  OdGiUpsideDownRasterTransformer();
  virtual ~OdGiUpsideDownRasterTransformer();
 
  void scanLines(OdUInt8* scnLines, OdUInt32 firstScanline, OdUInt32 numLines = 1) const;
  const OdUInt8* scanLines() const;
 
  OdRxObjectPtr clone() const;
  void copyFrom(const OdRxObject *pSource);
};
 
/** \details
    This raster image transformer class mirrors image right to left.
 
    Library: TD_Gi
 
    \remarks
    Transforming an image does not effect the orignal.
 
    <group OdGi_Classes>
*/
class ODGI_EXPORT OdGiLeftToRightRasterTransformer : public OdGiRasterImageWrapper
{
public:
  OdGiLeftToRightRasterTransformer();
  virtual ~OdGiLeftToRightRasterTransformer();
 
  void scanLines(OdUInt8* scnLines, OdUInt32 firstScanline, OdUInt32 numLines = 1) const;
  const OdUInt8* scanLines() const;
 
  OdRxObjectPtr clone() const;
  void copyFrom(const OdRxObject *pSource);
};
 
/** \details
    This raster image transformer class negates image colors.
 
    Library: TD_Gi
 
    \remarks
    Transforming an image does not effect the orignal.
 
    <group OdGi_Classes>
*/
class ODGI_EXPORT OdGiInversionRasterTransformer : public OdGiRasterImageWrapper
{
public:
  OdGiInversionRasterTransformer();
  virtual ~OdGiInversionRasterTransformer();
 
  ODCOLORREF color(OdUInt32 colorIndex) const;
  void paletteData(OdUInt8* bytes) const;
 
  void scanLines(OdUInt8* scnLines, OdUInt32 firstScanline, OdUInt32 numLines = 1) const;
  const OdUInt8* scanLines() const;
 
  OdRxObjectPtr clone() const;
  void copyFrom(const OdRxObject *pSource);
protected:
  virtual ODCOLORREF colorXform(ODCOLORREF color) const;
};
 
/** \details
    This raster image transformer class converts image colors into grayscale.
 
    Library: TD_Gi
 
    \remarks
    Transforming an image does not effect the orignal.
 
    <group OdGi_Classes>
*/
class ODGI_EXPORT OdGiGrayscaleRasterTransformer : public OdGiInversionRasterTransformer
{
public:
  OdGiGrayscaleRasterTransformer();
  virtual ~OdGiGrayscaleRasterTransformer();
 
  OdRxObjectPtr clone() const;
  void copyFrom(const OdRxObject *pSource);
protected:
  virtual ODCOLORREF colorXform(ODCOLORREF color) const;
};
 
/** \details
    This raster image transformer class converts image colors into monochrome.
 
    Library: TD_Gi
 
    \remarks
    Transforming an image does not effect the orignal.
 
    <group OdGi_Classes>
*/
class ODGI_EXPORT OdGiMonochromaticRasterTransformer : public OdGiGrayscaleRasterTransformer
{
  int m_threshold;
public:
  OdGiMonochromaticRasterTransformer();
  virtual ~OdGiMonochromaticRasterTransformer();
 
  OdRxObjectPtr clone() const;
  void copyFrom(const OdRxObject *pSource);
 
  void setThreshold(OdUInt8 treshold) { m_threshold = treshold; if (m_threshold > 254) m_threshold = 254; };
  int threshold() const { return m_threshold; }
protected:
  virtual ODCOLORREF colorXform(ODCOLORREF color) const;
};
 
#include "TD_PackPop.h"
 
#endif //  __OD_GI_RASTER_WRAPPERS__