1
0

image.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #ifndef NULLSOFT_ML_IMAGE_HEADER
  2. #define NULLSOFT_ML_IMAGE_HEADER
  3. #include <windows.h>
  4. #define RGBA(r,g,b,a) ((COLORREF)(((BYTE)(r)|((WORD)(g)<<8))|(((DWORD)(BYTE)(b))<<16)|(((DWORD)(BYTE)(a))<<24)))
  5. #define FIXCOLORREF(clr) RGBA(GetBValue(clr),GetGValue(clr), GetRValue(clr),((DWORD)(clr)) >> 24)
  6. // loader function will be called every time MLImage need to
  7. // reload picture. Input parameter - handle to the calling object
  8. // Output - loaded bitmap
  9. typedef HBITMAP (*IMGLOADFUNC)(INT_PTR handle);
  10. class MLImage
  11. {
  12. public:
  13. MLImage(void);
  14. MLImage(IMGLOADFUNC loader, BOOL deleteDone);
  15. MLImage(int width, int height);
  16. ~MLImage(void);
  17. public:
  18. // sets the loader function and returns handle to the class or NULL if error
  19. // loader - pointer to the loader function
  20. // deleteDone - if TRUE MLImage will delete HBITMAP object from loader every time it is done loading
  21. // forceLoad - forcing to load bitamp immedialty by calling Load()
  22. INT_PTR SetLoader(IMGLOADFUNC loader, BOOL deleteDone, BOOL forceLoad);
  23. BOOL Load(void); // load image
  24. MLImage* Init(int width, int height); // init image (allocates memory)
  25. MLImage* Init(int width, int height, COLORREF color); // init image (allocates memory) and set
  26. BOOL Draw(HDC hdcDest, int destX, int destY, int destWidth, int destHeight, int sourceX, int sourceY); // draw image
  27. BOOL Draw(HDC hdcDest, int destX, int destY); // draw image
  28. public:
  29. int GetWidth(void) const;
  30. int GetHeight(void) const;
  31. void* GetData(void) const;
  32. private:
  33. void ResetData(void);
  34. public:
  35. static MLImage* Copy(MLImage* destination, const MLImage* original);// copy all data from the original object (including image data) to the destination
  36. private:
  37. static HBITMAP ConvertTo32BppDIB(HBITMAP bmpHandle, int bmpWidth, int bmpHeight, LPBITMAPINFO bmpInfo, LPVOID *bmpData);
  38. private:
  39. IMGLOADFUNC loader; // pointer to the loader function
  40. BOOL loaderDelete; // TRUE - delete HBITMAP from loader after load
  41. HBITMAP hbmp; // my bitmap
  42. BITMAPINFO info;
  43. void *data;
  44. };
  45. #endif // NULLSOFT_ML_IMAGE_HEADER