const GraphicsContext& context
| 509 | |
| 510 | // const GraphicsContext& context |
| 511 | void CairoImage::loadFromPNG(const char* const pngData, const uint pngSize) noexcept |
| 512 | { |
| 513 | struct PngReaderData |
| 514 | { |
| 515 | const char* dataPtr; |
| 516 | uint sizeLeft; |
| 517 | |
| 518 | static cairo_status_t read(void* const closure, uchar* const data, const uint length) noexcept |
| 519 | { |
| 520 | PngReaderData& readerData = *reinterpret_cast<PngReaderData*>(closure); |
| 521 | |
| 522 | if (readerData.sizeLeft < length) |
| 523 | return CAIRO_STATUS_READ_ERROR; |
| 524 | |
| 525 | std::memcpy(data, readerData.dataPtr, length); |
| 526 | readerData.dataPtr += length; |
| 527 | readerData.sizeLeft -= length; |
| 528 | return CAIRO_STATUS_SUCCESS; |
| 529 | } |
| 530 | }; |
| 531 | |
| 532 | PngReaderData readerData; |
| 533 | readerData.dataPtr = pngData; |
| 534 | readerData.sizeLeft = pngSize; |
| 535 | |
| 536 | cairo_surface_t* const newsurface = cairo_image_surface_create_from_png_stream(PngReaderData::read, &readerData); |
| 537 | DISTRHO_SAFE_ASSERT_RETURN(newsurface != nullptr,); |
| 538 | |
| 539 | const int newwidth = cairo_image_surface_get_width(newsurface); |
| 540 | const int newheight = cairo_image_surface_get_height(newsurface); |
| 541 | DISTRHO_SAFE_ASSERT_INT_RETURN(newwidth > 0, newwidth,); |
| 542 | DISTRHO_SAFE_ASSERT_INT_RETURN(newheight > 0, newheight,); |
| 543 | |
| 544 | cairo_surface_destroy(surface); |
| 545 | |
| 546 | if (datarefcount != nullptr && --(*datarefcount) == 0) |
| 547 | std::free(surfacedata); |
| 548 | else |
| 549 | datarefcount = static_cast<int*>(malloc(sizeof(*datarefcount))); |
| 550 | |
| 551 | surface = newsurface; |
| 552 | surfacedata = nullptr; // cairo_image_surface_get_data(newsurface); |
| 553 | *datarefcount = 1; |
| 554 | |
| 555 | rawData = nullptr; |
| 556 | format = kImageFormatNull; // asCairoImageFormat(cairo_image_surface_get_format(newsurface)); |
| 557 | size = Size<uint>(static_cast<uint>(newwidth), static_cast<uint>(newheight)); |
| 558 | } |
| 559 | |
| 560 | void CairoImage::drawAt(const GraphicsContext& context, const Point<int>& pos) |
| 561 | { |