| 247 | } |
| 248 | |
| 249 | XImage* XIcon::GetBest(bool night, bool *free) |
| 250 | { |
| 251 | #if 1 |
| 252 | if (ImageSVG) { |
| 253 | NSVGimage* sImage = (NSVGimage*)ImageSVGnight; |
| 254 | if (!night || !ImageSVGnight) sImage = (NSVGimage*)ImageSVG; |
| 255 | float Scale = sImage->scale; |
| 256 | NSVGrasterizer* rast = nsvgCreateRasterizer(); |
| 257 | float Height = sImage->height * Scale; |
| 258 | float Width = sImage->width * Scale; |
| 259 | int iWidth = (int)(Width + 0.5f); |
| 260 | int iHeight = (int)(Height + 0.5f); |
| 261 | XImage* NewImage = new XImage(iWidth, iHeight); //TODO creating new XImage we have to delete it after use |
| 262 | if (sImage->shapes == NULL) { |
| 263 | if (free) *free = true; |
| 264 | return NewImage; |
| 265 | } |
| 266 | float bounds[4]; |
| 267 | nsvg__imageBounds(sImage, bounds); |
| 268 | |
| 269 | float tx = 0.f, ty = 0.f; |
| 270 | float realWidth = (bounds[2] - bounds[0]) * Scale; |
| 271 | float realHeight = (bounds[3] - bounds[1]) * Scale; |
| 272 | tx = (Width - realWidth) * 0.5f; |
| 273 | ty = (Height - realHeight) * 0.5f; |
| 274 | |
| 275 | nsvgRasterize(rast, sImage, tx, ty, Scale, Scale, (UINT8*)NewImage->GetPixelPtr(0,0), iWidth, iHeight, iWidth*4); |
| 276 | nsvgDeleteRasterizer(rast); |
| 277 | // if (night) ImageNight = *NewImage; |
| 278 | // else Image = *NewImage; |
| 279 | // delete NewImage; |
| 280 | if (free) *free = true; |
| 281 | return NewImage; |
| 282 | } |
| 283 | #endif |
| 284 | XImage* RetImage = (night && !ImageNight.isEmpty())? &ImageNight : &Image; |
| 285 | if (free) *free = false; |
| 286 | return RetImage; |
| 287 | } |
| 288 | |
| 289 | |
| 290 |
no test coverage detected