Image Interpolation with Contour Stencils

basic.c

Go to the documentation of this file.
00001 
00026 #include <stdlib.h>
00027 #include <stdarg.h>
00028 #include "basic.h"
00029 
00030 
00032 void *MallocWithErrorMessage(size_t Size)
00033 {
00034     void *Ptr;
00035     
00036     if(!(Ptr = malloc(Size)))
00037         ErrorMessage("Memory allocation of %u bytes failed.\n", Size);
00038         
00039     return Ptr;
00040 }
00041 
00042 
00044 void *ReallocWithErrorMessage(void *Ptr, size_t Size)
00045 {
00046     void *NewPtr;
00047     
00048     if(!(NewPtr = realloc(Ptr, Size)))
00049     {
00050         ErrorMessage("Memory reallocation of %u bytes failed.\n", Size);
00051         Free(Ptr);  /* Free the previous block on failure */
00052     }
00053         
00054     return NewPtr;
00055 }
00056 
00057 
00059 void ErrorMessage(const char *Format, ...)
00060 {
00061     va_list Args;
00062     
00063     va_start(Args, Format);
00064     /* Write a formatted error message to stderr */
00065     vfprintf(stderr, Format, Args);
00066     va_end(Args);
00067 }
00068 
00069 
00070 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
00071 /* Windows: implement with GetSystemTime */
00072         
00073 #define WIN32_LEAN_AND_MEAN
00074 #include <windows.h>
00075 
00076 /* Clock:  Get the system clock in milliseconds */
00077 unsigned long Clock()
00078 {
00079         static SYSTEMTIME TimeVal;
00080         GetSystemTime(&TimeVal);
00081         return (unsigned long)((unsigned long)TimeVal.wMilliseconds
00082                 + 1000*((unsigned long)TimeVal.wSecond
00083                 + 60*((unsigned long)TimeVal.wMinute 
00084                 + 60*((unsigned long)TimeVal.wHour 
00085                 + 24*(unsigned long)TimeVal.wDay))));
00086 }
00087 
00088 #else
00089 /* UNIX: implement with gettimeofday */
00090 
00091 #include <sys/time.h>
00092 #include <unistd.h>
00093 
00094 /* Clock:  Get the system clock in milliseconds */
00095 unsigned long Clock()
00096 {
00097         struct timeval TimeVal;
00098         gettimeofday(&TimeVal, NULL); 
00099         return (unsigned long)(TimeVal.tv_usec/1000 + TimeVal.tv_sec*1000);
00100 }
00101 
00102 #endif
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines