File: showimage-Add-save-and-quit-options.patch

package info (click to toggle)
sdl-image1.2 1.2.12-14
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,028 kB
  • sloc: sh: 10,194; ansic: 9,697; objc: 248; csh: 219; makefile: 83
file content (71 lines) | stat: -rw-r--r-- 1,865 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
From: Simon McVittie <smcv@collabora.com>
Date: Mon, 23 Sep 2019 15:37:05 +0100
Subject: showimage: Add -save and -quit options

This allows showimage to be used as a non-interactive smoke-test to
check that the SDL_image library can be linked against successfully.

Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 showimage.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/showimage.c b/showimage.c
index 6f29d7d..20601b6 100644
--- a/showimage.c
+++ b/showimage.c
@@ -77,11 +77,13 @@ int main(int argc, char *argv[])
 {
 	Uint32 flags;
 	SDL_Surface *screen, *image;
-	int i, depth, done;
+	int i, depth;
+	int done = 0;
 	SDL_Event event;
 #if 0
 	SDL_RWops* rw_ops;
 #endif
+	const char *saveFile = NULL;
 
 	/* Check command line usage */
 	if ( ! argv[1] ) {
@@ -102,6 +104,15 @@ int main(int argc, char *argv[])
 			flags |= SDL_FULLSCREEN;
 			continue;
 		}
+		if ( SDL_strcmp(argv[i], "-quit") == 0 ) {
+			done = 1;
+			continue;
+		}
+		if ( SDL_strcmp(argv[i], "-save") == 0 && argv[i+1] ) {
+			++i;
+			saveFile = argv[i];
+			continue;
+		}
 #if 0
 		rw_ops = SDL_RWFromFile(argv[1], "r");
 		
@@ -125,6 +136,15 @@ int main(int argc, char *argv[])
 			        argv[i], SDL_GetError());
 			continue;
 		}
+
+		if ( saveFile ) {
+			if ( SDL_SaveBMP(image, saveFile) == 0 ) {
+				fprintf(stderr, "Saved a copy of %s to %s\n", argv[i], saveFile);
+			} else {
+				fprintf(stderr, "Couldn't save a copy of %s to %s: %s\n", argv[i], saveFile, SDL_GetError());
+			}
+		}
+
 		SDL_WM_SetCaption(argv[i], "showimage");
 
 		/* Create a display for the image */
@@ -164,7 +184,6 @@ int main(int argc, char *argv[])
 		SDL_BlitSurface(image, NULL, screen, NULL);
 		SDL_UpdateRect(screen, 0, 0, 0, 0);
 
-		done = 0;
 		while ( ! done ) {
 			if ( SDL_PollEvent(&event) ) {
 				switch (event.type) {