MCPcopy Create free account
hub / github.com/DISTRHO/Cardinal / Window__downscaleBitmap

Function Window__downscaleBitmap

src/override/Window.cpp:554–583  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

552
553#ifdef STBI_WRITE_NO_STDIO
554static void Window__downscaleBitmap(uint8_t* pixels, int& width, int& height) {
555 int targetWidth = width;
556 int targetHeight = height;
557 double scale = 1.0;
558
559 if (targetWidth > 340) {
560 scale = width / 340.0;
561 targetWidth = 340;
562 targetHeight = height / scale;
563 }
564 if (targetHeight > 210) {
565 scale = height / 210.0;
566 targetHeight = 210;
567 targetWidth = width / scale;
568 }
569 DISTRHO_SAFE_ASSERT_INT_RETURN(targetWidth <= 340, targetWidth,);
570 DISTRHO_SAFE_ASSERT_INT_RETURN(targetHeight <= 210, targetHeight,);
571
572 // FIXME worst possible quality :/
573 for (int y = 0; y < targetHeight; ++y) {
574 const int ys = static_cast<int>(y * scale);
575 for (int x = 0; x < targetWidth; ++x) {
576 const int xs = static_cast<int>(x * scale);
577 std::memmove(pixels + (width * y + x) * 3, pixels + (width * ys + xs) * 3, 3);
578 }
579 }
580
581 width = targetWidth;
582 height = targetHeight;
583}
584
585static void Window__writeImagePNG(void* context, void* data, int size) {
586 USE_NAMESPACE_DISTRHO

Callers 1

Window.cppFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected