47 #define arcs_assert(a) (assert(a))
50 #define EventLogVar(a)
55#pragma GCC diagnostic ignored "-Wstrict-overflow"
101 length((size_t)width*(size_t)height),
102 size(length*(size_t)(32/8)),
110 IsFontDataLocked(true),
113 Screen = (uint32_t*) malloc(length*
sizeof(uint32_t));
114 Background = (uint32_t*) malloc(length*
sizeof(uint32_t));
137 IsFontDataLocked(true),
141 fbfd = open(DeviceName.c_str(), O_RDWR, 0);
145 ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo);
146 xlen = finfo.line_length;
149 ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo);
152 depth = vinfo.bits_per_pixel;
153 xofst = vinfo.xoffset;
154 yofst = vinfo.yoffset;
155 bppx = vinfo.bits_per_pixel;
156 length = (size_t)width*(
size_t)height;
157 size = length*(size_t)depth/8;
158 arcs_assert(depth == 32 &&
"[ERROR] FrameGraphics : Not supported color depth of display settings.");
160 Frame = (uint32_t*) mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fbfd, 0);
161 arcs_assert(Frame != MAP_FAILED &&
"[ERROR] FrameGraphics : mmap(...)");
164 EventLog(
"Could not open the frame buffer device. Trying to use a dummy buffer.");
172 length = (size_t)width*(
size_t)height;
173 size = length*(size_t)depth/8;
174 Frame = (uint32_t*) malloc(length*
sizeof(uint32_t));
177 Screen = (uint32_t*) malloc(length*
sizeof(uint32_t));
178 Background = (uint32_t*) malloc(length*
sizeof(uint32_t));
186 free(Background); Background =
nullptr;
187 free(Screen); Screen =
nullptr;
190 munmap(Frame, size); Frame =
nullptr;
191 close(fbfd); fbfd = 0;
194 free(Frame); Frame =
nullptr;
205 fp = fopen(FileName.c_str(),
"wb");
207 png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
nullptr,
nullptr,
nullptr);
208 info_ptr = png_create_info_struct(png_ptr);
209 png_init_io(png_ptr, fp);
216 PNG_COLOR_TYPE_RGB_ALPHA,
218 PNG_COMPRESSION_TYPE_DEFAULT,
219 PNG_FILTER_TYPE_DEFAULT
221 png_write_info(png_ptr, info_ptr);
222 png_set_invert_alpha(png_ptr);
223 png_set_bgr(png_ptr);
226 for(
size_t y = 0; y < static_cast<size_t>(height); ++y) png_write_row(png_ptr, (png_bytep)(&(Screen[width*y])));
229 png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
230 png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
233 fclose(fp); fp =
nullptr;
238 memcpy(Frame, Screen, size);
247 size_t i = ConvCoordinateToIndex(x, y);
248 for(
int j = 0; j < h; ++j){
250 memcpy(Frame + i + width*j, Screen + i + width*j,
sizeof(uint32_t)*w);
256 memcpy(Background, Screen, size);
265 size_t i = ConvCoordinateToIndex(x, y);
266 for(
int j = 0; j < h; ++j){
268 memcpy(Background + i + width*j, Screen + i + width*j,
sizeof(uint32_t)*w);
274 memcpy(Screen, Background, size);
283 size_t i = ConvCoordinateToIndex(x, y);
284 for(
int j = 0; j < h; ++j){
286 memcpy(Screen + i + width*j, Background + i + width*j,
sizeof(uint32_t)*w);
292 memcpy(Screen, Frame, size);
298 std::fill(Frame, Frame + length, ColorData);
304 std::fill(Screen, Screen + length, ColorData);
310 std::fill(Background, Background + length, ColorData);
333 template <FGsize T = FGsize::PX_1>
338 DrawDot(x, y, ColorData);
341 DrawDot(x , y , ColorData);
342 DrawDot(x , y + 1, ColorData);
343 DrawDot(x + 1, y , ColorData);
344 DrawDot(x + 1, y + 1, ColorData);
347 DrawDot(x , y , ColorData);
348 DrawDot(x , y + 1, ColorData);
349 DrawDot(x + 1, y , ColorData);
350 DrawDot(x + 1, y + 1, ColorData);
351 DrawDot(x , y - 1, ColorData);
352 DrawDot(x - 1, y , ColorData);
353 DrawDot(x - 1, y - 1, ColorData);
354 DrawDot(x + 1, y - 1, ColorData);
355 DrawDot(x - 1, y + 1, ColorData);
368 template <FGsize T = FGsize::PX_1>
378 template <FGsize T = FGsize::PX_1>
379 void DrawPoint(
int x,
int y,
double r,
double g,
double b){
388 template <FGsize T = FGsize::PX_1>
389 void DrawPoint(
int x,
int y,
double a,
double r,
double g,
double b){
398 DrawDot(x + 2, y, ColorData);
399 DrawDot(x - 2, y, ColorData);
400 DrawDot(x + 1, y, ColorData);
401 DrawDot(x - 1, y, ColorData);
402 DrawDot(x, y , ColorData);
403 DrawDot(x, y + 1, ColorData);
404 DrawDot(x, y - 1, ColorData);
405 DrawDot(x, y + 2, ColorData);
406 DrawDot(x, y - 2, ColorData);
421 void DrawCross(
int x,
int y,
double r,
double g,
double b){
430 template <FGsize T = FGsize::PX_1>
431 void DrawLine(
int x1,
int y1,
int x2,
int y2, uint32_t ColorData){
445 bool IsHighGradient = std::abs(x2 - x1) < std::abs(y2 - y1);
446 if(IsHighGradient ==
true){
455 int Dy = std::abs(y2 - y1);
464 for(
int x = x1; x <= x2; ++x){
465 if(IsHighGradient ==
true){
483 template <FGsize T = FGsize::PX_1>
495 for(
int y = ysta; y <= yend;y ++)
504 template <FGsize T = FGsize::PX_1>
516 for(
int x = xsta; x <= xend; x++)
525 template <FGsize T = FGsize::PX_1>
535 template <FGsize T = FGsize::PX_1>
536 void DrawLine(
int x1,
int y1,
int x2,
int y2,
double r,
double g,
double b){
545 template <FGsize T = FGsize::PX_1>
546 void DrawStairs(
int x1,
int y1,
int x2,
int y2, uint32_t ColorData){
556 template <FGsize T = FGsize::PX_1>
566 template <FGsize T = FGsize::PX_1>
567 void DrawStairs(
int x1,
int y1,
int x2,
int y2,
double r,
double g,
double b){
576 template <FGsize T = FGsize::PX_1>
577 void DrawRect(
int x,
int y,
int w,
int h, uint32_t ColorData){
589 template <FGsize T = FGsize::PX_1>
599 template <FGsize T = FGsize::PX_1>
600 void DrawRect(
int x,
int y,
int w,
int h,
double r,
double g,
double b){
609 size_t i = ConvCoordinateToIndex(x, y);
610 for(
int j = 0; j < h; ++j){
612 size_t sta = i + width*j;
613 size_t end = sta + w;
614 if(end < length) std::fill(Screen + sta, Screen + end, ColorData);
630 void DrawRectFill(
int x,
int y,
int w,
int h,
double r,
double g,
double b){
638 void DrawRectFill(
int x,
int y,
int w,
int h,
double r,
double g,
double b,
double a){
646 void DrawCircle(
int cx,
int cy,
int radius,
unsigned int N, uint32_t ColorData){
648 const double TwoPIdivN = 2.0*M_PI/(double)N;
649 int x_prev = (double)radius + cx;
651 for(
unsigned int i=0;i<=N;i++){
652 double theta = TwoPIdivN*(double)i;
653 int x = (double)radius*cos(theta) + cx;
654 int y = (double)radius*sin(theta) + cy;
655 DrawLine(x_prev,y_prev, x,y, ColorData);
673 void DrawCircle(
int cx,
int cy,
int radius,
unsigned int N,
double r,
double g,
double b){
681 IsFontDataLocked =
true;
694 IsFontDataLocked =
false;
702 case FGalign::ALIGN_LEFT:
705 case FGalign::ALIGN_CENTER:
709 case FGalign::ALIGN_RIGHT:
716 for(
size_t i = 0; i < text.length();i ++){
725 char str[TEXT_MAXLEN] = {
'\0'};
726 sprintf(str, format.c_str(), val);
732 DrawRect(4*width/6, 1*height/6, width/6, height/6, FGcolors::WHITE);
733 DrawRectFill(3*width/6, 2*height/6, width/6, height/6, FGcolors::RED);
734 DrawRectFill(4*width/6, 2*height/6, width/6, height/6, FGcolors::GREEN);
735 DrawRectFill(5*width/6, 2*height/6, width/6, height/6, FGcolors::BLUE);
736 DrawRectFill(12*width/2/12, 0, width/2/12, height/6, FGcolors::RED);
737 DrawRectFill(13*width/2/12, 0, width/2/12, height/6, FGcolors::GREEN);
738 DrawRectFill(14*width/2/12, 0, width/2/12, height/6, FGcolors::BLUE);
739 DrawRectFill(15*width/2/12, 0, width/2/12, height/6, FGcolors::CYAN);
740 DrawRectFill(16*width/2/12, 0, width/2/12, height/6, FGcolors::MAGENTA);
741 DrawRectFill(17*width/2/12, 0, width/2/12, height/6, FGcolors::YELLOW);
742 DrawRectFill(18*width/2/12, 0, width/2/12, height/6, FGcolors::ORANGE);
743 DrawRectFill(19*width/2/12, 0, width/2/12, height/6, FGcolors::WHITE);
744 DrawRectFill(20*width/2/12, 0, width/2/12, height/6, FGcolors::GRAY75);
745 DrawRectFill(21*width/2/12, 0, width/2/12, height/6, FGcolors::GRAY50);
746 DrawRectFill(22*width/2/12, 0, width/2/12, height/6, FGcolors::GRAY25);
747 DrawRectFill(23*width/2/12, 0, width/2/12, height/6, FGcolors::BLACK);
750 for(
size_t i = 0; i < N; ++i){
751 double beta = (double)i/(
double)N;
752 DrawLine(i+N, 3*height/6, i+N, 4*height/6, beta, 0, 0);
753 DrawLine(i+N, 4*height/6, i+N, 5*height/6, 0, beta, 0);
754 DrawLine(i+N, 5*height/6, i+N, 6*height/6, 0, 0, beta);
755 DrawLine(i, 3*height/6, i, 4*height/6, beta, beta, beta);
759 for(
size_t i = 0; i < N; ++i){
760 double beta = (double)i/(
double)N;
761 DrawLine(i, 4*height/6, i, height - 1, beta, 0, 1.0 - beta);
762 DrawLine(i + N, 4*height/6, i + N, height - 1, 1.0 - beta, beta, 0 );
763 DrawLine(i + 2*N, 4*height/6, i + 2*N, height - 1, 0, 1.0 - beta, beta );
766 DrawCircle(3*width/4, height/4, height/6, 100, FGcolors::GRAY50);
768 DrawLine(width/2, height/2, width - 1, 0, FGcolors::GRAY75);
769 DrawLine(width/2, 0, width - 1, height/2, FGcolors::GRAY75);
770 DrawLine(0, height/2, width - 1, height/2, FGcolors::WHITE);
771 DrawLine(width/2, 0, width/2, height - 1, FGcolors::WHITE);
774 PrintValue(10, 20, FGalign::ALIGN_LEFT,
"WIDTH = %15.0f [px]", width);
775 PrintValue(10, 30, FGalign::ALIGN_LEFT,
"HEIGHT = %15.0f [px]", height);
776 PrintValue(10, 40, FGalign::ALIGN_LEFT,
"DEPTH = %15.0f [bit]", depth);
777 PrintValue(10, 50, FGalign::ALIGN_LEFT,
"LENGTH = %15.0f [-]", length);
778 PrintValue(10, 60, FGalign::ALIGN_LEFT,
"SIZE = %15.0f [byte]", size);
779 PrintValue(10, 70, FGalign::ALIGN_LEFT,
"XOFST = %15.0f [-]", xofst);
780 PrintValue(10, 80, FGalign::ALIGN_LEFT,
"YOFST = %15.0f [-]", yofst);
781 PrintValue(10, 90, FGalign::ALIGN_LEFT,
"XLEN = %15.0f [-]", xlen);
782 PrintValue(10,100, FGalign::ALIGN_LEFT,
"BPPX = %15.0f [bit/px]", bppx);
783 PrintText(10, 120, FGalign::ALIGN_LEFT,
"FRAME GRAPHICS TEST PATTERN");
784 PrintText(10, 140, FGalign::ALIGN_LEFT,
"frame graphics test pattern");
798 return ColorSet[
static_cast<size_t>(color)];
804 uint32_t r = 0, g = 0, b = 0;
805 r = DoubleToRedIntensity(Red);
806 g = DoubleToGreenIntensity(Green);
807 b = DoubleToBlueIntensity(Blue);
814 uint32_t r = 0, g = 0, b = 0, a = 0;
815 a = DoubleToAlphaIntensity(Alpha);
816 r = DoubleToRedIntensity(Red);
817 g = DoubleToGreenIntensity(Green);
818 b = DoubleToBlueIntensity(Blue);
819 return a | r | g | b;
828 static constexpr size_t NUM_COLOR_SET = 13;
836 static constexpr std::array<uint32_t, NUM_COLOR_SET> ColorSet = {
855 uint32_t *Background;
864 struct fb_fix_screeninfo finfo;
865 struct fb_var_screeninfo vinfo;
872 static constexpr unsigned int TEXT_INTERVAL = 1;
873 static constexpr unsigned int TEXT_MAXLEN = 256;
874 bool IsFontDataLocked;
881 inline size_t ConvCoordinateToIndex(
int x,
int y){
882 return (
size_t)width*(size_t)y + (
size_t)x;
889 inline void DrawDot(
int x,
int y, uint32_t ColorData){
890 size_t i = ConvCoordinateToIndex(x, y);
891 if(length <= i)
return;
892 Screen[i] = ColorData;
896 uint32_t DoubleToIntensity(
double u){
899 return (uint32_t)((double)0x00FFFFFF*u);
903 uint32_t DoubleToRedIntensity(
double u){
906 return ((uint32_t)((
double)0x000000FF*u)) << 16;
910 uint32_t DoubleToGreenIntensity(
double u){
913 return ((uint32_t)((
double)0x000000FF*u)) << 8;
917 uint32_t DoubleToBlueIntensity(
double u){
920 return ((uint32_t)((
double)0x000000FF*u));
924 uint32_t DoubleToAlphaIntensity(
double u){
927 return ((uint32_t)((
double)0x000000FF*u)) << 24;
933 unsigned int ConvAsciiToIndex(
unsigned int ascii){
946 void WriteFont(
int x,
int y,
unsigned int ascii){
947 if(IsFontDataLocked ==
true)
return;
948 size_t i = ConvCoordinateToIndex(x, y);
949 unsigned int index = ConvAsciiToIndex(ascii);
#define EventLog(a)
イベントログ用マクロ (任意メッセージ記録版)
Definition ARCSeventlog.hh:27
#define arcs_assert(a)
ARCS用assertマクロ a : assert条件
Definition ARCSassert.hh:17
FGcolors
色の定義
Definition FrameGraphics.hh:60
FGsize
点および線の太さの定義
Definition FrameGraphics.hh:77
FGalign
文字列揃え位置の定義
Definition FrameGraphics.hh:84
static constexpr unsigned int WIDTH
[px] フォントの幅
Definition FrameFontSmall.hh:25
static constexpr unsigned int LINEBYTE32
32bitフォントデータ1ラインのバイト数
Definition FrameFontSmall.hh:30
static constexpr unsigned int NUM
収録しているフォントの数
Definition FrameFontSmall.hh:24
static constexpr int DATA[NUM][HEIGHT][WIDTH]
フォントデータ (フォントが気に食わない人は各自で好きなように変えてネ)
Definition FrameFontSmall.hh:34
static constexpr unsigned int END_ASCII
フォントデータに収録している最後の文字のアスキーコード
Definition FrameFontSmall.hh:28
static constexpr unsigned int HEIGHT
[px] フォントの高さ
Definition FrameFontSmall.hh:26
static constexpr unsigned int FST_ASCII
フォントデータに収録している最初の文字のアスキーコード
Definition FrameFontSmall.hh:27
フレームグラフィックスクラス(新型テンプレート版)
Definition FrameGraphics.hh:91
void DrawStairs(int x1, int y1, int x2, int y2, FGcolors color)
階段直線(x1,y1)ー(x2,y2)を引く関数(色の名前版)
Definition FrameGraphics.hh:557
void DrawLine(int x1, int y1, int x2, int y2, double r, double g, double b)
直線(x1,y1)ー(x2,y2)を引く関数(RGB版)
Definition FrameGraphics.hh:536
void FillBackground(uint32_t ColorData)
背景バッファを指定した色で埋める関数
Definition FrameGraphics.hh:309
void DrawPoint(int x, int y, uint32_t ColorData)
点(x,y)を描画する関数(バイナリデータ版)
Definition FrameGraphics.hh:334
void DrawRect(int x, int y, int w, int h, uint32_t ColorData)
長方形の描画をする関数(バイナリ色データ版)(色は塗らない)
Definition FrameGraphics.hh:577
void DrawCircle(int cx, int cy, int radius, unsigned int N, FGcolors color)
円の描画をする(色の名前版)
Definition FrameGraphics.hh:665
void PrintAllFontData(void)
収録されているすべてのフォントデータを描画するテスト用関数
Definition FrameGraphics.hh:788
void DrawCross(int x, int y, double r, double g, double b)
十字(x,y)を描画する関数(RGB版)
Definition FrameGraphics.hh:421
void DrawHorizontalLine(int x1, int x2, int y, uint32_t ColorData)
水平の直線(x1,y)ー(x2,y)を引く関数(バイナリデータ版)
Definition FrameGraphics.hh:505
FrameGraphics(const std::string &DeviceName)
コンストラクタ(フレームバッファ版)
Definition FrameGraphics.hh:121
void DrawCross(int x, int y, uint32_t ColorData)
十字(x,y)を描画する関数(バイナリデータ版)
Definition FrameGraphics.hh:397
void ClearFrame(void)
フレームバッファをクリアする関数
Definition FrameGraphics.hh:314
void DrawRect(int x, int y, int w, int h, FGcolors color)
長方形の描画をする関数(色の名前版)(色は塗らない)
Definition FrameGraphics.hh:590
void DrawStairs(int x1, int y1, int x2, int y2, double r, double g, double b)
階段直線(x1,y1)ー(x2,y2)を引く関数(RGB版)
Definition FrameGraphics.hh:567
void DrawPoint(int x, int y, double a, double r, double g, double b)
点(x,y)を描画する関数(αRGB版)
Definition FrameGraphics.hh:389
uint32_t ARGBcolorToData(double Alpha, double Red, double Green, double Blue)
0~1の浮動小数点で表現された赤緑青透過色の輝度値をバイナリ色データに変える
Definition FrameGraphics.hh:813
void SavePngImageFile(const std::string &FileName)
PNG画像ファイルを保存する関数
Definition FrameGraphics.hh:200
void DrawStairs(int x1, int y1, int x2, int y2, uint32_t ColorData)
階段直線(x1,y1)ー(x2,y2)を引く関数(バイナリデータ版)
Definition FrameGraphics.hh:546
void DrawRectFill(int x, int y, int w, int h, FGcolors color)
長方形の範囲内に色を塗る関数(色の名前版) (色を塗る)
Definition FrameGraphics.hh:622
void DrawTestPattern(void)
テストパターンを描画する関数
Definition FrameGraphics.hh:731
void DrawCircle(int cx, int cy, int radius, unsigned int N, uint32_t ColorData)
円の描画をする関数(バイナリ色データ版)
Definition FrameGraphics.hh:646
void DrawLine(int x1, int y1, int x2, int y2, FGcolors color)
直線(x1,y1)ー(x2,y2)を引く関数(色の名前版)
Definition FrameGraphics.hh:526
void FillScreen(uint32_t ColorData)
画面バッファを指定した色で埋める関数
Definition FrameGraphics.hh:303
uint32_t ColorNameToData(FGcolors color)
色の名前からバイナリ色データに変換する関数
Definition FrameGraphics.hh:797
void RefreshFrame(int x, int y, int w, int h)
指定した矩形範囲のみフレームバッファを更新する関数
Definition FrameGraphics.hh:246
void RefreshFrame(void)
フレームバッファを更新する関数
Definition FrameGraphics.hh:237
void PrepareFontData(FGcolors fore_color, FGcolors back_color)
指定した色のフォントデータを準備する関数
Definition FrameGraphics.hh:678
void DrawPoint(int x, int y, FGcolors color)
点(x,y)を描画する関数(色の名前版)
Definition FrameGraphics.hh:369
void LoadBackgroundToScreen(void)
背景バッファを画面バッファへ読み込む関数
Definition FrameGraphics.hh:273
void DrawLine(int x1, int y1, int x2, int y2, uint32_t ColorData)
直線(x1,y1)ー(x2,y2)を引く関数(バイナリデータ版)
Definition FrameGraphics.hh:431
void DrawCross(int x, int y, FGcolors color)
十字(x,y)を描画する関数(色の名前版)
Definition FrameGraphics.hh:413
void DrawRectFill(int x, int y, int w, int h, double r, double g, double b)
長方形の範囲内に色を塗る関数(RGB色データ版) (色を塗る)
Definition FrameGraphics.hh:630
void DrawVerticalLine(int x, int y1, int y2, uint32_t ColorData)
垂直の直線(x,y1)ー(x,y2)を引く関数(バイナリデータ版)
Definition FrameGraphics.hh:484
void PrintText(int x, int y, FGalign align, std::string text)
文字列を描画する関数 x:[px]横位置,y:[px] 縦位置,align:揃え位置,text:所望の文字列
Definition FrameGraphics.hh:699
void DrawCircle(int cx, int cy, int radius, unsigned int N, double r, double g, double b)
円の描画をする(RGB色データ版)
Definition FrameGraphics.hh:673
~FrameGraphics()
デストラクタ
Definition FrameGraphics.hh:185
void ClearBackground(void)
背景バッファをクリアする関数
Definition FrameGraphics.hh:324
void LoadFrameToScreen(void)
フレームバッファから画面バッファへ読み込む関数
Definition FrameGraphics.hh:291
FrameGraphics(int Width, int Height)
コンストラクタ(PNG画像ファイル版)
Definition FrameGraphics.hh:94
void StoreScreenAsBackground(int x, int y, int w, int h)
指定した矩形範囲のみ現在の画面バッファを背景バッファとして保存する関数
Definition FrameGraphics.hh:264
void DrawRect(int x, int y, int w, int h, double r, double g, double b)
長方形の描画をする関数(RGB版)(色は塗らない)
Definition FrameGraphics.hh:600
uint32_t RGBcolorToData(double Red, double Green, double Blue)
0~1の浮動小数点で表現された赤緑青色の輝度値をバイナリ色データに変える
Definition FrameGraphics.hh:803
void FillFrame(uint32_t ColorData)
フレームバッファを指定した色で埋める関数
Definition FrameGraphics.hh:297
void DrawRectFill(int x, int y, int w, int h, double r, double g, double b, double a)
長方形の範囲内に色を塗る関数(ARGB色データ版) (色を塗る)
Definition FrameGraphics.hh:638
void LoadBackgroundToScreen(int x, int y, int w, int h)
指定した矩形範囲のみ背景バッファを画面バッファへ読み込む関数
Definition FrameGraphics.hh:282
void DrawPoint(int x, int y, double r, double g, double b)
点(x,y)を描画する関数(RGB版)
Definition FrameGraphics.hh:379
void DrawRectFill(int x, int y, int w, int h, uint32_t ColorData)
長方形の範囲内に色を塗る関数(バイナリ色データ版) (色を塗る)
Definition FrameGraphics.hh:608
void StoreScreenAsBackground(void)
現在の画面バッファを背景バッファとして保存する関数
Definition FrameGraphics.hh:255
void ClearScreen(void)
画面バッファをクリアする関数
Definition FrameGraphics.hh:319
void PrintValue(int x, int y, FGalign align, std::string format, double val)
指定した書式で文字列を描画する関数 x:[px] 横位置,y:[px] 縦位置,align:揃え位置,format:書式指定子,val:所望の数値 formatの書式指定子は printf関数 の場合の...
Definition FrameGraphics.hh:724