Coin Logo Coin3D is Free Software,
published under the BSD 3-clause license.
https://coin3d.github.io
https://www.kongsberg.com/en/kogt/
Data Structures | Macros | Typedefs | Functions | Variables
simage.c File Reference
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <config.h>
#include <simage.h>
#include <simage_private.h>
#include <string.h>

Go to the source code of this file.

Data Structures

struct  _loader_data
 

Macros

#define SIMAGE_ERROR_BUFSIZE   512
 

Typedefs

typedef struct _loader_data loader_data
 

Functions

static void * add_loader (loader_data *loader, unsigned char *(*load_func)(const char *, int *, int *, int *), int(*identify_func)(const char *, const unsigned char *, int headerlen), int(*error_func)(char *, int), int is_internal, int addbefore)
 
static loader_datafind_loader (const char *filename)
 
static void add_internal_loaders (void)
 
unsigned char * simage_read_image (const char *filename, int *width, int *height, int *numComponents)
 
const char * simage_get_last_error (void)
 
void simage_clear_error (void)
 
int simage_check_supported (const char *filename)
 
void * simage_add_loader (const struct simage_plugin *plugin, int addbefore)
 
void simage_remove_loader (void *handle)
 
static int cnt_bits (int val, int *highbit)
 
int simage_next_power_of_two (int val)
 
void simage_version (int *major, int *minor, int *micro)
 
void simage_free_image (unsigned char *imagedata)
 
s_images_image_open (const char *filename, int oktoreadall)
 
int s_image_read_line (s_image *image, int line, unsigned char *buf)
 
void s_set_dynamic_loader_interface (s_dlopen_func *dlopen_func, s_dlsym_func *dlsym_func, s_dlclose_func *dlclose_func)
 

Variables

static loader_datafirst_loader = NULL
 
static loader_datalast_loader = NULL
 
char simage_error_msg [512+1]
 
static s_dlopen_funcdlopen = NULL
 
static s_dlsym_funcdlsym = NULL
 
static s_dlclose_funcdlclose = NULL
 

Macro Definition Documentation

#define SIMAGE_ERROR_BUFSIZE   512

Definition at line 288 of file simage.c.

Referenced by simage_read_image().

Typedef Documentation

typedef struct _loader_data loader_data

Definition at line 38 of file simage.c.

Function Documentation

static void add_internal_loaders ( void  )
static
static void* add_loader ( loader_data loader,
unsigned char *(*)(const char *, int *, int *, int *)  load_func,
int(*)(const char *, const unsigned char *, int headerlen)  identify_func,
int(*)(char *, int)  error_func,
int  is_internal,
int  addbefore 
)
static
static int cnt_bits ( int  val,
int *  highbit 
)
static

Definition at line 370 of file simage.c.

Referenced by simage_next_power_of_two().

static loader_data* find_loader ( const char *  filename)
static
s_image* s_image_open ( const char *  filename,
int  oktoreadall 
)
int s_image_read_line ( s_image image,
int  line,
unsigned char *  buf 
)
void s_set_dynamic_loader_interface ( s_dlopen_func dlopen_func,
s_dlsym_func dlsym_func,
s_dlclose_func dlclose_func 
)

Definition at line 495 of file simage.c.

void* simage_add_loader ( const struct simage_plugin plugin,
int  addbefore 
)
int simage_check_supported ( const char *  filename)

Checks if image file format is supported. Returns 1 if filename can be loaded, 0 otherwise.

Definition at line 328 of file simage.c.

References add_internal_loaders(), and find_loader().

void simage_clear_error ( void  )
void simage_free_image ( unsigned char *  imagedata)

Free resources allocated by either simage_read_image() or simage_resize() (Windows goes berzerk if you call free() from the client application)

Definition at line 406 of file simage.c.

Referenced by s_image_load().

const char* simage_get_last_error ( void  )

Returns error message, which is set when simage_read_image returned NULL or simage_write_image returns 0.

Definition at line 319 of file simage.c.

References simage_error_msg.

int simage_next_power_of_two ( int  val)

Returns the first 2^n bigger or equal to val. If simage_next_power_of_two(size) != size, you'll typically need to resize your image to be able to use it in an OpenGL app.

Definition at line 383 of file simage.c.

References cnt_bits().

unsigned char* simage_read_image ( const char *  filename,
int *  width,
int *  height,
int *  numcomponents 
)

Attempts to read filename, and return a pointer to the image data. NULL is returned if the image could not be loaded. The memory is allocated using malloc(), and it is the callers responsibility to free the memory (using free()) width and height contains the width and height of the image, and numcomponents is a number indicating the following:

1 : Grayscale image (GL_LUMINANCE) 2 : Grayscale with alpha channel (GL_LUMINANCE_ALPHA) 3 : RGB data (GL_RGB) 4 : RGB data with alpha component (GL_RGBA)

Returned image buffer must be freed by simage_free_image()

Definition at line 292 of file simage.c.

References add_internal_loaders(), simage_plugin::error_func, find_loader(), _loader_data::funcs, simage_plugin::load_func, and SIMAGE_ERROR_BUFSIZE.

Referenced by s_image_load(), and s_image_read_line().

void simage_remove_loader ( void *  handle)

Definition at line 346 of file simage.c.

References first_loader, and _loader_data::next.

void simage_version ( int *  major,
int *  minor,
int *  micro 
)

Note specifically for Microsoft Windows that by leaving out the APIENTRY keyword for the function definitions, we default to the __cdecl calling convention. This is important to take into consideration when explicitly linking to the library at runtime: when using the wrong calling convention, obscure errors due to stack corruption can occur under certain (possibly rare) conditions.

Returns runtime version for simage.

Definition at line 398 of file simage.c.

Variable Documentation

s_dlclose_func* dlclose = NULL
static

Definition at line 492 of file simage.c.

s_dlopen_func* dlopen = NULL
static

Definition at line 490 of file simage.c.

s_dlsym_func* dlsym = NULL
static

Definition at line 491 of file simage.c.

loader_data* first_loader = NULL
static

Definition at line 100 of file simage.c.

Referenced by add_loader(), find_loader(), and simage_remove_loader().

loader_data* last_loader = NULL
static

Definition at line 101 of file simage.c.

char simage_error_msg[512+1]

Definition at line 289 of file simage.c.

Referenced by simage_get_last_error().