Language: EN

libreria-arduino-image-scaling

Arduino Image Scaling Library

The Image Scaling library contains basic algorithms for scaling images on a microprocessor like Arduino.

Typical uses of the library are, for example, adapting an image to the available screen size. It is also useful for drawing at a lower resolution than the screen, to speed up rendering, and then scaling it.

The available algorithms are as follows:

  • Average. Suitable for reducing, slow processing.
  • Scalar. Suitable for increasing, very fast processing.
  • NearestNeighbor. Suitable for increasing, fast processing.
  • Bilinear. Suitable for increasing, slow processing.

The library is compatible with the TFT_eSPI library natively, or with others through UnifiedGFX.

USAGE


#pragma GCC optimize ("-Ofast")

#include <m5stickcplus.h>
#include <esp_color.h>
#include <image_scaling.h>

const uint8_t origSize = 64;
const uint8_t destSize = 16;

TFT_eSprite Original = TFT_eSprite(&amp;M5.Lcd);
TFT_eSprite Scaled = TFT_eSprite(&amp;M5.Lcd);
TFT_eSprite Final = TFT_eSprite(&amp;M5.Lcd);

void setup() {
  Serial.begin(115200);
  M5.begin();
  M5.Lcd.setRotation(0);

  Original.setColorDepth(16);
  Original.createSprite(origSize, origSize);
  Original.fillScreen(TFT_BLACK);

  auto color = TFT_CYAN;
  const int grid = 6;
  for (auto x = 0; x < grid; x++)
  {
    for (auto y = 0; y < grid; y++)
    {
      Original.fillRect(x * origSize / grid, y * origSize / grid, origSize / grid, origSize / grid, color);
      color = color == TFT_RED ? TFT_CYAN : TFT_RED;
    }
    color = color == TFT_RED ? TFT_CYAN : TFT_RED;
  }

  Scaled.setColorDepth(16);
  Scaled.createSprite(destSize, destSize);
  Scaled.fillScreen(TFT_BLACK);

  Final.setColorDepth(16);
  Final.createSprite(origSize, origSize);
  Final.fillScreen(TFT_BLACK);
}

void Render()
{
  ImageScaling::Average(Original, Scaled);
  ImageScaling::Bilineal(Scaled, Final);

  Original.pushSprite(0, 0);
  Scaled.pushSprite(30, 64 + 10);
  Final.pushSprite(0, 160 - 64);
}

void loop()
{
  M5.update();

  Render();
  delay(500);
}

Installation

  • Download the latest version from GitHub
  • Unzip the file
  • Copy to your libraries folder (usually My Documents\Arduino\libraries)
  • Restart the Arduino IDE

github-full