// static ImageArray ImageRoll::SplitH(const wxImage &src, wxColour magicColor) { ImageArray result; int width = src.GetWidth(); int height = src.GetHeight(); unsigned char *data = src.GetData(); unsigned char *ptr = data; unsigned char magicRed = magicColor.Red(); unsigned char magicGreen = magicColor.Green(); unsigned char magicBlue = magicColor.Blue(); bool cur, prev; int i, j, start; // Sanity check... if (width<=0 || height<=0 || data==NULL) return result; prev = false; start = 0; for(i=0; i<width+1; i++) { if (i < width) { unsigned char *ptr2 = ptr; cur = true; for(j=0; j<height && cur; j++) { if (!(ptr2[0] == magicRed && ptr2[1] == magicGreen && ptr2[2] == magicBlue)) cur = false; ptr2 += 3 * width; } } else cur = !prev; if ((cur && !prev)) { wxRect subRect(start, 0, i-start, height); wxImage subImage; if (subRect.width > 0) subImage = src.GetSubImage(subRect); else subImage = wxImage(subRect.width, subRect.height); result.Add(subImage); } else if (!cur && prev) { start = i; } prev = cur; ptr += 3; } return result; }
wxBitmap gcThemeManager::getSprite(wxImage& img, const char* spriteId, const char* spriteName) { SpriteRectI* rect = getSpriteRect(spriteId, spriteName); if (!rect || !img.IsOk()) return wxBitmap(); int w = rect->getW(); int h = rect->getH(); int x = rect->getX(); int y = rect->getY(); if (w < 0) w = img.GetWidth(); if (h < 0) h = img.GetHeight(); if (w > img.GetWidth()) w = img.GetWidth(); if (h > img.GetHeight()) h = img.GetHeight(); if (x < 0) x = 0; if (x > img.GetWidth() - w) x = 0; if (y < 0) y = 0; if (y > img.GetHeight() - h) y = 0; return wxBitmap( img.GetSubImage( wxRect(x,y,w,h) ) ); }