Fixed Drawing of rects in Emulator.
Got frames from pixy to emulator. Slooooow.
This commit is contained in:
148
common/app/app.c
148
common/app/app.c
@@ -12,26 +12,37 @@ void app_init() {
|
||||
|
||||
//only testwise
|
||||
tft_clear(WHITE);
|
||||
tft_draw_pixel(0,0,GREEN);
|
||||
tft_draw_pixel(320-1,240-1,GREEN);
|
||||
tft_draw_line(10,10,30,40,RGB(0xFF,0,0xFF));
|
||||
tft_draw_pixel(100,100,RED);
|
||||
tft_draw_rectangle(120,120,20,30,BLUE);
|
||||
tft_fill_rectangle(200,120,30,30,GREEN);
|
||||
|
||||
|
||||
tft_draw_pixel(10,210,BLUE);
|
||||
tft_draw_pixel(12,210,BLUE);
|
||||
tft_draw_rectangle(40,210,60,235,BLUE);
|
||||
tft_fill_rectangle(100,215,200,225,GREEN);
|
||||
tft_draw_line(10,215,310,225,RGB(0xFF,0,0xFF));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void pixy_led_test();
|
||||
void pixy_frame_test();
|
||||
|
||||
//app event loop
|
||||
void app_process() {
|
||||
pixy_service(); //send/receive event data
|
||||
|
||||
//Code for tests see below
|
||||
pixy_led_test();
|
||||
pixy_frame_test();
|
||||
|
||||
//system_delay(500);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
int colorind;
|
||||
const uint32_t colors [] = {0xFF0000, 0x00FF00,0x0000FF,0xFFFF00,0x00FFFF,0xFF00FF,0xFFFFFF,0x000000};
|
||||
const int num_colors = sizeof(colors)/sizeof(uint32_t);
|
||||
|
||||
//app event loop
|
||||
void app_process() {
|
||||
pixy_service();
|
||||
|
||||
void pixy_led_test() {
|
||||
if(colorind==0) {
|
||||
pixy_led_set_max_current(5);
|
||||
}
|
||||
@@ -40,6 +51,115 @@ void app_process() {
|
||||
int return_value;
|
||||
return_value = pixy_command("led_set", INT32(colors[colorind++]), END_OUT_ARGS, &response, END_IN_ARGS);
|
||||
colorind%=num_colors;
|
||||
|
||||
system_delay(500);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
int renderBA81(uint8_t renderFlags, uint16_t width, uint16_t height, uint32_t frameLen, uint8_t *frame);
|
||||
|
||||
|
||||
void pixy_frame_test() {
|
||||
|
||||
uint8_t* videodata;
|
||||
int32_t response;
|
||||
int32_t fourccc;
|
||||
int8_t renderflags;
|
||||
uint16_t xwidth;
|
||||
uint16_t ywidth;
|
||||
uint32_t size;
|
||||
|
||||
|
||||
int return_value = pixy_command("cam_getFrame", // String id for remote procedure
|
||||
INT8(0x21), // mode
|
||||
INT16(0), // xoffset
|
||||
INT16(0), // yoffset
|
||||
INT16(320), // width
|
||||
INT16(200), // height
|
||||
END_OUT_ARGS, // separator
|
||||
&response, // pointer to mem address for return value
|
||||
&fourccc,
|
||||
&renderflags,
|
||||
&xwidth,
|
||||
&ywidth,
|
||||
&size,
|
||||
&videodata, // pointer to mem address for returned frame
|
||||
END_IN_ARGS);
|
||||
|
||||
|
||||
if(return_value==0) {
|
||||
return_value = renderBA81(renderflags,xwidth,ywidth,size,videodata);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline void interpolateBayer(uint16_t width, uint16_t x, uint16_t y, uint8_t *pixel, uint8_t* r, uint8_t* g, uint8_t* b)
|
||||
{
|
||||
if (y&1)
|
||||
{
|
||||
if (x&1)
|
||||
{
|
||||
*r = *pixel;
|
||||
*g = (*(pixel-1)+*(pixel+1)+*(pixel+width)+*(pixel-width))>>2;
|
||||
*b = (*(pixel-width-1)+*(pixel-width+1)+*(pixel+width-1)+*(pixel+width+1))>>2;
|
||||
}
|
||||
else
|
||||
{
|
||||
*r = (*(pixel-1)+*(pixel+1))>>1;
|
||||
*g = *pixel;
|
||||
*b = (*(pixel-width)+*(pixel+width))>>1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (x&1)
|
||||
{
|
||||
*r = (*(pixel-width)+*(pixel+width))>>1;
|
||||
*g = *pixel;
|
||||
*b = (*(pixel-1)+*(pixel+1))>>1;
|
||||
}
|
||||
else
|
||||
{
|
||||
*r = (*(pixel-width-1)+*(pixel-width+1)+*(pixel+width-1)+*(pixel+width+1))>>2;
|
||||
*g = (*(pixel-1)+*(pixel+1)+*(pixel+width)+*(pixel-width))>>2;
|
||||
*b = *pixel;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int renderBA81(uint8_t renderFlags, uint16_t width, uint16_t height, uint32_t frameLen, uint8_t *frame)
|
||||
{
|
||||
uint16_t x, y;
|
||||
uint8_t r, g, b;
|
||||
|
||||
|
||||
// skip first line
|
||||
frame += width;
|
||||
|
||||
// don't render top and bottom rows, and left and rightmost columns because of color
|
||||
// interpolation
|
||||
//uint32_t decodedimage[(width-2)*(height-2)];
|
||||
uint16_t decodedimage[(width-2)*(height-2)];
|
||||
|
||||
uint16_t* line = decodedimage;
|
||||
for (y=1; y<height-1; y++)
|
||||
{
|
||||
//line = (unsigned int *)img.scanLine(y-1);
|
||||
frame++;
|
||||
for (x=1; x<width-1; x++, frame++)
|
||||
{
|
||||
interpolateBayer(width, x, y, frame, &r, &g, &b);
|
||||
//*line++ = (0xff<<24) | (r<<16) | (g<<8) | (b<<0);
|
||||
*line++ = RGB(r,g,b);
|
||||
}
|
||||
frame++;
|
||||
}
|
||||
|
||||
tft_draw_bitmap_unscaled(0,0,width-2,height-2,decodedimage);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,5 +7,5 @@ void ll_tft_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16
|
||||
void ll_tft_draw_pixel(uint16_t x,uint16_t y,uint16_t color);
|
||||
void ll_tft_draw_rectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2, uint16_t color);
|
||||
void ll_tft_fill_rectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2, uint16_t color);
|
||||
void ll_tft_draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint8_t* dat);
|
||||
void ll_tft_draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t *dat);
|
||||
|
||||
|
||||
@@ -30,6 +30,6 @@ void tft_fill_rectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2, uint16_
|
||||
ll_tft_fill_rectangle(x1,y1,x2,y2,color);
|
||||
}
|
||||
|
||||
void tft_draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint8_t* dat) {
|
||||
void tft_draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t* dat) {
|
||||
ll_tft_draw_bitmap_unscaled(x,y,width,height,dat);
|
||||
}
|
||||
|
||||
@@ -17,4 +17,4 @@ void tft_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t
|
||||
void tft_draw_pixel(uint16_t x,uint16_t y,uint16_t color);
|
||||
void tft_draw_rectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2, uint16_t color);
|
||||
void tft_fill_rectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2, uint16_t color);
|
||||
void tft_draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint8_t* dat);
|
||||
void tft_draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t* dat);
|
||||
|
||||
@@ -24,7 +24,7 @@ void ll_tft_fill_rectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2, uint
|
||||
|
||||
}
|
||||
|
||||
void ll_tft_draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint8_t* dat) {
|
||||
void ll_tft_draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t* dat) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ OBJ_DIR=./obj
|
||||
#Architecture flags
|
||||
|
||||
#Compiler, Linker Options
|
||||
CPPFLAGS=-I$(INC_DIR) -D__LINUX__=1 -DHOST=1 -DDEBUG=1
|
||||
CPPFLAGS=-I$(INC_DIR) -D__LINUX__=1 -DHOST=1 #-DDEBUG=1
|
||||
CFLAGS=$(ARCH_FLAGS) -O0 -g #-ffunction-sections -fdata-sections -g
|
||||
#CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork
|
||||
#CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
|
||||
|
||||
@@ -37,7 +37,7 @@ void ll_tft_fill_rectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2, uint
|
||||
mainwindow->fill_rectangle(x1,y1,x2,y2,color);
|
||||
}
|
||||
|
||||
void ll_tft_draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint8_t* dat) {
|
||||
void ll_tft_draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t* dat) {
|
||||
mainwindow->draw_bitmap_unscaled(x,y,width,height,dat);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#define DISPLAY_X 10
|
||||
#define DISPLAY_Y 10
|
||||
|
||||
QColor colorFromRGB565(uint16_t color) {
|
||||
QColor QColorFromRGB565(uint16_t color) {
|
||||
|
||||
int R8 = (int) floor( (color>>(5+6)) * 255.0 / 31.0 + 0.5);
|
||||
int G8 = (int) floor( ((color>>5)&0x3F) * 255.0 / 63.0 + 0.5);
|
||||
@@ -18,81 +18,92 @@ QColor colorFromRGB565(uint16_t color) {
|
||||
return QColor::fromRgb(R8,G8,B8);
|
||||
}
|
||||
|
||||
QRgb QRgbFromRGB565(uint16_t color) {
|
||||
|
||||
int R8 = (int) floor( (color>>(5+6)) * 255.0 / 31.0 + 0.5);
|
||||
int G8 = (int) floor( ((color>>5)&0x3F) * 255.0 / 63.0 + 0.5);
|
||||
int B8 = (int) floor( (color&0x1F) * 255.0 / 31.0 + 0.5);
|
||||
return qRgb(R8,G8,B8);
|
||||
}
|
||||
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
pixmap(DISPLAY_WIDTH,DISPLAY_HEIGHT),
|
||||
image(DISPLAY_WIDTH,DISPLAY_HEIGHT,QImage::Format_RGB16),
|
||||
ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
image.fill(Qt::black);
|
||||
}
|
||||
|
||||
void MainWindow::draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
|
||||
{
|
||||
|
||||
render_mutex.lock();
|
||||
QPainter painter(&(pixmap));
|
||||
painter.setPen(colorFromRGB565(color));
|
||||
//render_mutex.lock();
|
||||
QPainter painter(&(image));
|
||||
painter.setPen(QColorFromRGB565(color));
|
||||
painter.drawLine(x1,y1,x2,y2);
|
||||
render_mutex.unlock();
|
||||
//render_mutex.unlock();
|
||||
update();
|
||||
}
|
||||
|
||||
void MainWindow::draw_pixel(uint16_t x, uint16_t y, uint16_t color)
|
||||
{
|
||||
render_mutex.lock();
|
||||
QPainter painter(&(pixmap));
|
||||
painter.setPen(colorFromRGB565(color));
|
||||
painter.drawPoint(x,y);
|
||||
render_mutex.unlock();
|
||||
//render_mutex.lock();
|
||||
image.setPixel(x,y,QRgbFromRGB565(color));
|
||||
//render_mutex.unlock();
|
||||
update();
|
||||
}
|
||||
|
||||
void MainWindow::clear(uint16_t color)
|
||||
{
|
||||
render_mutex.lock();
|
||||
pixmap.fill(colorFromRGB565(color));
|
||||
render_mutex.unlock();
|
||||
//render_mutex.lock();
|
||||
image.fill(QColorFromRGB565(color));
|
||||
//render_mutex.unlock();
|
||||
update();
|
||||
}
|
||||
|
||||
void MainWindow::draw_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
|
||||
{
|
||||
render_mutex.lock();
|
||||
QPainter painter(&(pixmap));
|
||||
painter.setPen(colorFromRGB565(color));
|
||||
painter.drawRect(x1,y1,x2,y2);
|
||||
render_mutex.unlock();
|
||||
//render_mutex.lock();
|
||||
QPainter painter(&(image));
|
||||
painter.setPen(QColorFromRGB565(color));
|
||||
painter.drawRect(x1,y1,abs(x2-x1)+1,abs(y2-y1)+1);
|
||||
//render_mutex.unlock();
|
||||
update();
|
||||
}
|
||||
|
||||
void MainWindow::fill_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
|
||||
{
|
||||
render_mutex.lock();
|
||||
QPainter painter(&(pixmap));
|
||||
painter.fillRect(x1,y1,x2,y2,colorFromRGB565(color));
|
||||
render_mutex.unlock();
|
||||
//render_mutex.lock();
|
||||
QPainter painter(&(image));
|
||||
painter.fillRect(x1,y1,abs(x2-x1)+1,abs(y2-y1)+1,QColorFromRGB565(color));
|
||||
//render_mutex.unlock();
|
||||
update();
|
||||
}
|
||||
|
||||
void MainWindow::draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint8_t *dat)
|
||||
void MainWindow::draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t *dat)
|
||||
{
|
||||
render_mutex.lock();
|
||||
QPainter painter(&(pixmap));
|
||||
//render_mutex.lock();
|
||||
|
||||
for(int yi=0; yi<height; yi++) {
|
||||
for(int xi=0; xi<width; xi++) {
|
||||
painter.setPen(colorFromRGB565(dat[yi*width+xi]));
|
||||
painter.drawPoint(x+xi,y+yi);
|
||||
image.setPixel(x+xi,y+yi,QRgbFromRGB565(dat[yi*width+xi]));
|
||||
}
|
||||
}
|
||||
render_mutex.unlock();
|
||||
|
||||
//render_mutex.unlock();
|
||||
update();
|
||||
}
|
||||
|
||||
void MainWindow::paintEvent(QPaintEvent *)
|
||||
{
|
||||
render_mutex.lock();
|
||||
//render_mutex.lock();
|
||||
QPainter painter(this);
|
||||
|
||||
painter.drawPixmap(DISPLAY_X,DISPLAY_Y,pixmap);
|
||||
painter.drawImage(DISPLAY_X,DISPLAY_Y,image);
|
||||
painter.setPen(QPen(Qt::green,2));
|
||||
painter.drawRect(DISPLAY_X-1,DISPLAY_Y-1,DISPLAY_WIDTH+2,DISPLAY_HEIGHT+2);
|
||||
render_mutex.unlock();
|
||||
//render_mutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
void clear(uint16_t color);
|
||||
void draw_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
|
||||
void fill_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
|
||||
void draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint8_t* dat);
|
||||
void draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t *dat);
|
||||
|
||||
|
||||
protected:
|
||||
@@ -28,8 +28,8 @@ protected:
|
||||
~MainWindow();
|
||||
|
||||
private:
|
||||
QMutex render_mutex;
|
||||
QPixmap pixmap;
|
||||
//QMutex render_mutex;
|
||||
QImage image;
|
||||
|
||||
Ui::MainWindow *ui;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user