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