summaryrefslogtreecommitdiff
path: root/code/test
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2017-09-12 18:29:14 +0200
committerUros Majstorovic <majstor@majstor.org>2017-09-12 18:29:14 +0200
commit4cb21b503585764ae8f5208fee6f7ffd103d70f4 (patch)
tree49ab7795e281330de474c91fcdcd5a90bd631b9b /code/test
parent34b378ee754f5811b1f1cb30ca55a17dd26bb9cd (diff)
video test passed
Diffstat (limited to 'code/test')
-rw-r--r--code/test/vid/display.c68
-rw-r--r--code/test/vid/display.h17
2 files changed, 85 insertions, 0 deletions
diff --git a/code/test/vid/display.c b/code/test/vid/display.c
new file mode 100644
index 0000000..d378431
--- /dev/null
+++ b/code/test/vid/display.c
@@ -0,0 +1,68 @@
+#include <stdio.h>
+
+#include "display.h"
+
+void sdl_open(SDLCanvas *o, int img_width, int img_height) {
+ // Initialize the SDL
+ if (SDL_Init(SDL_INIT_VIDEO) != 0) {
+ fprintf(stderr, "SDL_Init() Failed: %s\n", SDL_GetError());
+ exit(1);
+ }
+
+ o->display = SDL_CreateWindow("SDL Tutorial",
+ SDL_WINDOWPOS_UNDEFINED,
+ SDL_WINDOWPOS_UNDEFINED,
+ img_width, img_height, 0);
+ if (o->display == NULL) {
+ fprintf(stderr, "SDL_SetVideoMode() Failed: %s\n", SDL_GetError());
+ exit(1);
+ }
+
+ o->renderer = SDL_CreateRenderer(o->display, -1, 0);
+ if (o->renderer == NULL) {
+ fprintf(stderr, "SDL_CreateRenderer() Failed: %s\n", SDL_GetError());
+ exit(1);
+ }
+
+ o->texture = SDL_CreateTexture(o->renderer, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING, img_width, img_height);
+ if (o->texture == NULL) {
+ fprintf(stderr, "SDL_CreateTextureFromSurface() Failed: %s\n", SDL_GetError());
+ exit(1);
+ }
+
+ o->yPlaneSz = img_width * img_height;
+ o->uvPlaneSz = img_width * img_height / 4;
+ o->yuvBuffer = (Uint8*)malloc(o->yPlaneSz + 2 * o->uvPlaneSz);
+ o->yPitch = img_width;
+ o->uvPitch = img_width / 2;
+}
+
+void sdl_close(SDLCanvas *o) {
+ free(o->yuvBuffer);
+ SDL_DestroyTexture(o->texture);
+ SDL_DestroyRenderer(o->renderer);
+ SDL_DestroyWindow(o->display);
+ SDL_Quit();
+}
+
+void sdl_display_frame(SDLCanvas *o) {
+ SDL_UpdateYUVTexture(o->texture, NULL, o->yuvBuffer, o->yPitch, o->yuvBuffer + o->yPlaneSz, o->uvPitch, o->yuvBuffer + o->yPlaneSz + o->uvPlaneSz, o->uvPitch);
+ SDL_RenderClear(o->renderer);
+ SDL_RenderCopy(o->renderer, o->texture, NULL, NULL);
+ SDL_RenderPresent(o->renderer);
+}
+
+void sdl_loop(void) {
+ SDL_Event event;
+
+ while(1) {
+ // Check for messages
+ if (SDL_PollEvent(&event)) {
+ // Check for the quit message
+ if (event.type == SDL_QUIT) {
+ // Quit the program
+ break;
+ }
+ }
+ }
+}
diff --git a/code/test/vid/display.h b/code/test/vid/display.h
new file mode 100644
index 0000000..38e07be
--- /dev/null
+++ b/code/test/vid/display.h
@@ -0,0 +1,17 @@
+#include "SDL.h"
+
+typedef struct SDLCanvas {
+ SDL_Window *display;
+ SDL_Renderer *renderer;
+ SDL_Texture *texture;
+ Uint8 *yuvBuffer;
+ size_t yPlaneSz;
+ size_t uvPlaneSz;
+ int yPitch;
+ int uvPitch;
+} SDLCanvas;
+
+void sdl_open(SDLCanvas *o, int img_width, int img_height);
+void sdl_close(SDLCanvas *o);
+void sdl_display_frame(SDLCanvas *o);
+void sdl_loop(void);