Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix color inversion inside a buffer #143

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

dimitre
Copy link
Contributor

@dimitre dimitre commented Jun 17, 2024

Maixduino use to handle flipped colors inside a image buffer. By removing a byte swap from lcd we are able now to handle colors correctly for objects and image buffer.
it is now possible to make a gradient from black to white inside one image with the changes in this PR.

closes
#141
closes
#138

@dimitre
Copy link
Contributor Author

dimitre commented Jun 18, 2024

We have here a minimal example to test the color fixes:

#include <Sipeed_ST7789.h>
#include <Sipeed_OV2640.h>

SPIClass spi_(SPI0);
Sipeed_ST7789 lcd(320, 240, spi_);
Sipeed_OV2640 camera(FRAMESIZE_QQVGA, PIXFORMAT_RGB565);
GFXcanvas16 canvas(160, 120);

uint16_t rgbto565(uint8_t r, uint8_t g, uint8_t b) {
	return ((r & 0b11111000) << 8) | ((g & 0b11111100) << 3) | (b >> 3);
}

uint16_t rgbto565(uint8_t v) {
	return rgbto565(v, v, v);
}

void setup() {
	lcd.begin(15000000, COLOR_RED);
	lcd.println("hello Sipeed Maix");
	camera.begin();
	camera.run(true);
}

void loop() {
	// This should be Green and it is another color
	canvas.fillScreen(COLOR_GREEN);
	uint8_t * img = camera.snapshot();
	for (uint16_t x=0; x<camera.width(); x++) {
		for (uint16_t y=0; y<15; y++) {
			uint32_t index = x + y * camera.width();
			uint8_t gray = x * 255 / camera.width();
			// this should be a smooth gradient from black to white. 
			camera.getRGB565()[index] = rgbto565(gray);
			canvas.getBuffer()[index] = rgbto565(gray);
		}
	}
	lcd.drawImage(0, 30, camera.width(), camera.height(), camera.getRGB565());
	lcd.drawImage(camera.width(), 30, camera.width(), camera.height(), (uint16_t*)canvas.getBuffer());
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant