pdf-icon

Arduino入門

2. デバイス&サンプル

画像描画

画像

createPng

関数プロトタイプ:

void* createPng( size_t* datalen, int32_t x = 0, int32_t y = 0, int32_t width = 0, int32_t height = 0)

機能説明:

  • スクリーンショット機能で、パネルに表示されているデータをPNG形式でデバイスメモリに保存します。
注意事項:
保存できる画像サイズはメモリ容量によって異なります。例えば、PSRAM機能が無効の場合、高解像度・高色深の画像は保存できません。

引数:

  • datalen:画像データの長さ
  • x:スクリーンショット開始点のx座標
  • y:スクリーンショット開始点のy座標
  • w:スクリーンショットの幅
  • h:スクリーンショットの高さ

戻り値:

  • void*:
    • スクリーンショット成功時:PNG画像データのメモリ領域へのポインタ
    • スクリーンショット失敗時:nullptr

サンプルプログラム:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#include <Arduino.h>
#include <M5GFX.h>
#include <M5Unified.h>

M5GFX display;
size_t png_datalen = 320 * 240;
uint8_t* PngData = (uint8_t*)malloc(png_datalen * sizeof(uint8_t));

void setup() {
    display.begin();
    display.setColorDepth(8);
    display.setRotation(1);
    display.clear(TFT_WHITE);
    display.setTextFont(&fonts::FreeSansOblique12pt7b);
    display.setTextColor(TFT_BLACK);
    delay(1000);
    uint16_t x = display.width() / 2;
    uint16_t y = display.height() / 2;

    display.drawCenterString("Create PNG Test", x, y);
    delay(2000);
    PngData = (uint8_t*)display.createPng(&png_datalen, 0, 0, 320, 240);
    display.drawCenterString("Screenshot successful", x, y+30);
    delay(2000);
    display.clear(TFT_WHITE);
    delay(1000);
    display.drawCenterString("5s later show screenshot", x, y);
    delay(5000);
    display.drawPng(PngData, png_datalen);
}

void loop() {
}

drawBmp

関数プロトタイプ1:

