Linear Methods for Image Interpolation
Defines | Functions
basic.h File Reference

Memory management, portable types, timing, and math constants. More...

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
Include dependency graph for basic.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define Malloc(s)   MallocWithErrorMessage(s)
 Function to allocate a block of memory.
#define Realloc(p, s)   ReallocWithErrorMessage(p, s)
 Function to reallocate a block of memory.
#define Free(p)   free(p)
 Function to free memory.
#define M_2PI   6.28318530717958647692528676655900576
 The constant 2 pi.
#define M_PI   3.14159265358979323846264338327950288
 The constant pi.
#define M_PI_2   1.57079632679489661923132169163975144
 The constant pi/2.
#define M_PI_4   0.78539816339744830961566084581987572
 The constant pi/4.
#define M_PI_8   0.39269908169872415480783042290993786
 The constant pi/8.
#define M_SQRT2   1.41421356237309504880168872420969808
 The constant sqrt(2)
#define M_1_SQRT2   0.70710678118654752440084436210484904
 The constant 1/sqrt(2)
#define M_E   2.71828182845904523536028747135266250
 The natural number.
#define M_LOG2E   1.44269504088896340735992468100189213
 Log base 2 of the natural number.
#define M_LOG10E   0.43429448190325182765112891891660508
 Log base 10 of the natural number.
#define M_LN2   0.69314718055994530941723212145817657
 Natural log of 2.
#define M_LN10   2.30258509299404568401799145468436421
 Natural log of 10.
#define M_EULER   0.57721566490153286060651209008240243
 Euler number.
#define ROUND(X)   (floor((X) + 0.5))
 Round double X.
#define ROUNDF(X)   (floor((X) + 0.5f))
 Round float X.
#define ATTRIBUTE_UNUSED
#define ATTRIBUTE_ALWAYSINLINE

Functions

void * MallocWithErrorMessage (size_t Size)
 malloc with an error message on failure.
void * ReallocWithErrorMessage (void *Ptr, size_t Size)
 realloc with an error message and free on failure.
unsigned long Clock ()
 Time in milliseconds, useful for measuring elapsed time.
void ErrorMessage (const char *Format,...)
 Redefine this function to customize error messages.

Detailed Description

Memory management, portable types, timing, and math constants.

Author:
Pascal Getreuer <getreuer@gmail.com>

The purpose of this file is to gather useful nonportable C features and then use compiler-defined symbols so that the right thing happens most of the time automatically. This way, if changes are required for your platform, hopefully only this file and possibly also basic.c need to be changed.

For memory management, macros Malloc, Realloc, and Free are defined here, which can be modified to customize memory management.

Types uint8_t, uint16_t, uint32_t are defined as unsigned integer types such that

Similarly, int8_t, int16_t, int32_t are defined as signed integer types such that

These definitions are implemented with types __int8, __int16, and __int32 under Windows and by including stdint.h under UNIX.

A millisecond-precision timer Clock() is defined. There is no portable ANSI C millisecond timer, so Clock is defined depending on the platform. On Windows systems, Clock is implemented using GetSystemTime. On POSIX systems, Clock uses gettimeofday. If the system is neither POSIX nor Windows, the time.h time function is used as a fallback, which has only second accuracy.

To define the math constants, math.h is included, and any of the following that were not defined by math.h are defined here according to the values from Hart & Cheney.

Copyright (c) 2010-2011, Pascal Getreuer All rights reserved.

This program is free software: you can use, modify and/or redistribute it under the terms of the simplified BSD License. You should have received a copy of this license along this program. If not, see <http://www.opensource.org/licenses/bsd-license.html>.

Definition in file basic.h.


Define Documentation

#define ATTRIBUTE_ALWAYSINLINE

Definition at line 201 of file basic.h.

#define ATTRIBUTE_UNUSED

Definition at line 200 of file basic.h.

#define Free (   p)    free(p)

Function to free memory.

Definition at line 80 of file basic.h.

#define M_1_SQRT2   0.70710678118654752440084436210484904

The constant 1/sqrt(2)

Definition at line 156 of file basic.h.

#define M_2PI   6.28318530717958647692528676655900576

The constant 2 pi.

Definition at line 132 of file basic.h.

#define M_E   2.71828182845904523536028747135266250

The natural number.

Definition at line 160 of file basic.h.

#define M_EULER   0.57721566490153286060651209008240243

Euler number.

Definition at line 180 of file basic.h.

#define M_LN10   2.30258509299404568401799145468436421

Natural log of 10.

Definition at line 176 of file basic.h.

#define M_LN2   0.69314718055994530941723212145817657

Natural log of 2.

Definition at line 172 of file basic.h.

#define M_LOG10E   0.43429448190325182765112891891660508

Log base 10 of the natural number.

Definition at line 168 of file basic.h.

#define M_LOG2E   1.44269504088896340735992468100189213

Log base 2 of the natural number.

Definition at line 164 of file basic.h.

#define M_PI   3.14159265358979323846264338327950288

The constant pi.

Definition at line 136 of file basic.h.

#define M_PI_2   1.57079632679489661923132169163975144

The constant pi/2.

Definition at line 140 of file basic.h.

#define M_PI_4   0.78539816339744830961566084581987572

The constant pi/4.

Definition at line 144 of file basic.h.

#define M_PI_8   0.39269908169872415480783042290993786

The constant pi/8.

Definition at line 148 of file basic.h.

#define M_SQRT2   1.41421356237309504880168872420969808

The constant sqrt(2)

Definition at line 152 of file basic.h.

#define Malloc (   s)    MallocWithErrorMessage(s)

Function to allocate a block of memory.

Definition at line 74 of file basic.h.

#define Realloc (   p,
 
)    ReallocWithErrorMessage(p, s)

Function to reallocate a block of memory.

Definition at line 77 of file basic.h.

#define ROUND (   X)    (floor((X) + 0.5))

Round double X.

Definition at line 184 of file basic.h.

#define ROUNDF (   X)    (floor((X) + 0.5f))

Round float X.

Definition at line 187 of file basic.h.


Function Documentation

unsigned long Clock ( )

Time in milliseconds, useful for measuring elapsed time.

Returns:
Number of milliseconds since an arbitrary point

This routine obtains the system time with millisecond precision. There is no portable ANSI C millisecond timer, so Clock is defined depending on the platform. On POSIX systems, Clock uses gettimeofday. Otherwise, if the system is Windows, GetSystemTime is used. If the system is neither POSIX nor Windows, the low-resolution time.h clock function is used as a fallback.

Use this function as

     unsigned long Start, Stop;
     Start = Clock();
     BigComputation();
     Stop = Clock();
     printf("Elapsed time: %.3f\n", 0.001f*(Stop - Start));

Definition at line 75 of file basic.c.

Here is the caller graph for this function:

void ErrorMessage ( const char *  Format,
  ... 
)

Redefine this function to customize error messages.

Definition at line 117 of file basic.c.

Here is the caller graph for this function:

void* MallocWithErrorMessage ( size_t  Size)

malloc with an error message on failure.

Definition at line 90 of file basic.c.

Here is the call graph for this function:

void* ReallocWithErrorMessage ( void *  Ptr,
size_t  Size 
)

realloc with an error message and free on failure.

Definition at line 102 of file basic.c.

Here is the call graph for this function:

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines