#include "ninox.h" #ifdef MSWIN32 #include #endif // malloc() with error trapping void * Malloc(int nbytes) { unsigned char *buf = malloc(nbytes); if (! buf) { Print("Malloc: Out of Memory\n"); exit(1); } return buf; } void * ZeroMalloc(int nbytes) { unsigned char *buf = Malloc(nbytes); int i; for(i=0; idepth == 16) I = img; else { I = ConvertImage(img,img->type,16); last_needs_destroy = 1; } if (DisplayFrames) { int x1,y1; d_width = I->width; d_height = I->height; // make sure the display width is a multiple of 4 d_width = (d_width+3) & ~3; // If the image dimensions have changed then shutdown and restart the display if (HaveWindow && (d_width > GetDisplayWidth() || d_height > GetDisplayHeight())) { ShutdownDisplay(); HaveWindow = 0; } if (! HaveWindow) { int Depth = 16; HaveWindow = InitDisplay("Ninox",d_width,d_height,Depth); InitProperties(); InitDisplay(); } if (! HaveWindow) { int Depth = 32; HaveWindow = InitDisplay("VideoShow",d_width,d_height,Depth); } if (! HaveWindow) { Message("Cannot start SDL, display disabled"); DisplayFrames = 0; } if (HaveWindow) { int kb; if (prop<0) prop = CreateProperty(0,1.0,1.0); y1 = (d_height - I->dst_height)/2; x1 = (d_width - I->dst_width)/2; DisplayImage(I,prop,x1,y1); if (DisplayPause) while(PollKeyboard() != 2) {Usleep(100);} else PollKeyboard(); } } } #undef malloc #undef free // Code taken from man page for vsprintf() int Print(char *fmt, ...) { /* Guess we need no more than 100 bytes. */ int n, size = 100; char *p; va_list ap; static int start_of_line = 1; FILE *fd = stdout; if ((p = (char *)malloc (size)) == NULL) { fprintf(fd,"Print: Out of memory!\n"); fflush(fd); return 0; } while (1) { /* Try to print in the allocated space. */ va_start(ap, fmt); n = vsnprintf (p, size, fmt, ap); va_end(ap); /* If that worked, return the string. */ if (n > -1 && n < size) { for(n=0; n -1) /* glibc 2.1 */ size = n+1; /* precisely what is needed */ else /* glibc 2.0 */ size *= 2; /* twice the old size */ if ((p = realloc (p, size)) == NULL) { fprintf(fd,"Print: Out of memory!\n"); fflush(fd); return 0; } } // notreached fflush(fd); return 0; }