1
0

bitmap.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //NONPORTABLE
  2. #ifndef _BITMAP_H
  3. #define _BITMAP_H
  4. #pragma warning( disable: 4251 )
  5. // http://www.unknownroad.com/rtfm/VisualStudio/warningC4251.html
  6. #include <tataki/export.h>
  7. #include <bfc/platform/platform.h>
  8. class ifc_canvas; // see canvas.h
  9. //#define NO_MMX
  10. class api_region;
  11. // a skinnable bitmap
  12. class TATAKIAPI SkinBitmap
  13. {
  14. public:
  15. void AddRef();
  16. void Release();
  17. #ifndef _NOSTUDIO
  18. #ifdef _WIN32
  19. SkinBitmap(HINSTANCE hInst, int _id, const wchar_t *colorgroup = NULL); //NONPORTABLE
  20. #endif
  21. SkinBitmap(const wchar_t *elementname, int cached = 1);
  22. #endif
  23. // SkinBitmap(SkinBitmap *source, int w, int h);
  24. SkinBitmap(int w, int h, ARGB32 bgcolor = RGBA(255,255,255,255)); //untested --BU
  25. #ifdef _WIN32
  26. SkinBitmap(HBITMAP bitmap);
  27. SkinBitmap(HBITMAP bitmap, HDC dc, int has_alpha = 0, void *bits = NULL);
  28. #endif
  29. SkinBitmap(ARGB32 *bits, int w, int h, bool own=false); // added by benski, use if you have raw image bits
  30. SkinBitmap(ifc_canvas *canvas);
  31. ~SkinBitmap();
  32. int getWidth() const { return subimage_w == -1 ? fullimage_w : subimage_w; };
  33. int getHeight() const { return subimage_h == -1 ? fullimage_h : subimage_h; };
  34. int getFullWidth() const { return fullimage_w; };
  35. int getFullHeight() const { return fullimage_h; };
  36. int getX() const { return x_offset == -1 ? 0 : x_offset; };
  37. int getY() const { return y_offset == -1 ? 0 : y_offset; };
  38. int getBpp() const { return 32; };
  39. int getAlpha() const { return has_alpha; };
  40. void setHasAlpha(int ha);
  41. virtual void *getBits();
  42. int isInvalid();
  43. const wchar_t *getBitmapName();
  44. void blit(ifc_canvas *canvas, int x, int y);
  45. void blitAlpha(ifc_canvas *canvas, int x, int y, int alpha = 255);
  46. // blits a chunk of source into dest rect
  47. void blitToRect(ifc_canvas *canvas, RECT *src, RECT *dst, int alpha = 255);
  48. void blitTile(ifc_canvas *canvas, RECT *dest, int xoffs = 0, int yoffs = 0, int alpha = 255);
  49. void blitRectToTile(ifc_canvas *canvas, RECT *dest, RECT *src, int xoffs = 0, int yoffs = 0, int alpha = 255);
  50. void stretch(ifc_canvas *canvas, int x, int y, int w, int h);
  51. void stretchToRect(ifc_canvas *canvas, RECT *r);
  52. void stretchRectToRect(ifc_canvas *canvas, RECT *src, RECT *dst);
  53. void stretchToRectAlpha(ifc_canvas *canvas, RECT *r, int alpha = 255);
  54. void stretchToRectAlpha(ifc_canvas *canvas, RECT *src, RECT *dst, int alpha = 255);
  55. ARGB32 getPixel(int x, int y);
  56. private:
  57. #ifdef _WIN32
  58. void bmpToBits(HBITMAP hbmp, HDC defaultDC = NULL);
  59. #endif
  60. int has_alpha;
  61. int x_offset, y_offset, subimage_w, subimage_h, fullimage_w, fullimage_h;
  62. ARGB32 *bits;
  63. int ownbits;
  64. int last_failed;
  65. wchar_t *bitmapname;
  66. int fromskin;
  67. size_t references;
  68. enum
  69. {
  70. OWNBITS_NOTOURS =0 ,
  71. OWNBITS_USEIMGLDR = 1,
  72. OWNBITS_USESTDFREE = 2,
  73. OWNBITS_USECFREE = 3,
  74. OWNBITS_USESYSFREE = 4,
  75. };
  76. protected:
  77. bool high_quality_resampling;
  78. };
  79. #ifndef _NOSTUDIO
  80. class HQSkinBitmap : public SkinBitmap
  81. {
  82. public:
  83. HQSkinBitmap(ARGB32 *bits, int w, int h, bool own=false) : SkinBitmap(bits, w, h, own)
  84. {
  85. high_quality_resampling=true;
  86. }
  87. HQSkinBitmap(const wchar_t *elementname, int cached = 1) : SkinBitmap(elementname, cached)
  88. {
  89. high_quality_resampling=true;
  90. }
  91. #ifdef _WIN32
  92. HQSkinBitmap(HINSTANCE hInst, int _id, const wchar_t *colorgroup = NULL) : SkinBitmap(hInst, _id, colorgroup)
  93. {
  94. high_quality_resampling=true;
  95. }
  96. #endif
  97. };
  98. #endif
  99. #endif