void drawBmp(const uint8_t *data, uint32_t len, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

関数プロトタイプ2:

void drawBmp(DataWrapper *data, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

機能説明:

  • BMP画像を描画/表示します

引数:

  • data:画像データのポインタ
  • const uint8_t:元画像データのポインタ
  • DataWrapper:ラップされた画像データオブジェクトのポインタ(DataWrapperについて
  • len:データ長
  • x:描画開始点のx座標
  • y:描画開始点のy座標
  • maxWidth:画像の最大幅
  • maxHeight:画像の最大高さ
  • offX:x軸オフセット
  • offY:y軸オフセット
  • scale_x:x方向のスケール比
  • scale_y:y方向のスケール比
  • datum:画像の揃え方、デフォルトは左上揃え(datum_tについて

戻り値:

  • null

drawBmpFile

関数プロトタイプ1:

void drawBmpFile(T &fs, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

関数プロトタイプ3:

void drawBmpFile(DataWrapper* file, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

関数プロトタイプ2:

void drawBmpFile(const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

機能説明:

  • BMPファイルからBMP画像を描画/表示します

引数:

  • fs:ファイルシステムオブジェクト
  • SPIFFS
  • SD
    など
  • path:BMPファイルのパス
  • file:DataWrapper構造体のポインタ(DataWrapperについて
  • x:描画開始点のx座標
  • y:描画開始点のy座標
  • maxWidth:画像の最大幅
  • maxHeight:画像の最大高さ
  • offX:x軸オフセット
  • offY:y軸オフセット
  • scale_x:x方向のスケール比
  • scale_y:y方向のスケール比
  • datum:画像の揃え方、デフォルトは左上揃え(datum_tについて

戻り値:

  • null

drawBmpUrl

関数プロトタイプ:

bool drawBmpUrl(const char* url, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 
bool drawBmpUrl(String& url, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

機能説明:

  • リンクからBMP画像を描画/表示します
注意事項:
この機能を使用するには、<M5GFX.h>をインクルードする前に#include <HTTPClient.h>を記述してください。

引数:

  • url:画像リンク
  • x:描画開始点のx座標
  • y:描画開始点のy座標
  • maxWidth:画像の最大幅
  • maxHeight:画像の最大高さ
  • offX:x軸オフセット
  • offY:y軸オフセット
  • scale_x:x方向のスケール比
  • scale_y:y方向のスケール比
  • datum:画像の揃え方、デフォルトは左上揃え

戻り値:

  • bool
  • true:描画/表示成功
  • false:描画/表示失敗

drawJpg

関数プロトタイプ1:

void drawJpg(const uint8_t *data, uint32_t len, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

関数プロトタイプ2:

void drawJpg(DataWrapper *data, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

機能説明:

  • JPG画像を描画/表示します

引数:

  • data
  • const uint8_t:元の定数データポインタ
  • DataWrapper:ラップされたデータオブジェクトのポインタ
  • len:データ長
  • x:描画開始点のx座標
  • y:描画開始点のy座標
  • maxWidth:画像の最大幅
  • maxHeight:画像の最大高さ
  • offX:x軸オフセット
  • offY:y軸オフセット
  • scale_x:x方向のスケール比
  • scale_y:y方向のスケール比
  • datum:画像の揃え方、デフォルトは左上揃え(datum_tについて

戻り値:

  • null

drawJpgFile

関数プロトタイプ1:

void drawJpgFile(T &fs, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

関数プロトタイプ3:

void drawJpgFile(DataWrapper* file, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

関数プロトタイプ2:

void drawJpgFile(const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

機能説明:

  • JPGファイルからJPG画像を描画/表示します

引数:

  • fs:ファイルシステムオブジェクト
  • SPIFFS
  • SD
    など
  • path:JPGファイルのパス
  • file:DataWrapper構造体のポインタ(DataWrapperについて
  • x:描画開始点のx座標
  • y:描画開始点のy座標
  • maxWidth:画像の最大幅
  • maxHeight:画像の最大高さ
  • offX:x軸オフセット
  • offY:y軸オフセット
  • scale_x:x方向のスケール比
  • scale_y:y方向のスケール比
  • datum:画像の揃え方、デフォルトは左上揃え(datum_tについて

戻り値:

  • null

drawJpgUrl

関数プロトタイプ:

bool drawJpgUrl(const char* url, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 
bool drawJpgUrl(String& url, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

機能説明:

  • リンクからJPG画像を描画/表示します
注意事項:
この機能を使用するには、<M5GFX.h>をインクルードする前に#include <HTTPClient.h>を記述してください。

引数:

  • url:画像リンク
  • x:描画開始点のx座標
  • y:描画開始点のy座標
  • maxWidth:画像の最大幅
  • maxHeight:画像の最大高さ
  • offX:x軸オフセット
  • offY:y軸オフセット
  • scale_x:x方向のスケール比
  • scale_y:y方向のスケール比
  • datum:画像の揃え方、デフォルトは左上揃え

戻り値:

  • bool
  • true:描画/表示成功
  • false:描画/表示失敗

drawPng

関数プロトタイプ1:

void drawPng(const uint8_t *data, uint32_t len, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

関数プロトタイプ2:

void drawPng(DataWrapper *data, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

機能説明:

  • PNG画像を描画/表示します

引数:

  • data
  • const uint8_t:元の定数データポインタ
  • DataWrapper:ラップされたデータオブジェクトのポインタ
  • len:データ長
  • x:描画開始点のx座標
  • y:描画開始点のy座標
  • maxWidth:画像の最大幅
  • maxHeight:画像の最大高さ
  • offX:x軸オフセット
  • offY:y軸オフセット
  • scale_x:x方向のスケール比
  • scale_y:y方向のスケール比
  • datum:画像の揃え方、デフォルトは左上揃え(datum_tについて

drawPngFile

関数プロトタイプ1:

void drawPngFile(T &fs, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

関数プロトタイプ3:

void drawPngFile(DataWrapper* file, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

関数プロトタイプ2:

void drawPngFile(const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

機能説明:

  • PNGファイルからPNG画像を描画/表示します

引数:

  • fs:ファイルシステムオブジェクト
  • SPIFFS
  • SD
    など
  • path:PNGファイルのパス
  • file:DataWrapper構造体のポインタ(DataWrapperについて
  • x:描画開始点のx座標
  • y:描画開始点のy座標
  • maxWidth:画像の最大幅
  • maxHeight:画像の最大高さ
  • offX:x軸オフセット
  • offY:y軸オフセット
  • scale_x:x方向のスケール比
  • scale_y:y方向のスケール比
  • datum:画像の揃え方、デフォルトは左上揃え(datum_tについて

戻り値:

  • null

drawPngUrl

関数プロトタイプ:

bool drawPngUrl(const char* url, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 
bool drawPngUrl(String& url, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

機能説明:

  • リンクからPNG画像を描画/表示します
注意事項:
この機能を使用するには、<M5GFX.h>をインクルードする前に#include <HTTPClient.h>を記述してください。

引数:

  • url:画像リンク
  • x:描画開始点のx座標
  • y:描画開始点のy座標
  • maxWidth:画像の最大幅
  • maxHeight:画像の最大高さ
  • offX:x軸オフセット
  • offY:y軸オフセット
  • scale_x:x方向のスケール比
  • scale_y:y方向のスケール比
  • datum:画像の揃え方、デフォルトは左上揃え

戻り値:

  • bool
  • true:描画/表示成功
  • false:描画/表示失敗

drawQoi

関数プロトタイプ1:

void drawQoi(const uint8_t *data, uint32_t len, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

関数プロトタイプ2:

void drawQoi(DataWrapper *data, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

機能説明:

  • Qoi画像を描画/表示します

引数:

  • data
  • const uint8_t:元の定数データポインタ
  • DataWrapper:ラップされたデータオブジェクトのポインタ
  • len:データ長
  • x:描画開始点のx座標
  • y:描画開始点のy座標
  • maxWidth:画像の最大幅
  • maxHeight:画像の最大高さ
  • offX:x軸オフセット
  • offY:y軸オフセット
  • scale_x:x方向のスケール比
  • scale_y:y方向のスケール比
  • datum:画像の揃え方、デフォルトは左上揃え(datum_tについて

戻り値:

  • null

drawQoiFile

関数プロトタイプ1:

void drawQoiFile(T &fs, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

関数プロトタイプ3:

void drawQoiFile(DataWrapper* file, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

関数プロトタイプ2:

void drawQoiFile(const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

機能説明:

  • QoiファイルからQoi画像を描画/表示します

引数:

  • fs:ファイルシステムオブジェクト
  • SPIFFS
  • SD
    など
  • path:Qoiファイルのパス
  • file:DataWrapper構造体のポインタ(DataWrapperについて
  • x:描画開始点のx座標
  • y:描画開始点のy座標
  • maxWidth:画像の最大幅
  • maxHeight:画像の最大高さ
  • offX:x軸オフセット
  • offY:y軸オフセット
  • scale_x:x方向のスケール比
  • scale_y:y方向のスケール比
  • datum:画像の揃え方、デフォルトは左上揃え(datum_tについて

戻り値:

  • null

drawQoiUrl

関数プロトタイプ:

bool drawQoiUrl(const char* url, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 
bool drawQoiUrl(String& url, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

機能説明:

  • リンクからQoi画像を描画/表示します
注意事項:
この機能を使用するには、<M5GFX.h>をインクルードする前に#include <HTTPClient.h>を記述してください。

引数:

  • url:画像リンク
  • x:描画開始点のx座標
  • y:描画開始点のy座標
  • maxWidth:画像の最大幅
  • maxHeight:画像の最大高さ
  • offX:x軸オフセット
  • offY:y軸オフセット
  • scale_x:x方向のスケール比
  • scale_y:y方向のスケール比
  • datum:画像の揃え方、デフォルトは左上揃え

戻り値:

  • bool
  • true:描画/表示成功
  • false:描画/表示失敗
説明:
本サンプルプログラムで使用しているデバイスはM5Core2です。実際に使用するデバイスに応じてSDカード制御ピンを変更してください。

サンプルプログラム:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#include <Arduino.h>
#include <SPI.h>
#include <SD.h>
#include <M5Unified.h>
#include <M5GFX.h>

#define SD_SPI_CS_PIN   4
#define SD_SPI_SCK_PIN  18
#define SD_SPI_MISO_PIN 38
#define SD_SPI_MOSI_PIN 23

void setup() {
  M5.begin();

  M5.Display.setTextFont(&fonts::Orbitron_Light_24);
  M5.Display.setTextSize(1);

  // SDカード初期化
  SPI.begin(SD_SPI_SCK_PIN, SD_SPI_MISO_PIN, SD_SPI_MOSI_PIN, SD_SPI_CS_PIN);
  if (!SD.begin(SD_SPI_CS_PIN, SPI, 25000000)) {
    // SDカードの初期化に失敗した場合やSDカードが存在しない場合はメッセージを表示します。
    M5.Display.print("\n SD card not detected\n");
    while (1)
      ;
  } else {
    M5.Display.print("\n SD card detected\n");
  }
  delay(1000);

  M5.Display.print("\n SD card read test...\n");
  if (SD.open("/TestPicture01.png", FILE_READ, false)) {
    M5.Display.print(" PNG file 01 detected\n");
  } else {
    M5.Display.print(" PNG file 01 not detected\n");
  }
  if (SD.open("/TestPicture02.png", FILE_READ, false)) {
    M5.Display.print(" PNG file 02 detected\n");
  } else {
    M5.Display.print(" PNG file 02 not detected\n");
  }
}

void loop() {
  // 画像ファイルを読み込み、画像を描画
  //         drawBmpFile
  //         drawJpgFile
  //         drawQoiFile
  M5.Display.drawPngFile(SD, "/TestPicture01.png");
  delay(1000);
  M5.Display.drawPngFile(SD, "/TestPicture02.png");
  delay(1000);
}  

このプログラムはSDカード内の2枚のPNG画像をループ再生します。

pushAlphaImage

関数プロトタイプ:

void pushAlphaImage(int32_t x, int32_t y, int32_t w, int32_t h, const T* data)

機能説明:

  • アルファチャンネル付き画像をディスプレイにプッシュします。24ビット以上の画像フォーマットのみ対応。

引数:

  • x:画像左上のx座標
  • y:画像左上のy座標
  • w:画像の幅
  • h:画像の高さ
  • param:pixelcopy_t構造体へのポインタ、画像データやその他パラメータを含む
  • data:画像ピクセルデータへのポインタ

戻り値:

  • null

pushGrayscaleImage

関数プロトタイプ1:

void pushGrayscaleImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint8_t* image, color_depth_t depth, const T& forecolor, const T& backcolor)

機能説明:

  • グレースケール画像をディスプレイにプッシュします

引数:

  • x:画像左上のx座標
  • y:画像左上のy座標
  • w:画像の幅
  • h:画像の高さ
  • image:画像データへのポインタ
  • depth:画像のカラーデプス
  • forecolor:前景色
  • backcolor:背景色

戻り値:

  • null

pushGrayscaleImageAffine

関数プロトタイプ:

void pushGrayscaleImageAffine(const float matrix[6], int32_t w, int32_t h, const uint8_t* image, color_depth_t depth, const T& forecolor, const T& backcolor)

機能説明:

  • グレースケール画像をアフィン変換でディスプレイにプッシュします

引数:

  • matrix:6つのfloat値の配列、アフィン変換行列
  • w:画像の幅
  • h:画像の高さ
  • image:画像データへのポインタ
  • depth:画像のカラーデプス
  • forecolor:前景色
  • backcolor:背景色

戻り値:

  • null

pushGrayscaleImageRotateZoom

関数プロトタイプ:

void pushGrayscaleImageRotateZoom(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, const uint8_t* image, color_depth_t depth, const T& forecolor, const T& backcolor)

機能説明:

  • グレースケール画像をアフィン変換でディスプレイにプッシュします

引数:

  • dst_x:出力画像左上のx座標
  • dst_y:出力画像左上のy座標
  • src_x:元画像左上のx座標
  • src_y:元画像左上のy座標
  • angle:回転角度(ラジアン単位)
  • zoom_x:x方向のズーム比
  • zoom_y:y方向のズーム比
  • w:画像の幅
  • h:画像の高さ
  • image:画像データへのポインタ
  • depth:画像のカラーデプス
  • forecolor:前景色
  • backcolor:背景色

戻り値:

  • null

pushImage

関数プロトタイプ1:

void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const T* data)

関数プロトタイプ2:

void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const T1* data, const T2& transparent)

関数プロトタイプ3:

void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const void* data, color_depth_t depth, const T* palette)

関数プロトタイプ4:

void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const void* data, uint32_t transparent, color_depth_t depth, const T* palette)

機能説明:

  • 画像をディスプレイにプッシュします

引数:

  • x:画像左上のx座標
  • y:画像左上のy座標
  • w:画像の幅
  • h:画像の高さ
  • data:画像ピクセルデータへのポインタ
  • transparent:透過色
  • depth:画像のカラーデプス
  • palette:パレットへのポインタ

戻り値:

  • null

pushImageDMA

関数プロトタイプ1:

void pushImageDMA(int32_t x, int32_t y, int32_t w, int32_t h, const T* data)

関数プロトタイプ2:

void pushImageDMA(int32_t x, int32_t y, int32_t w, int32_t h, const void* data, color_depth_t depth, const T* palette)

機能説明:

  • DMAを使って画像をディスプレイにプッシュします

引数:

  • x:画像左上のx座標
  • y:画像左上のy座標
  • w:画像の幅
  • h:画像の高さ
  • data:画像ピクセルデータへのポインタ
  • depth:画像のカラーデプス
  • palette:パレットへのポインタ

戻り値:

  • null

pushImageAffine

関数プロトタイプ1:

void pushImageAffine(const float matrix[6], int32_t w, int32_t h, const T* data)

関数プロトタイプ2:

void pushImageAffine(const float matrix[6], int32_t w, int32_t h, const T1* data, const T2& transparent)

関数プロトタイプ3:

void pushImageAffine(const float matrix[6], int32_t w, int32_t h, const void* data, color_depth_t depth, const T* palette)

関数プロトタイプ4:

void pushImageAffine(const float matrix[6], int32_t w, int32_t h, const void* data, uint32_t transparent, color_depth_t depth, const T* palette)

機能説明:

  • アフィン変換を使って画像をディスプレイにプッシュします

引数:

  • matrix:6つのfloat値の配列、アフィン変換行列
  • w:画像の幅
  • h:画像の高さ
  • data:画像ピクセルデータへのポインタ
  • transparent:透過色
  • depth:画像のカラーデプス
  • palette:パレットへのポインタ

戻り値:

  • null

pushImageAffineWithAA

関数プロトタイプ1:

void pushImageAffineWithAA(const float matrix[6], int32_t w, int32_t h, const T* data)

関数プロトタイプ2:

void pushImageAffineWithAA(const float matrix[6], int32_t w, int32_t h, const T1* data, const T2& transparent)

関数プロトタイプ3:

void pushImageAffineWithAA(const float matrix[6], int32_t w, int32_t h, const void* data, color_depth_t depth, const T* palette)

関数プロトタイプ4:

void pushImageAffineWithAA(const float matrix[6], int32_t w, int32_t h, const void* data, uint32_t transparent, color_depth_t depth, const T* palette)

機能説明:

  • アンチエイリアス付きアフィン変換で画像をディスプレイにプッシュします

引数:

  • matrix:6つのfloat値の配列、アフィン変換行列
  • w:画像の幅
  • h:画像の高さ
  • data:画像ピクセルデータへのポインタ
  • transparent:透過色
  • depth:画像のカラーデプス
  • palette:パレットへのポインタ

戻り値:

  • null

pushImageRotateZoom

関数プロトタイプ1:

void pushImageRotateZoom(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, const T* data)

関数プロトタイプ2:

void pushImageRotateZoom(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, const T1* data, const T2& transparent)

関数プロトタイプ3:

void pushImageRotateZoom(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, const void* data, color_depth_t depth, const T* palette)

関数プロトタイプ4:

void pushImageRotateZoom(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, const void* data, uint32_t transparent, color_depth_t depth, const T* palette)

機能説明:

  • 画像を回転・ズームしてディスプレイにプッシュします

引数:

  • dst_x:出力画像左上のx座標
  • dst_y:出力画像左上のy座標
  • src_x:元画像左上のx座標
  • src_y:元画像左上のy座標
  • angle:回転角度(ラジアン単位)
  • zoom_x:x方向のズーム比
  • zoom_y:y方向のズーム比
  • w:画像の幅
  • h:画像の高さ
  • data:画像ピクセルデータへのポインタ
  • transparent:透過色
  • depth:画像のカラーデプス
  • palette:パレットへのポインタ

戻り値:

  • null

pushImageRotateZoomWithAA

関数プロトタイプ1:

void pushImageRotateZoomWithAA(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, const T* data)

関数プロトタイプ2:

void pushImageRotateZoomWithAA(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, const T1* data, const T2& transparent)

関数プロトタイプ3:

void pushImageRotateZoomWithAA(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, const void* data, color_depth_t depth, const T* palette)

関数プロトタイプ4:

void pushImageRotateZoomWithAA(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, const void* data, uint32_t transparent, color_depth_t depth, const T* palette)

機能説明:

  • アンチエイリアス付きで画像を回転・ズームしてディスプレイにプッシュします

引数:

  • dst_x:出力画像左上のx座標
  • dst_y:出力画像左上のy座標
  • src_x:元画像左上のx座標
  • src_y:元画像左上のy座標
  • angle:回転角度(ラジアン単位)
  • zoom_x:x方向のズーム比
  • zoom_y:y方向のズーム比
  • w:画像の幅
  • h:画像の高さ
  • data:画像ピクセルデータへのポインタ
  • transparent:透過色
  • depth:画像のカラーデプス
  • palette:パレットへのポインタ

戻り値:

  • null

画像色変換

setSwapBytes

関数プロトタイプ:

void setSwapBytes(bool swap)

機能説明:

  • バイトスワップ状態を設定します

引数:

  • swap:バイトスワップ状態
    • true:バイトスワップする
    • false:バイトスワップしない

戻り値:

  • null

getSwapBytes

関数プロトタイプ:

bool getSwapBytes(void)

機能説明:

  • setSwapBytesで設定したバイトスワップ状態を取得します

引数:

  • null

戻り値:

  • bool:バイトスワップ状態
    • true:スワップ済み
    • false:未スワップ

swap565

関数プロトタイプ:

uint16_t swap565( uint8_t r, uint8_t g, uint8_t b)

機能説明:

  • R,G,B成分からカラーコードを生成します

引数:

  • r: 赤成分、0-255
  • g: 緑成分、0-255
  • b: 青成分、0-255

戻り値:

  • uint16_t:RGB565カラーコード

swap888

関数プロトタイプ:

uint16_t swap888( uint8_t r, uint8_t g, uint8_t b)

機能説明:

  • R,G,B成分からカラーコードを生成します

引数:

  • r: 赤成分、0-255
  • g: 緑成分、0-255
  • b: 青成分、0-255

戻り値:

  • uint32_t:RGB888カラーコード

サンプルプログラム:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#include <Arduino.h>
#include <M5GFX.h>
#include <M5Unified.h>

M5GFX display;
uint16_t PngData[1600];
static float Affine_mat[9] = {1, 0, 0,
                              0, 1, 60,
                              0, 0, 1  };

void setup() {
    display.begin();
    display.setColorDepth(24);
    display.setRotation(1);
    display.clear(TFT_WHITE);
    display.setTextFont(&fonts::FreeSansOblique12pt7b);
    display.setTextColor(0xF81F);
    delay(1000);
    uint16_t x = display.width() / 2;
    uint16_t y = display.height() / 2;
    // display.setSwapBytes(true);//If you want to directly assign a 16-bit color code in the lower code section, you need to enable this line of code.
    for (int i = 0; i < 1600; ++i) PngData[i] = display.swap565( 255, 0, 0);//After swapping, it becomes BGR565.

    display.drawCenterString("Push Image Test", x, 10);
    delay(2000);
    display.pushImage(0, y, 320, 5, PngData);
    // display.pushImageDMA(0, y, 320, 5, PngData);
    // Shift 60 units from the origin(0,0) using the affine matrix
    // display.pushImageAffine(Affine_mat, 320, 5, PngData, 80);
    display.pushImageAffineWithAA(Affine_mat, 320, 5, PngData, 40);
    // Rotate and Zoom, by comparing on the screen, you can see the effect of anti-aliasing.
    display.pushImageRotateZoom(x, y, 0, 0, 37, 2, 2, 320, 5, PngData);
    display.pushImageRotateZoomWithAA(x, y, 0, 4, 143, 2, 2, 320, 5, PngData);
}

void loop() {
}
On This Page