commit: 21c8c3e4cbd5fa58439f1bbea09c338448c36fa8
parent 84d49fa27ed79b1ccb784bb528425816b4bec719
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Fri, 9 Oct 2020 01:16:46 +0200
SDL_YUV_visualisation: Use nearest scale, YUY2 instead of YV12, update_texture macro
Diffstat:
1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/C/SDL_YUV_visualisation.c b/C/SDL_YUV_visualisation.c
@@ -3,10 +3,9 @@
// Inspired by IBNIZ: http://pelulamu.net/ibniz/
#include <SDL2/SDL.h>
-#define SIZE_X 256
-#define SIZE_Y 256
+#define WIDTH 512
-uint32_t pixels[SIZE_X][SIZE_Y];
+uint32_t pixels[WIDTH][WIDTH];
struct
{
@@ -20,12 +19,12 @@ main(void)
{
SDL_Init(SDL_INIT_VIDEO);
- sdl.s = SDL_CreateWindow("IBVIZ", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SIZE_X, SIZE_Y, SDL_WINDOW_RESIZABLE);
+ sdl.s = SDL_CreateWindow("SDL YUV", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH, WIDTH, SDL_WINDOW_RESIZABLE);
sdl.r = SDL_CreateRenderer(sdl.s, -1, 0);
- SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
- SDL_RenderSetLogicalSize(sdl.r, SIZE_X, SIZE_Y);
- uint32_t format = SDL_PIXELFORMAT_YV12;
- sdl.o = SDL_CreateTexture(sdl.r, format, SDL_TEXTUREACCESS_STREAMING, SIZE_X, SIZE_Y);
+ SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest");
+ SDL_RenderSetLogicalSize(sdl.r, WIDTH, WIDTH);
+ uint32_t format = SDL_PIXELFORMAT_YUY2;
+ sdl.o = SDL_CreateTexture(sdl.r, format, SDL_TEXTUREACCESS_STREAMING, WIDTH, WIDTH);
while(1) {
SDL_Event event;
@@ -39,13 +38,17 @@ main(void)
}
uint32_t t = SDL_GetTicks();
- for(uint16_t y = 0; y < SIZE_Y; y++)
- for(uint16_t x = 0; x < SIZE_X; x++)
+ for(uint32_t y = 0; y < WIDTH; y++)
+ for(uint32_t x = 0; x < WIDTH; x++)
{
- pixels[x][y] = (t|2)<<(x*y/2);
+ //pixels[x][y] = (t|2)<<(x*y/2); // Mostly green with some colors; Christmas
+ //pixels[x][y] = (x|t)*(y|t);
+ //pixels[x][y] = 0x00FF0055;
+ //pixels[x][y] = ((x/2)<<24&0xFF000000);
+ pixels[x][y] = ((x/2)<<8&0x0000FF00);
}
- SDL_UpdateTexture(sdl.o, NULL, &pixels, (256/2) * 4);
+ SDL_UpdateTexture(sdl.o, NULL, &pixels, WIDTH*SDL_BYTESPERPIXEL(format));
SDL_RenderClear(sdl.r);
SDL_RenderCopy(sdl.r, sdl.o, NULL, NULL);
SDL_RenderPresent(sdl.r);