1 /* 2 * Copyright 2006-2008, Haiku. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _ICON_UTILS_H 6 #define _ICON_UTILS_H 7 8 9 #include <Mime.h> 10 11 class BBitmap; 12 class BNode; 13 14 15 // This class is a little different from many other classes. 16 // You don't create an instance of it; you just call its various 17 // static member functions for utility-like operations. 18 class BIconUtils { 19 BIconUtils(); 20 ~BIconUtils(); 21 BIconUtils(const BIconUtils&); 22 BIconUtils& operator=(const BIconUtils&); 23 24 public: 25 26 // Utility function to import an icon from the node that 27 // has either of the provided attribute names. Which icon type 28 // is preferred (vector, small or large B_CMAP8 icon) depends 29 // on the colorspace of the provided bitmap. If the colorspace 30 // is B_CMAP8, B_CMAP8 icons are preferred. In that case, the 31 // bitmap size must also match the provided icon_size "size"! 32 static status_t GetIcon(BNode* node, 33 const char* vectorIconAttrName, 34 const char* smallIconAttrName, 35 const char* largeIconAttrName, 36 icon_size size, BBitmap* result); 37 38 // Utility functions to import a vector icon in "flat icon" 39 // format from a BNode attribute or from a flat buffer in 40 // memory into the preallocated BBitmap "result". 41 // The colorspace of result needs to be B_RGBA32 or at 42 // least B_RGB32 (though that makes less sense). The icon 43 // will be scaled from it's "native" size of 64x64 to the 44 // size of the bitmap, the scale is derived from the bitmap 45 // width, the bitmap should have square dimension, or the 46 // icon will be cut off at the bottom (or have room left). 47 static status_t GetVectorIcon(BNode* node, 48 const char* attrName, BBitmap* result); 49 50 static status_t GetVectorIcon(const uint8* buffer, 51 size_t size, BBitmap* result); 52 53 // Utility function to import an "old" BeOS icon in B_CMAP8 54 // colorspace from either the small icon attribute or the 55 // large icon attribute as given in "smallIconAttrName" and 56 // "largeIconAttrName". Which icon is loaded depends on 57 // the given "size". 58 static status_t GetCMAP8Icon(BNode* node, 59 const char* smallIconAttrName, 60 const char* largeIconAttrName, 61 icon_size size, BBitmap* icon); 62 63 // Utility functions to convert from old icon colorspace 64 // into colorspace of BBitmap "result" (should be B_RGBA32 65 // to make any sense). 66 static status_t ConvertFromCMAP8(BBitmap* source, 67 BBitmap* result); 68 static status_t ConvertToCMAP8(BBitmap* source, 69 BBitmap* result); 70 71 static status_t ConvertFromCMAP8(const uint8* data, 72 uint32 width, uint32 height, 73 uint32 bytesPerRow, BBitmap* result); 74 75 static status_t ConvertToCMAP8(const uint8* data, 76 uint32 width, uint32 height, 77 uint32 bytesPerRow, BBitmap* result); 78 }; 79 80 #endif // _ICON_UTILS_H 81