SDL_YUV_visualisation.c (1566B)
- // 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 WIDTH 512
- uint32_t pixels[WIDTH][WIDTH];
- struct
- {
- SDL_Window *s;
- SDL_Texture *o;
- SDL_Renderer *r;
- } sdl;
- int
- main(void)
- {
- SDL_Init(SDL_INIT_VIDEO);
- 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, "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;
- 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(uint32_t y = 0; y < WIDTH; y++)
- for(uint32_t x = 0; x < WIDTH; x++)
- {
- //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, WIDTH*SDL_BYTESPERPIXEL(format));
- 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;
- }