commit: b7f111ca723a576ca76163f5dcade89f456adf34
parent 66e56c1c6acd0dd73a47368e3afc76bc3998ed69
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Tue, 6 Oct 2020 23:33:12 +0200
SDL_YUV_visualisation: New file
Diffstat:
2 files changed, 66 insertions(+), 0 deletions(-)
diff --git a/C/Makefile b/C/Makefile
@@ -0,0 +1,6 @@
+SDL_YUV_visualisation:
+ $(CC) $(CFLAGS) SDL_YUV_visualisation.c -o SDL_YUV_visualisation `sdl2-config --cflags --libs`
+
+.PHONY: clean
+clean:
+ rm SDL_YUV_visualisation
diff --git a/C/SDL_YUV_visualisation.c b/C/SDL_YUV_visualisation.c
@@ -0,0 +1,60 @@
+// Copyright © 2020 Haelwenn (lanodan) Monnier <https://hacktivis.me/>
+// SPDX-License-Identifier: BSD-3-Clause
+
+// Inspired by IBNIZ: http://pelulamu.net/ibniz/
+#include <SDL2/SDL.h>
+#define SIZE_X 256
+#define SIZE_Y 256
+
+uint32_t pixels[SIZE_X][SIZE_Y];
+
+struct
+{
+ SDL_Window *s;
+ SDL_Texture *o;
+ SDL_Renderer *r;
+} sdl;
+
+int
+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.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);
+
+ while(1) {
+ SDL_Event event;
+
+ while (SDL_PollEvent(&event)) {
+ if(event.type == SDL_QUIT) goto quit;
+
+ if((event.type == SDL_KEYDOWN)
+ && (event.key.keysym.sym==SDLK_ESCAPE)
+ ) goto quit;
+ }
+
+ uint32_t t = SDL_GetTicks();
+ for(uint16_t y = 0; y < SIZE_Y; y++)
+ for(uint16_t x = 0; x < SIZE_X; x++)
+ {
+ pixels[x][y] = (t|2)<<(x*y/2);
+ }
+
+ SDL_UpdateTexture(sdl.o, NULL, &pixels, (256/2) * 4);
+ SDL_RenderClear(sdl.r);
+ SDL_RenderCopy(sdl.r, sdl.o, NULL, NULL);
+ SDL_RenderPresent(sdl.r);
+ }
+
+quit:
+ SDL_DestroyRenderer(sdl.r);
+ SDL_DestroyWindow(sdl.s);
+ SDL_Quit();
+
+ return 0;
+}