@@ -89,17 +89,37 @@ int main(int argc, char* * argv) {
89
89
char * gifname ;
90
90
struct ngiflibSDL_animation * animation ;
91
91
int i ;
92
+ int width , height ;
93
+ char windows_caption [256 ];
94
+ char icon_caption [256 ];
92
95
93
96
if (argc > 1 )
94
97
gifname = argv [1 ];
95
98
else
96
99
gifname = "amigagry.gif" ;
100
+
97
101
if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER ) < 0 ) {
98
102
fprintf (stderr , "Erreur d'init de la SDL !\n" );
99
103
return 1 ;
100
104
}
101
105
atexit (SDL_Quit );
102
- SDL_WM_SetCaption ("SDL gif viewer" , "gif viewer" ); /* window caption, icon caption */
106
+
107
+ animation = SDL_LoadAnimatedGif (gifname );
108
+ if (animation == NULL ) {
109
+ fprintf (stderr , "Failed to read %s\n" , gifname );
110
+ return 1 ;
111
+ }
112
+
113
+ if (animation -> image_count == 0 ) {
114
+ fprintf (stderr , "%s contains 0 images !\n" , gifname );
115
+ return 1 ;
116
+ }
117
+ width = animation -> images [0 ].surface -> w ;
118
+ height = animation -> images [0 ].surface -> h ;
119
+
120
+ snprintf (windows_caption , sizeof (windows_caption ), "SDL gif viewer : %s" , gifname );
121
+ snprintf (icon_caption , sizeof (icon_caption ), "gif viewer : %s" , gifname );
122
+ SDL_WM_SetCaption (windows_caption , icon_caption ); /* window caption, icon caption */
103
123
vidinf = SDL_GetVideoInfo ();
104
124
printf ("bpp of the \"best\" video mode = %d \n" , vidinf -> vfmt -> BitsPerPixel );
105
125
modes = SDL_ListModes (NULL , SDL_HWSURFACE );
@@ -113,14 +133,14 @@ int main(int argc, char* * argv) {
113
133
}
114
134
}
115
135
116
- bpp = SDL_VideoModeOK (640 , 480 , 16 , SDL_HWSURFACE | SDL_DOUBLEBUF );
136
+ bpp = SDL_VideoModeOK (width , height , 16 , SDL_HWSURFACE | SDL_DOUBLEBUF );
117
137
118
138
if (!bpp ){
119
139
printf ("Mode not available.\n" );
120
140
exit (-1 );
121
141
}
122
- printf ("SDL Recommends 640x480 @%dbpp.\n" , bpp );
123
- screen = SDL_SetVideoMode (640 , 480 , bpp , SDL_HWSURFACE | SDL_DOUBLEBUF );
142
+ printf ("SDL Recommends %dx%d @%dbpp.\n" , width , height , bpp );
143
+ screen = SDL_SetVideoMode (width , height , bpp , SDL_HWSURFACE | SDL_DOUBLEBUF );
124
144
#if 0
125
145
/* code to display single image : */
126
146
ShowGIF (gifname , screen , 0 ,0 );
@@ -131,9 +151,7 @@ int main(int argc, char* * argv) {
131
151
}
132
152
#endif
133
153
134
- animation = SDL_LoadAnimatedGif (gifname );
135
- printf ("SDL_LoadAnimatedGif(%s) => %p\n" , gifname , animation );
136
- if (animation != NULL ) {
154
+ {
137
155
printf ("%d images\n" , animation -> image_count );
138
156
for (;;)
139
157
for (i = 0 ; i < animation -> image_count ; i ++ ) {
@@ -154,7 +172,7 @@ int main(int argc, char* * argv) {
154
172
if (animation -> image_count > 1 ) {
155
173
if (animation -> images [i ].delay_time == 0 ) {
156
174
SDL_Delay (100 ); /* default delay of 1/10th of seconds */
157
- } else {
175
+ } else if ( animation -> images [ i ]. delay_time > 0 ) {
158
176
SDL_Delay (10 * animation -> images [i ].delay_time );
159
177
}
160
178
while (SDL_PollEvent (& event )) {
0 commit comments