Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(423068)

Side by Side Diff: examples/player_example.c

Issue 1357: Preserve video aspect ratio when resizing.
Patch Set: Created 3 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /*Daala video codec 1 /*Daala video codec
2 Copyright (c) 2006-2013 Daala project contributors. All rights reserved. 2 Copyright (c) 2006-2013 Daala project contributors. All rights reserved.
3 3
4 Redistribution and use in source and binary forms, with or without 4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met: 5 modification, are permitted provided that the following conditions are met:
6 6
7 - Redistributions of source code must retain the above copyright notice, this 7 - Redistributions of source code must retain the above copyright notice, this
8 list of conditions and the following disclaimer. 8 list of conditions and the following disclaimer.
9 9
10 - Redistributions in binary form must reproduce the above copyright notice, 10 - Redistributions in binary form must reproduce the above copyright notice,
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 int ret; 220 int ret;
221 if (player == NULL) return -1; 221 if (player == NULL) return -1;
222 if (player->input == stdin) return -1; 222 if (player->input == stdin) return -1;
223 ret = player_example_close_input(player); 223 ret = player_example_close_input(player);
224 if (ret != 0) return -1; 224 if (ret != 0) return -1;
225 ret = player_example_open_input(player, player->input_path); 225 ret = player_example_open_input(player, player->input_path);
226 return ret; 226 return ret;
227 } 227 }
228 228
229 void player_example_display_frame(player_example *player) { 229 void player_example_display_frame(player_example *player) {
230 int renderer_w = 0;
231 int renderer_h = 0;
232 double w_scale = 0.0;
233 double h_scale = 0.0;
234 double scale_factor = 0.0;
235 SDL_Rect dstrect = {0, 0, 0, 0};
236 /*Scale the video output so that it touches the renderer edges.*/
237 SDL_GetRendererOutputSize(player->renderer, &renderer_w, &renderer_h);
238 w_scale = (double) renderer_w / (double) player->width;
239 h_scale = (double) renderer_h / (double) player->height;
240 scale_factor = (w_scale < h_scale) ? w_scale : h_scale;
241 dstrect.w = player->width * scale_factor;
242 dstrect.h = player->height * scale_factor;
243 /*Centralize the video on the window.*/
244 dstrect.x = renderer_w / 2 - dstrect.w / 2;
245 dstrect.y = renderer_h / 2 - dstrect.h / 2;
230 SDL_RenderClear(player->renderer); 246 SDL_RenderClear(player->renderer);
231 SDL_RenderCopy(player->renderer, player->texture, NULL, NULL); 247 SDL_RenderCopy(player->renderer, player->texture, NULL, &dstrect);
232 SDL_RenderPresent(player->renderer); 248 SDL_RenderPresent(player->renderer);
233 } 249 }
234 250
235 void player_example_handle_event(player_example *player, SDL_Event *event) { 251 void player_example_handle_event(player_example *player, SDL_Event *event) {
236 switch (event->type) { 252 switch (event->type) {
237 case SDL_QUIT: { 253 case SDL_QUIT: {
238 player->done = 1; 254 player->done = 1;
239 break; 255 break;
240 } 256 }
241 case SDL_KEYDOWN: { 257 case SDL_KEYDOWN: {
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 if (!*previous_ticks) 706 if (!*previous_ticks)
691 return; 707 return;
692 708
693 tmp = SDL_GetTicks(); 709 tmp = SDL_GetTicks();
694 while (tmp - *previous_ticks < ms_per_frame) { 710 while (tmp - *previous_ticks < ms_per_frame) {
695 SDL_Delay(ms_per_frame - (tmp - *previous_ticks)); 711 SDL_Delay(ms_per_frame - (tmp - *previous_ticks));
696 tmp = SDL_GetTicks(); 712 tmp = SDL_GetTicks();
697 } 713 }
698 *previous_ticks = tmp; 714 *previous_ticks = tmp;
699 } 715 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld