0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ドットアイテムのデータ構造を考える2(プログラム)(完

Last updated at Posted at 2023-11-07

オンラインコンパイラー

x カラー液晶は、 ST7789 ST7789V2 ATM0130B3 の事

目的
オンラインコンパイラーで動作を確認する

仕様
8000バイト
2000ドットアイテム
1ラインバッファは、240ドット、
480バイト

1ライン毎に最大2000回の直線検索がかかる。

インクリメントして2000で無視



    //ドットアイテムのカラーの設定
    //printf("%d(%d,%d)=%x \n",D_ID,x,y,color);
    buffer[ D_ID * 4 + 0] = y;
    buffer[ D_ID * 4 + 1] = x;
    buffer[ D_ID * 4 + 2] = (color >> 8) & 0xff;
    buffer[ D_ID * 4 + 3] =  color       & 0xff;

    if (D_ID < (MAX_D_ID - 2)) {
      D_ID++;
    }//end if


初期化


  memset(buffer, 0xff, MAX_D_ID * 4 );
  D_ID=0;


ラインバッファ処理



  //画面の表示
  int     kk;
  int     fy,fx,fh,fl;
  uint8_t linebuf[WIDTH * 2];

  for (int y = 0; y < HEIGHT; y++) {

    // y
    //ラインバッファの初期化
    for (int ii = 0; ii < (WIDTH * 2); ii++) {
      linebuf[ii] = 0;
    }
    kk = 0;
    //無限ループ
    while (1) { //直線検索(全件検索)
      fy = buffer[kk * 4 + 0];
      //fx = buffer[kk*4 + 1];
      //fh = buffer[kk*4 + 2];
      //fl = buffer[kk*4 + 3];
      //printf("[%d]",fy);
      if (fy == 0xff ) {break;}

      if (fy == y) {

        //fy = buffer[kk*4 + 0];
        fx = buffer[kk * 4 + 1];
        fh = buffer[kk * 4 + 2];
        fl = buffer[kk * 4 + 3];

        linebuf[ fx * 2 + 0] = fh;
        linebuf[ fx * 2 + 1] = fl;

      }//end if fy

      kk++;

    }//while


    for (int x = 0; x < WIDTH; x++) {

      //---------------- 1バイト目
      LCD_Write_Data(linebuf[ x * 2 + 0]);

      //---------------- 2バイト目
      LCD_Write_Data(linebuf[ x * 2 + 1]);

    }//x
  }//y




●結果

o_cop758.jpg

●プログラム

main.cpp



#include <iostream>
using namespace std;


uint8_t     *buffer;
uint8_t     *linebuf;
uint16_t    D_ID = 0;    

//buffer = (uint16_t *)malloc(WIDTH * HEIGHT * 2);

#define WIDTH  240
#define HEIGHT 240

#define NA_ST7735_P_BLACK 0x0000
#define NA_ST7735_P_WHITE 0xffff

int16_t width(){return(WIDTH);}

int16_t height(){return(HEIGHT);}

int getRotation(){return(0);}

void NA_ST7735_P_swap(int x, int y){int a=x;x=y;y=a;}


//とりま めんどくさいから普通の関数として定義する

//点の表示
void drawPixel(int16_t x, int16_t y, uint16_t color) {
  if ((x >= 0) && (x < width()) && (y >= 0) && (y < height())) {
    // Pixel is in-bounds. Rotate coordinates if needed.
    switch (getRotation()) {
    case 1:
      NA_ST7735_P_swap(x, y);
      x = WIDTH - x - 1;
      break;
    case 2:
      x = WIDTH - x - 1;
      y = HEIGHT - y - 1;
      break;
    case 3:
      NA_ST7735_P_swap(x, y);
      y = HEIGHT - y - 1;
      break;
    }//end switch

    //ドットアイテムのカラーの設定
    //printf("%d(%d,%d)=%x \n",D_ID,x,y,color);
    buffer[ D_ID*4 + 0] = y;
    buffer[ D_ID*4 + 1] = x;
    buffer[ D_ID*4 + 2] = (color >> 8) & 0xff;
    buffer[ D_ID*4 + 3] =  color       & 0xff;

    if (D_ID < (2000 - 2)) {D_ID++;}

  }//if
}//drawPixel


uint16_t ggg[] = {
0x0000,0x1111,0x1111,0x0000,0x0000,0x0000,0x0000,0x0000,
0x1111,0x0000,0x0000,0x1111,0x0000,0x0000,0x0000,0x0000,
0x1111,0x0000,0x0000,0x1111,0x0000,0x0000,0x0000,0x0000,
0x1111,0x1111,0x1111,0x1111,0x0000,0x0000,0x0000,0x0000,
0x1111,0x0000,0x0000,0x1111,0x0000,0x0000,0x0000,0x0000,
0x1111,0x0000,0x0000,0x1111,0x0000,0x0000,0x0000,0x0000,
0x1111,0x0000,0x0000,0x1111,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
};


int main(void){

    printf("\r\n");
    printf("START\r\n");

    //表示用のドットアイテムとラインバッファのエリア確保
    buffer = (uint8_t *)malloc(2000 * 4);
    linebuf = (uint8_t *)malloc(WIDTH * 2);

    //ドットアイテムバッファの初期化
    for(int ii=0;ii<(2000*4);ii++){buffer[ii]=0xff;}

    int jj=0;
    for(int y=0;y<8;y++){
      for(int x=0;x<8;x++){
	//buffer[ x |  y_shift[y]  ] = ggg[jj];
        drawPixel(x, y, ggg[jj]);
        //printf("(%d,%d)=%x",x,y,ggg[jj]);
        jj++;
      }//y
    }//x


    int fy;
    int fx;
    int fh;
    int fl;

/*
for(int mm=0;mm<16;mm++){
fy = buffer[mm*4 + 0];
fx = buffer[mm*4 + 1];
fh = buffer[mm*4 + 2];
fl = buffer[mm*4 + 3];


printf("%d %d %x %x\n",fy,fx,fh,fl);

}//for mm
*/


    //画面の表示
    printf("\r\n");
    int kk=0;
    int color=0;

    for(int y=0;y<8;y++){


// y
//ラインバッファの初期化
for(int ii=0;ii<(WIDTH * 2);ii++){linebuf[ii]=0;}
kk = 0;
//無限ループ
while(1){//直線検索(全件検索)
fy = buffer[kk*4 + 0];
//fx = buffer[kk*4 + 1];
//fh = buffer[kk*4 + 2];
//fl = buffer[kk*4 + 3];
//printf("[%d]",fy);
if(fy == 0xff ) break;

if(fy == y){

  //fy = buffer[kk*4 + 0];
  fx = buffer[kk*4 + 1];
  fh = buffer[kk*4 + 2];
  fl = buffer[kk*4 + 3];

  linebuf[ fx*2 + 0] = fh;
  linebuf[ fx*2 + 1] = fl;

}//end if fy

kk++;

}//while


      for(int x=0;x<40;x++){

        color =
        (linebuf[ x*2 + 0]<<8) 
        + 
         linebuf[ x*2 + 1];

	if( color == 0x0000){printf(" ");}else{printf("*");}

      }//x
      printf("\r\n");
    }//y



//printf("END\n");

}//main




0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?