rawbmp.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/rawbmp.h
  3. // Purpose: macros for fast, raw bitmap data access
  4. // Author: Eric Kidd, Vadim Zeitlin
  5. // Modified by:
  6. // Created: 10.03.03
  7. // Copyright: (c) 2002 Vadim Zeitlin <vadim@wxwidgets.org>
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_RAWBMP_H_
  11. #define _WX_RAWBMP_H_
  12. #include "wx/defs.h"
  13. #ifdef wxHAS_RAW_BITMAP
  14. #include "wx/image.h"
  15. #include "wx/bitmap.h"
  16. // ----------------------------------------------------------------------------
  17. // Abstract Pixel API
  18. //
  19. // We need to access our raw bitmap data (1) portably and (2) efficiently.
  20. // We do this using a two-dimensional "iteration" interface. Performance
  21. // is extremely important here: these functions will be called hundreds
  22. // of thousands of times in a row, and even small inefficiencies will
  23. // make applications seem slow.
  24. //
  25. // We can't always rely on inline functions, because not all compilers actually
  26. // bother to inline them unless we crank the optimization levels way up.
  27. // Therefore, we also provide macros to wring maximum speed out of compiler
  28. // unconditionally (e.g. even in debug builds). Of course, if the performance
  29. // isn't absolutely crucial for you you shouldn't be using them but the inline
  30. // functions instead.
  31. // ----------------------------------------------------------------------------
  32. /*
  33. Usage example:
  34. typedef wxPixelData<wxBitmap, wxNativePixelFormat> PixelData;
  35. wxBitmap bmp;
  36. PixelData data(bmp);
  37. if ( !data )
  38. {
  39. ... raw access to bitmap data unavailable, do something else ...
  40. return;
  41. }
  42. if ( data.GetWidth() < 20 || data.GetHeight() < 20 )
  43. {
  44. ... complain: the bitmap it too small ...
  45. return;
  46. }
  47. PixelData::Iterator p(data);
  48. // we draw a (10, 10)-(20, 20) rect manually using the given r, g, b
  49. p.Offset(data, 10, 10);
  50. for ( int y = 0; y < 10; ++y )
  51. {
  52. PixelData::Iterator rowStart = p;
  53. for ( int x = 0; x < 10; ++x, ++p )
  54. {
  55. p.Red() = r;
  56. p.Green() = g;
  57. p.Blue() = b;
  58. }
  59. p = rowStart;
  60. p.OffsetY(data, 1);
  61. }
  62. */
  63. /*
  64. Note: we do not use WXDLLIMPEXP_CORE with classes in this file because VC++ has
  65. problems with exporting inner class defined inside a specialization of a
  66. template class from a DLL. Besides, as all the methods are inline it's not
  67. really necessary to put them in DLL at all.
  68. */
  69. // ----------------------------------------------------------------------------
  70. // wxPixelFormat
  71. // ----------------------------------------------------------------------------
  72. /*
  73. wxPixelFormat is a template class describing the bitmap data format. It
  74. contains the constants describing the format of pixel data, but does not
  75. describe how the entire bitmap is stored (i.e. top-to-bottom,
  76. bottom-to-top, ...). It is also a "traits"-like class, i.e. it only
  77. contains some constants and maybe static methods but nothing more, so it
  78. can be safely used without incurring any overhead as all accesses to it are
  79. done at compile-time.
  80. Current limitations: we don't support RAGABA and ARAGAB formats supported
  81. by Mac OS X. If there is sufficient interest, these classes could be
  82. extended to deal with them. Neither do we support alpha channel having
  83. different representation from the RGB ones (happens under QNX/Photon I
  84. think), but again this could be achieved with some small extra effort.
  85. Template parameters are:
  86. - type of a single pixel component
  87. - size of the single pixel in bits
  88. - indices of red, green and blue pixel components inside the pixel
  89. - index of the alpha component or -1 if none
  90. - type which can contain the full pixel value (all channels)
  91. */
  92. template <class Channel,
  93. size_t Bpp, int R, int G, int B, int A = -1,
  94. class Pixel = wxUint32>
  95. struct wxPixelFormat
  96. {
  97. // iterator over pixels is usually of type "ChannelType *"
  98. typedef Channel ChannelType;
  99. // the type which may hold the entire pixel value
  100. typedef Pixel PixelType;
  101. // NB: using static ints initialized inside the class declaration is not
  102. // portable as it doesn't work with VC++ 6, so we must use enums
  103. // size of one pixel in bits
  104. enum { BitsPerPixel = Bpp };
  105. // size of one pixel in ChannelType units (usually bytes)
  106. enum { SizePixel = Bpp / (8 * sizeof(Channel)) };
  107. // the channels indices inside the pixel
  108. enum
  109. {
  110. RED = R,
  111. GREEN = G,
  112. BLUE = B,
  113. ALPHA = A
  114. };
  115. // true if we have an alpha channel (together with the other channels, this
  116. // doesn't cover the case of wxImage which stores alpha separately)
  117. enum { HasAlpha = A != -1 };
  118. };
  119. // some "predefined" pixel formats
  120. // -------------------------------
  121. // wxImage format is common to all platforms
  122. typedef wxPixelFormat<unsigned char, 24, 0, 1, 2> wxImagePixelFormat;
  123. // the (most common) native bitmap format without alpha support
  124. #if defined(__WXMSW__)
  125. // under MSW the RGB components are reversed, they're in BGR order
  126. typedef wxPixelFormat<unsigned char, 24, 2, 1, 0> wxNativePixelFormat;
  127. #define wxPIXEL_FORMAT_ALPHA 3
  128. #elif defined(__WXMAC__)
  129. // under Mac, first component is unused but still present, hence we use
  130. // 32bpp, not 24
  131. typedef wxPixelFormat<unsigned char, 32, 1, 2, 3> wxNativePixelFormat;
  132. #define wxPIXEL_FORMAT_ALPHA 0
  133. #elif defined(__WXCOCOA__)
  134. // Cocoa is standard RGB or RGBA (normally it is RGBA)
  135. typedef wxPixelFormat<unsigned char, 24, 0, 1, 2> wxNativePixelFormat;
  136. #define wxPIXEL_FORMAT_ALPHA 3
  137. #elif defined(__WXGTK__)
  138. // Under GTK+ 2.X we use GdkPixbuf, which is standard RGB or RGBA
  139. typedef wxPixelFormat<unsigned char, 24, 0, 1, 2> wxNativePixelFormat;
  140. #define wxPIXEL_FORMAT_ALPHA 3
  141. #elif defined(__WXPM__)
  142. // Under PM, we can use standard RGB or RGBA
  143. typedef wxPixelFormat<unsigned char, 24, 0, 1, 2> wxNativePixelFormat;
  144. #define wxPIXEL_FORMAT_ALPHA 3
  145. #elif defined(__WXDFB__)
  146. // Under DirectFB, RGB components are reversed, they're in BGR order
  147. typedef wxPixelFormat<unsigned char, 24, 2, 1, 0> wxNativePixelFormat;
  148. #define wxPIXEL_FORMAT_ALPHA 3
  149. #endif
  150. // the (most common) native format for bitmaps with alpha channel
  151. #ifdef wxPIXEL_FORMAT_ALPHA
  152. typedef wxPixelFormat<unsigned char, 32,
  153. wxNativePixelFormat::RED,
  154. wxNativePixelFormat::GREEN,
  155. wxNativePixelFormat::BLUE,
  156. wxPIXEL_FORMAT_ALPHA> wxAlphaPixelFormat;
  157. #endif // wxPIXEL_FORMAT_ALPHA
  158. // we also define the (default/best) pixel format for the given class: this is
  159. // used as default value for the pixel format in wxPixelIterator template
  160. template <class T> struct wxPixelFormatFor;
  161. #if wxUSE_IMAGE
  162. // wxPixelFormatFor is only defined for wxImage, attempt to use it with other
  163. // classes (wxBitmap...) will result in compile errors which is exactly what we
  164. // want
  165. template <>
  166. struct wxPixelFormatFor<wxImage>
  167. {
  168. typedef wxImagePixelFormat Format;
  169. };
  170. #endif //wxUSE_IMAGE
  171. // ----------------------------------------------------------------------------
  172. // wxPixelData
  173. // ----------------------------------------------------------------------------
  174. /*
  175. wxPixelDataBase is just a helper for wxPixelData: it contains things common
  176. to both wxImage and wxBitmap specializations.
  177. */
  178. class wxPixelDataBase
  179. {
  180. public:
  181. // origin of the rectangular region we represent
  182. wxPoint GetOrigin() const { return m_ptOrigin; }
  183. // width and height of the region we represent
  184. int GetWidth() const { return m_width; }
  185. int GetHeight() const { return m_height; }
  186. wxSize GetSize() const { return wxSize(m_width, m_height); }
  187. // the distance between two rows
  188. int GetRowStride() const { return m_stride; }
  189. // private: -- see comment in the beginning of the file
  190. // the origin of this image inside the bigger bitmap (usually (0, 0))
  191. wxPoint m_ptOrigin;
  192. // the size of the image we address, in pixels
  193. int m_width,
  194. m_height;
  195. // this parameter is the offset of the start of the (N+1)st row from the
  196. // Nth one and can be different from m_bypp*width in some cases:
  197. // a) the most usual one is to force 32/64 bit alignment of rows
  198. // b) another one is for bottom-to-top images where it's negative
  199. // c) finally, it could conceivably be 0 for the images with all
  200. // lines being identical
  201. int m_stride;
  202. protected:
  203. // ctor is protected because this class is only meant to be used as the
  204. // base class by wxPixelData
  205. wxPixelDataBase()
  206. {
  207. m_width =
  208. m_height =
  209. m_stride = 0;
  210. }
  211. };
  212. /*
  213. wxPixelData represents the entire bitmap data, i.e. unlike
  214. wxPixelFormat (which it uses) it also stores the global bitmap
  215. characteristics such as its size, inter-row separation and so on.
  216. Because of this it can be used to move the pixel iterators (which don't
  217. have enough information about the bitmap themselves). This may seem a bit
  218. unnatural but must be done in this way to keep the iterator objects as
  219. small as possible for maximum efficiency as otherwise they wouldn't be put
  220. into the CPU registers by the compiler any more.
  221. Implementation note: we use the standard workaround for lack of partial
  222. template specialization support in VC (both 6 and 7): instead of partly
  223. specializing the class Foo<T, U> for some T we introduce FooOut<T> and
  224. FooIn<U> nested in it, make Foo<T, U> equivalent to FooOut<T>::FooIn<U> and
  225. fully specialize FooOut.
  226. Also note that this class doesn't have any default definition because we
  227. can't really do anything without knowing the exact image class. We do
  228. provide wxPixelDataBase to make it simpler to write new wxPixelData
  229. specializations.
  230. */
  231. // we need to define this skeleton template to mollify VC++
  232. template <class Image>
  233. struct wxPixelDataOut
  234. {
  235. template <class PixelFormat>
  236. class wxPixelDataIn
  237. {
  238. public:
  239. class Iterator { };
  240. };
  241. };
  242. #if wxUSE_IMAGE
  243. // wxPixelData specialization for wxImage: this is the simplest case as we
  244. // don't have to care about different pixel formats here
  245. template <>
  246. struct wxPixelDataOut<wxImage>
  247. {
  248. // NB: this is a template class even though it doesn't use its template
  249. // parameter because otherwise wxPixelData couldn't compile
  250. template <class dummyPixelFormat>
  251. class wxPixelDataIn : public wxPixelDataBase
  252. {
  253. public:
  254. // the type of the class we're working with
  255. typedef wxImage ImageType;
  256. // the iterator which should be used for working with data in this
  257. // format
  258. class Iterator
  259. {
  260. public:
  261. // the pixel format we use
  262. typedef wxImagePixelFormat PixelFormat;
  263. // the pixel data we're working with
  264. typedef
  265. wxPixelDataOut<wxImage>::wxPixelDataIn<PixelFormat> PixelData;
  266. // go back to (0, 0)
  267. void Reset(const PixelData& data)
  268. {
  269. *this = data.GetPixels();
  270. }
  271. // creates the iterator pointing to the beginning of data
  272. Iterator(PixelData& data)
  273. {
  274. Reset(data);
  275. }
  276. // creates the iterator initially pointing to the image origin
  277. Iterator(const wxImage& image)
  278. {
  279. m_pRGB = image.GetData();
  280. if ( image.HasAlpha() )
  281. {
  282. m_pAlpha = image.GetAlpha();
  283. }
  284. else // alpha is not used at all
  285. {
  286. m_pAlpha = NULL;
  287. }
  288. }
  289. // true if the iterator is valid
  290. bool IsOk() const { return m_pRGB != NULL; }
  291. // navigation
  292. // ----------
  293. // advance the iterator to the next pixel, prefix version
  294. Iterator& operator++()
  295. {
  296. m_pRGB += PixelFormat::SizePixel;
  297. if ( m_pAlpha )
  298. ++m_pAlpha;
  299. return *this;
  300. }
  301. // postfix (hence less efficient -- don't use it unless you
  302. // absolutely must) version
  303. Iterator operator++(int)
  304. {
  305. Iterator p(*this);
  306. ++*this;
  307. return p;
  308. }
  309. // move x pixels to the right and y down
  310. //
  311. // note that the rows don't wrap!
  312. void Offset(const PixelData& data, int x, int y)
  313. {
  314. m_pRGB += data.GetRowStride()*y + PixelFormat::SizePixel*x;
  315. if ( m_pAlpha )
  316. m_pAlpha += data.GetWidth() + x;
  317. }
  318. // move x pixels to the right (again, no row wrapping)
  319. void OffsetX(const PixelData& WXUNUSED(data), int x)
  320. {
  321. m_pRGB += PixelFormat::SizePixel*x;
  322. if ( m_pAlpha )
  323. m_pAlpha += x;
  324. }
  325. // move y rows to the bottom
  326. void OffsetY(const PixelData& data, int y)
  327. {
  328. m_pRGB += data.GetRowStride()*y;
  329. if ( m_pAlpha )
  330. m_pAlpha += data.GetWidth();
  331. }
  332. // go to the given position
  333. void MoveTo(const PixelData& data, int x, int y)
  334. {
  335. Reset(data);
  336. Offset(data, x, y);
  337. }
  338. // data access
  339. // -----------
  340. // access to individual colour components
  341. PixelFormat::ChannelType& Red() { return m_pRGB[PixelFormat::RED]; }
  342. PixelFormat::ChannelType& Green() { return m_pRGB[PixelFormat::GREEN]; }
  343. PixelFormat::ChannelType& Blue() { return m_pRGB[PixelFormat::BLUE]; }
  344. PixelFormat::ChannelType& Alpha() { return *m_pAlpha; }
  345. // address the pixel contents directly (always RGB, without alpha)
  346. //
  347. // this can't be used to modify the image as assigning a 32bpp
  348. // value to 24bpp pixel would overwrite an extra byte in the next
  349. // pixel or beyond the end of image
  350. const typename PixelFormat::PixelType& Data()
  351. { return *(typename PixelFormat::PixelType *)m_pRGB; }
  352. // private: -- see comment in the beginning of the file
  353. // pointer into RGB buffer
  354. unsigned char *m_pRGB;
  355. // pointer into alpha buffer or NULL if alpha isn't used
  356. unsigned char *m_pAlpha;
  357. };
  358. // initializes us with the data of the given image
  359. wxPixelDataIn(ImageType& image) : m_image(image), m_pixels(image)
  360. {
  361. m_width = image.GetWidth();
  362. m_height = image.GetHeight();
  363. m_stride = Iterator::PixelFormat::SizePixel * m_width;
  364. }
  365. // initializes us with the given region of the specified image
  366. wxPixelDataIn(ImageType& image,
  367. const wxPoint& pt,
  368. const wxSize& sz) : m_image(image), m_pixels(image)
  369. {
  370. m_stride = Iterator::PixelFormat::SizePixel * m_width;
  371. InitRect(pt, sz);
  372. }
  373. // initializes us with the given region of the specified image
  374. wxPixelDataIn(ImageType& image,
  375. const wxRect& rect) : m_image(image), m_pixels(image)
  376. {
  377. m_stride = Iterator::PixelFormat::SizePixel * m_width;
  378. InitRect(rect.GetPosition(), rect.GetSize());
  379. }
  380. // we evaluate to true only if we could get access to bitmap data
  381. // successfully
  382. operator bool() const { return m_pixels.IsOk(); }
  383. // get the iterator pointing to the origin
  384. Iterator GetPixels() const { return m_pixels; }
  385. private:
  386. void InitRect(const wxPoint& pt, const wxSize& sz)
  387. {
  388. m_width = sz.x;
  389. m_height = sz.y;
  390. m_ptOrigin = pt;
  391. m_pixels.Offset(*this, pt.x, pt.y);
  392. }
  393. // the image we're working with
  394. ImageType& m_image;
  395. // the iterator pointing to the image origin
  396. Iterator m_pixels;
  397. };
  398. };
  399. #endif //wxUSE_IMAGE
  400. #if wxUSE_GUI
  401. // wxPixelData specialization for wxBitmap: here things are more interesting as
  402. // we also have to support different pixel formats
  403. template <>
  404. struct wxPixelDataOut<wxBitmap>
  405. {
  406. template <class Format>
  407. class wxPixelDataIn : public wxPixelDataBase
  408. {
  409. public:
  410. // the type of the class we're working with
  411. typedef wxBitmap ImageType;
  412. class Iterator
  413. {
  414. public:
  415. // the pixel format we use
  416. typedef Format PixelFormat;
  417. // the type of the pixel components
  418. typedef typename PixelFormat::ChannelType ChannelType;
  419. // the pixel data we're working with
  420. typedef wxPixelDataOut<wxBitmap>::wxPixelDataIn<Format> PixelData;
  421. // go back to (0, 0)
  422. void Reset(const PixelData& data)
  423. {
  424. *this = data.GetPixels();
  425. }
  426. // initializes the iterator to point to the origin of the given
  427. // pixel data
  428. Iterator(PixelData& data)
  429. {
  430. Reset(data);
  431. }
  432. // initializes the iterator to point to the origin of the given
  433. // bitmap
  434. Iterator(wxBitmap& bmp, PixelData& data)
  435. {
  436. // using cast here is ugly but it should be safe as
  437. // GetRawData() real return type should be consistent with
  438. // BitsPerPixel (which is in turn defined by ChannelType) and
  439. // this is the only thing we can do without making GetRawData()
  440. // a template function which is undesirable
  441. m_ptr = (ChannelType *)
  442. bmp.GetRawData(data, PixelFormat::BitsPerPixel);
  443. }
  444. // default constructor
  445. Iterator()
  446. {
  447. m_ptr = NULL;
  448. }
  449. // return true if this iterator is valid
  450. bool IsOk() const { return m_ptr != NULL; }
  451. // navigation
  452. // ----------
  453. // advance the iterator to the next pixel, prefix version
  454. Iterator& operator++()
  455. {
  456. m_ptr += PixelFormat::SizePixel;
  457. return *this;
  458. }
  459. // postfix (hence less efficient -- don't use it unless you
  460. // absolutely must) version
  461. Iterator operator++(int)
  462. {
  463. Iterator p(*this);
  464. ++*this;
  465. return p;
  466. }
  467. // move x pixels to the right and y down
  468. //
  469. // note that the rows don't wrap!
  470. void Offset(const PixelData& data, int x, int y)
  471. {
  472. m_ptr += data.GetRowStride()*y + PixelFormat::SizePixel*x;
  473. }
  474. // move x pixels to the right (again, no row wrapping)
  475. void OffsetX(const PixelData& WXUNUSED(data), int x)
  476. {
  477. m_ptr += PixelFormat::SizePixel*x;
  478. }
  479. // move y rows to the bottom
  480. void OffsetY(const PixelData& data, int y)
  481. {
  482. m_ptr += data.GetRowStride()*y;
  483. }
  484. // go to the given position
  485. void MoveTo(const PixelData& data, int x, int y)
  486. {
  487. Reset(data);
  488. Offset(data, x, y);
  489. }
  490. // data access
  491. // -----------
  492. // access to individual colour components
  493. ChannelType& Red() { return m_ptr[PixelFormat::RED]; }
  494. ChannelType& Green() { return m_ptr[PixelFormat::GREEN]; }
  495. ChannelType& Blue() { return m_ptr[PixelFormat::BLUE]; }
  496. ChannelType& Alpha() { return m_ptr[PixelFormat::ALPHA]; }
  497. // address the pixel contents directly
  498. //
  499. // warning: the format is platform dependent
  500. //
  501. // warning 2: assigning to Data() only works correctly for 16bpp or
  502. // 32bpp formats but using it for 24bpp ones overwrites
  503. // one extra byte and so can't be done
  504. typename PixelFormat::PixelType& Data()
  505. { return *(typename PixelFormat::PixelType *)m_ptr; }
  506. // private: -- see comment in the beginning of the file
  507. // for efficiency reasons this class should not have any other
  508. // fields, otherwise it won't be put into a CPU register (as it
  509. // should inside the inner loops) by some compilers, notably gcc
  510. ChannelType *m_ptr;
  511. };
  512. // ctor associates this pointer with a bitmap and locks the bitmap for
  513. // raw access, it will be unlocked only by our dtor and so these
  514. // objects should normally be only created on the stack, i.e. have
  515. // limited life-time
  516. wxPixelDataIn(wxBitmap& bmp) : m_bmp(bmp), m_pixels(bmp, *this)
  517. {
  518. }
  519. wxPixelDataIn(wxBitmap& bmp, const wxRect& rect)
  520. : m_bmp(bmp), m_pixels(bmp, *this)
  521. {
  522. InitRect(rect.GetPosition(), rect.GetSize());
  523. }
  524. wxPixelDataIn(wxBitmap& bmp, const wxPoint& pt, const wxSize& sz)
  525. : m_bmp(bmp), m_pixels(bmp, *this)
  526. {
  527. InitRect(pt, sz);
  528. }
  529. // we evaluate to true only if we could get access to bitmap data
  530. // successfully
  531. operator bool() const { return m_pixels.IsOk(); }
  532. // get the iterator pointing to the origin
  533. Iterator GetPixels() const { return m_pixels; }
  534. // dtor unlocks the bitmap
  535. ~wxPixelDataIn()
  536. {
  537. if ( m_pixels.IsOk() )
  538. {
  539. #if defined(__WXMSW__) || defined(__WXMAC__)
  540. // this is a hack to mark wxBitmap as using alpha channel
  541. if ( Format::HasAlpha )
  542. m_bmp.UseAlpha();
  543. #endif
  544. m_bmp.UngetRawData(*this);
  545. }
  546. // else: don't call UngetRawData() if GetRawData() failed
  547. }
  548. #if WXWIN_COMPATIBILITY_2_8
  549. // not needed anymore, calls to it should be simply removed
  550. wxDEPRECATED_INLINE( void UseAlpha(), wxEMPTY_PARAMETER_VALUE )
  551. #endif
  552. // private: -- see comment in the beginning of the file
  553. // the bitmap we're associated with
  554. wxBitmap m_bmp;
  555. // the iterator pointing to the image origin
  556. Iterator m_pixels;
  557. private:
  558. void InitRect(const wxPoint& pt, const wxSize& sz)
  559. {
  560. m_pixels.Offset(*this, pt.x, pt.y);
  561. m_ptOrigin = pt;
  562. m_width = sz.x;
  563. m_height = sz.y;
  564. }
  565. };
  566. };
  567. #endif //wxUSE_GUI
  568. // FIXME-VC6: VC6 doesn't like typename in default template parameters while
  569. // it is necessary with standard-conforming compilers, remove this
  570. // #define and just use typename when we drop VC6 support
  571. #if defined(__VISUALC__) && !wxCHECK_VISUALC_VERSION(7)
  572. #define wxTYPENAME_IN_TEMPLATE_DEFAULT_PARAM
  573. #else
  574. #define wxTYPENAME_IN_TEMPLATE_DEFAULT_PARAM typename
  575. #endif
  576. template <class Image,
  577. class PixelFormat = wxTYPENAME_IN_TEMPLATE_DEFAULT_PARAM
  578. wxPixelFormatFor<Image>::Format >
  579. class wxPixelData :
  580. public wxPixelDataOut<Image>::template wxPixelDataIn<PixelFormat>
  581. {
  582. public:
  583. typedef
  584. typename wxPixelDataOut<Image>::template wxPixelDataIn<PixelFormat>
  585. Base;
  586. wxPixelData(Image& image) : Base(image) { }
  587. wxPixelData(Image& i, const wxRect& rect) : Base(i, rect) { }
  588. wxPixelData(Image& i, const wxPoint& pt, const wxSize& sz)
  589. : Base(i, pt, sz)
  590. {
  591. }
  592. };
  593. // some "predefined" pixel data classes
  594. #if wxUSE_IMAGE
  595. typedef wxPixelData<wxImage> wxImagePixelData;
  596. #endif //wxUSE_IMAGE
  597. #if wxUSE_GUI
  598. typedef wxPixelData<wxBitmap, wxNativePixelFormat> wxNativePixelData;
  599. typedef wxPixelData<wxBitmap, wxAlphaPixelFormat> wxAlphaPixelData;
  600. #endif //wxUSE_GUI
  601. // ----------------------------------------------------------------------------
  602. // wxPixelIterator
  603. // ----------------------------------------------------------------------------
  604. /*
  605. wxPixel::Iterator represents something which points to the pixel data and
  606. allows us to iterate over it. In the simplest case of wxBitmap it is,
  607. indeed, just a pointer, but it can be something more complicated and,
  608. moreover, you are free to specialize it for other image classes and bitmap
  609. formats.
  610. Note that although it would have been much more intuitive to have a real
  611. class here instead of what we have now, this class would need two template
  612. parameters, and this can't be done because we'd need compiler support for
  613. partial template specialization then and neither VC6 nor VC7 provide it.
  614. */
  615. template < class Image, class PixelFormat = wxPixelFormatFor<Image> >
  616. struct wxPixelIterator : public wxPixelData<Image, PixelFormat>::Iterator
  617. {
  618. };
  619. #endif // wxHAS_RAW_BITMAP
  620. #endif // _WX_RAWBMP_H_