forked from ExternalVendorCode/Signal-Server
Tidy up and typedef structs for ease of maintenance
This commit is contained in:
10
image-ppm.cc
10
image-ppm.cc
@@ -4,7 +4,7 @@
|
||||
#include <errno.h>
|
||||
#include "image.hh"
|
||||
|
||||
int ppm_init(PIMAGE_CTX ctx){
|
||||
int ppm_init(image_ctx_t *ctx){
|
||||
size_t buf_size;
|
||||
|
||||
/* Perform simple sanity checking */
|
||||
@@ -12,7 +12,7 @@ int ppm_init(PIMAGE_CTX ctx){
|
||||
return EINVAL;
|
||||
ctx->model = IMAGE_RGB; //Override this as we only support RGB
|
||||
ctx->format = IMAGE_PPM;
|
||||
ctx->extension = ".ppm";
|
||||
ctx->extension = (char*)".ppm";
|
||||
|
||||
buf_size = ctx->width * ctx->height * RGB_SIZE;
|
||||
|
||||
@@ -25,7 +25,7 @@ int ppm_init(PIMAGE_CTX ctx){
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ppm_add_pixel(PIMAGE_CTX ctx,const uint8_t r,const uint8_t g,const uint8_t b,const uint8_t a){
|
||||
int ppm_add_pixel(image_ctx_t *ctx,const uint8_t r,const uint8_t g,const uint8_t b,const uint8_t a){
|
||||
register uint8_t* next;
|
||||
|
||||
next = ctx->next_pixel;
|
||||
@@ -39,12 +39,12 @@ int ppm_add_pixel(PIMAGE_CTX ctx,const uint8_t r,const uint8_t g,const uint8_t b
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ppm_get_pixel(PIMAGE_CTX ctx,const size_t x,const size_t y,const uint8_t *r,const uint8_t *g,const uint8_t *b,const uint8_t *a){
|
||||
int ppm_get_pixel(image_ctx_t *ctx,const size_t x,const size_t y,const uint8_t *r,const uint8_t *g,const uint8_t *b,const uint8_t *a){
|
||||
/* STUB */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ppm_write(PIMAGE_CTX ctx, FILE* fd){
|
||||
int ppm_write(image_ctx_t *ctx, FILE* fd){
|
||||
size_t written;
|
||||
size_t count;
|
||||
|
||||
|
16
image-ppm.hh
16
image-ppm.hh
@@ -4,10 +4,18 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include "image.hh"
|
||||
|
||||
int ppm_init(PIMAGE_CTX ctx);
|
||||
int ppm_add_pixel(PIMAGE_CTX ctx,const uint8_t r,const uint8_t g,const uint8_t b,const uint8_t a);
|
||||
int ppm_get_pixel(PIMAGE_CTX ctx,const size_t x,const size_t y,const uint8_t *r,const uint8_t *g,const uint8_t *b,const uint8_t *a);
|
||||
int ppm_write(PIMAGE_CTX ctx, FILE* fd);
|
||||
int ppm_init(image_ctx_t *ctx);
|
||||
int ppm_add_pixel(image_ctx_t *ctx,const uint8_t r,const uint8_t g,const uint8_t b,const uint8_t a);
|
||||
int ppm_get_pixel(image_ctx_t *ctx,const size_t x,const size_t y,const uint8_t *r,const uint8_t *g,const uint8_t *b,const uint8_t *a);
|
||||
int ppm_write(image_ctx_t *ctx, FILE* fd);
|
||||
|
||||
image_dispatch_table_t ppm_dt = {\
|
||||
.init = ppm_init, \
|
||||
.add_pixel = ppm_add_pixel, \
|
||||
.get_pixel = ppm_get_pixel, \
|
||||
.write = ppm_write
|
||||
};
|
||||
|
||||
#endif
|
69
image.cc
69
image.cc
@@ -14,22 +14,10 @@
|
||||
#include "image.hh"
|
||||
#include "image-ppm.hh"
|
||||
|
||||
typedef int _init(PIMAGE_CTX);
|
||||
typedef int _add_pixel(PIMAGE_CTX,const uint8_t,const uint8_t,const uint8_t,const uint8_t);
|
||||
typedef int _get_pixel(PIMAGE_CTX,const size_t,const size_t,const uint8_t*,const uint8_t*,const uint8_t*,const uint8_t*);
|
||||
typedef int _write(PIMAGE_CTX,FILE*);
|
||||
int get_dt(image_dispatch_table_t *dt, int format);
|
||||
int load_library(image_dispatch_table_t *dt);
|
||||
|
||||
int get_dt(struct image_dispatch_table *dt, IMAGE_FORMAT format);
|
||||
int load_library(struct image_dispatch_table *dt);
|
||||
|
||||
struct image_dispatch_table{
|
||||
_init *init;
|
||||
_add_pixel *add_pixel;
|
||||
_get_pixel *get_pixel;
|
||||
_write *write;
|
||||
};
|
||||
|
||||
static IMAGE_FORMAT default_format = IMAGE_PPM;
|
||||
static int default_format = IMAGE_PPM;
|
||||
char *dynamic_backend = NULL;
|
||||
|
||||
/*
|
||||
@@ -37,7 +25,7 @@ char *dynamic_backend = NULL;
|
||||
* Changes the default format for the next
|
||||
* uninitialized image canvas
|
||||
*/
|
||||
int image_set_format(IMAGE_FORMAT format){
|
||||
int image_set_format(int format){
|
||||
if(format <= IMAGE_DEFAULT || format >= IMAGE_FORMAT_MAX)
|
||||
return EINVAL;
|
||||
default_format = format;
|
||||
@@ -49,14 +37,14 @@ int image_set_format(IMAGE_FORMAT format){
|
||||
* Initialize an image context. Must be called
|
||||
* before attempting to write any image data
|
||||
*/
|
||||
int image_init(PIMAGE_CTX ctx, \
|
||||
int image_init(image_ctx_t *ctx, \
|
||||
const size_t width, \
|
||||
const size_t height, \
|
||||
const IMAGE_MODEL model, \
|
||||
const IMAGE_FORMAT format) {
|
||||
const int model, \
|
||||
const int format) {
|
||||
|
||||
int success = 0;
|
||||
struct image_dispatch_table *dt;
|
||||
image_dispatch_table_t *dt;
|
||||
|
||||
/* Perform some sanity checking on provided arguments */
|
||||
if(ctx == NULL)
|
||||
@@ -68,7 +56,7 @@ int image_init(PIMAGE_CTX ctx, \
|
||||
if(format >= IMAGE_FORMAT_MAX || (format == IMAGE_LIBRARY && dynamic_backend == NULL))
|
||||
return EINVAL;
|
||||
|
||||
memset(ctx,0x00,sizeof(IMAGE_CTX));
|
||||
memset(ctx,0x00,sizeof(image_ctx_t));
|
||||
|
||||
/* Assign the initialize values to the processing context */
|
||||
ctx->width = width;
|
||||
@@ -80,7 +68,7 @@ int image_init(PIMAGE_CTX ctx, \
|
||||
ctx->format = format;
|
||||
|
||||
/* Get the dispatch table for this image format */
|
||||
dt = (struct image_dispatch_table*) calloc(1,sizeof(struct image_dispatch_table));
|
||||
dt = (image_dispatch_table_t *) calloc(1,sizeof(image_dispatch_table_t));
|
||||
if(dt == NULL){
|
||||
fprintf(stderr,"Error allocating dispatch table\n");
|
||||
return ENOMEM;
|
||||
@@ -111,30 +99,26 @@ int image_init(PIMAGE_CTX ctx, \
|
||||
* takes an open file handle and writes image data to it.
|
||||
* These functions simply wrap the underlying format-specific functions
|
||||
*/
|
||||
int image_add_pixel(PIMAGE_CTX ctx, const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t a){
|
||||
struct image_dispatch_table *dt = (struct image_dispatch_table*)ctx->_dt;
|
||||
int image_add_pixel(image_ctx_t *ctx, const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t a){
|
||||
if(ctx->initialized != 1) return EINVAL;
|
||||
return dt->add_pixel(ctx,r,g,b,a);
|
||||
return ((image_dispatch_table_t*)ctx->_dt)->add_pixel(ctx,r,g,b,a);
|
||||
}
|
||||
int image_set_pixel(PIMAGE_CTX ctx, const size_t x, const size_t y, const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t a){
|
||||
int image_set_pixel(image_ctx_t *ctx, const size_t x, const size_t y, const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t a){
|
||||
size_t block_size;
|
||||
if(ctx->initialized != 1) return EINVAL;
|
||||
block_size = ctx->model == IMAGE_RGB ? RGB_SIZE : RGBA_SIZE;
|
||||
ctx->next_pixel = ctx->canvas + (x * block_size) + (ctx->width * block_size * y);
|
||||
struct image_dispatch_table *dt = (struct image_dispatch_table*)ctx->_dt;
|
||||
return dt->add_pixel(ctx,r,g,b,a);
|
||||
ctx->next_pixel = ctx->canvas + PIXEL_OFFSET(x,y,ctx->width,block_size);
|
||||
return ((image_dispatch_table_t*)ctx->_dt)->add_pixel(ctx,r,g,b,a);
|
||||
}
|
||||
int image_get_pixel(PIMAGE_CTX ctx, const size_t x, const size_t y, const uint8_t *r, const uint8_t *g, const uint8_t *b, const uint8_t *a){
|
||||
struct image_dispatch_table *dt = (struct image_dispatch_table*)ctx->_dt;
|
||||
int image_get_pixel(image_ctx_t *ctx, const size_t x, const size_t y, const uint8_t *r, const uint8_t *g, const uint8_t *b, const uint8_t *a){
|
||||
if(ctx->initialized != 1) return EINVAL;
|
||||
return dt->get_pixel(ctx,x,y,r,g,b,a);
|
||||
return ((image_dispatch_table_t*)ctx->_dt)->get_pixel(ctx,x,y,r,g,b,a);
|
||||
}
|
||||
int image_write(PIMAGE_CTX ctx, FILE *fd){
|
||||
struct image_dispatch_table *dt = (struct image_dispatch_table*)ctx->_dt;
|
||||
int image_write(image_ctx_t *ctx, FILE *fd){
|
||||
if(ctx->initialized != 1) return EINVAL;
|
||||
return dt->write(ctx,fd);
|
||||
return ((image_dispatch_table_t*)ctx->_dt)->write(ctx,fd);
|
||||
}
|
||||
void image_free(PIMAGE_CTX ctx){
|
||||
void image_free(image_ctx_t *ctx){
|
||||
if(ctx->initialized != 1) return;
|
||||
free(ctx->canvas);
|
||||
}
|
||||
@@ -145,7 +129,7 @@ void image_free(PIMAGE_CTX ctx){
|
||||
* by the user. If the extension is already correct, return
|
||||
* that; if not append if there is space
|
||||
*/
|
||||
int image_get_filename(PIMAGE_CTX ctx, char *out, size_t len_out, char *in){
|
||||
int image_get_filename(image_ctx_t *ctx, char *out, size_t len_out, char *in){
|
||||
size_t len_src;
|
||||
size_t len_ext;
|
||||
int success = 0;
|
||||
@@ -188,16 +172,13 @@ int image_get_filename(PIMAGE_CTX ctx, char *out, size_t len_out, char *in){
|
||||
* Load the dispatch table for the specified image
|
||||
* format. Currently only pixmap supported.
|
||||
*/
|
||||
int get_dt(struct image_dispatch_table *dt, IMAGE_FORMAT format){
|
||||
int get_dt(image_dispatch_table_t *dt, int format){
|
||||
int success = 0;
|
||||
|
||||
memset((void*)dt,0x00,sizeof(struct image_dispatch_table));
|
||||
memset((void*)dt,0x00,sizeof(image_dispatch_table_t));
|
||||
switch(format){
|
||||
case IMAGE_PPM:
|
||||
dt->init = ppm_init;
|
||||
dt->add_pixel = ppm_add_pixel;
|
||||
dt->get_pixel = ppm_get_pixel;
|
||||
dt->write = ppm_write;
|
||||
*dt = ppm_dt;
|
||||
break;
|
||||
case IMAGE_LIBRARY:
|
||||
success = load_library(dt);
|
||||
@@ -248,7 +229,7 @@ char* image_get_library(){
|
||||
* Load an external library to perform image processing
|
||||
* It must be a custom compatible library
|
||||
*/
|
||||
int load_library(struct image_dispatch_table *dt){
|
||||
int load_library(image_dispatch_table_t *dt){
|
||||
void *hndl;
|
||||
int success = 0;
|
||||
|
||||
|
56
image.hh
56
image.hh
@@ -6,40 +6,54 @@
|
||||
#define RGB_SIZE 3
|
||||
#define RGBA_SIZE 4
|
||||
|
||||
typedef enum _IMAGE_FORMAT{ IMAGE_DEFAULT = 0, \
|
||||
IMAGE_PPM, \
|
||||
IMAGE_LIBRARY, \
|
||||
IMAGE_FORMAT_MAX \
|
||||
} IMAGE_FORMAT;
|
||||
enum _image_format{ IMAGE_DEFAULT = 0, \
|
||||
IMAGE_PPM, \
|
||||
IMAGE_LIBRARY, \
|
||||
IMAGE_FORMAT_MAX \
|
||||
};
|
||||
|
||||
typedef enum _IMAGE_MODEL{ IMAGE_RGB, \
|
||||
IMAGE_RGBA, \
|
||||
IMAGE_MODEL_MAX
|
||||
} IMAGE_MODEL;
|
||||
enum _image_model{ IMAGE_RGB, \
|
||||
IMAGE_RGBA, \
|
||||
IMAGE_MODEL_MAX
|
||||
};
|
||||
|
||||
typedef struct _IMAGE_CTX{
|
||||
typedef struct _image_ctx{
|
||||
size_t width;
|
||||
size_t height;
|
||||
IMAGE_MODEL model;
|
||||
IMAGE_FORMAT format;
|
||||
int model;
|
||||
int format;
|
||||
uint8_t *canvas;
|
||||
uint8_t *next_pixel;
|
||||
uint32_t initialized;
|
||||
char *extension;
|
||||
void *_dt;
|
||||
} IMAGE_CTX, *PIMAGE_CTX;
|
||||
} image_ctx_t, *pimage_ctx_t;
|
||||
|
||||
int image_set_format(IMAGE_FORMAT);
|
||||
int image_init(PIMAGE_CTX, const size_t, const size_t, const IMAGE_MODEL, const IMAGE_FORMAT);
|
||||
int image_add_pixel(PIMAGE_CTX ctx, const uint8_t, const uint8_t, const uint8_t, const uint8_t);
|
||||
int image_set_pixel(PIMAGE_CTX ctx, const size_t, const size_t, const uint8_t, const uint8_t, const uint8_t, const uint8_t);
|
||||
int image_get_pixel(PIMAGE_CTX ctx,const size_t,const size_t, uint8_t const*, uint8_t const*, uint8_t const*, uint8_t const*);
|
||||
int image_get_filename(PIMAGE_CTX, char*, size_t, char*);
|
||||
int image_write(PIMAGE_CTX, FILE*);
|
||||
void image_free(PIMAGE_CTX);
|
||||
typedef int _init(image_ctx_t*);
|
||||
typedef int _add_pixel(image_ctx_t*,const uint8_t,const uint8_t,const uint8_t,const uint8_t);
|
||||
typedef int _get_pixel(image_ctx_t*,const size_t,const size_t,const uint8_t*,const uint8_t*,const uint8_t*,const uint8_t*);
|
||||
typedef int _write(image_ctx_t*,FILE*);
|
||||
|
||||
typedef struct _image_dispatch_table{
|
||||
_init *init;
|
||||
_add_pixel *add_pixel;
|
||||
_get_pixel *get_pixel;
|
||||
_write *write;
|
||||
} image_dispatch_table_t;
|
||||
|
||||
int image_set_format(int);
|
||||
int image_init(image_ctx_t*, const size_t, const size_t, const int, const int);
|
||||
int image_add_pixel(image_ctx_t* ctx, const uint8_t, const uint8_t, const uint8_t, const uint8_t);
|
||||
int image_set_pixel(image_ctx_t* ctx, const size_t, const size_t, const uint8_t, const uint8_t, const uint8_t, const uint8_t);
|
||||
int image_get_pixel(image_ctx_t* ctx,const size_t,const size_t, uint8_t const*, uint8_t const*, uint8_t const*, uint8_t const*);
|
||||
int image_get_filename(image_ctx_t*, char*, size_t, char*);
|
||||
int image_write(image_ctx_t*, FILE*);
|
||||
void image_free(image_ctx_t*);
|
||||
int image_set_library(char*);
|
||||
|
||||
#define ADD_PIXEL(ctx,r,g,b) image_add_pixel((ctx),(r),(g),(b),0xff)
|
||||
#define ADD_PIXELA(ctx,r,g,b,a) image_add_pixel((ctx),(r),(g),(b),(a))
|
||||
|
||||
#define PIXEL_OFFSET(x,y,width,pixel_size) (((x) * (pixel_size)) + ((width) * (pixel_size) * (y)))
|
||||
|
||||
#endif
|
@@ -31,7 +31,7 @@ void DoPathLoss(char *filename, unsigned char geo, unsigned char kml,
|
||||
int indx, x, y, z, x0 = 0, y0 = 0, loss, match;
|
||||
double lat, lon, conversion, one_over_gamma, minwest;
|
||||
FILE *fd;
|
||||
IMAGE_CTX ctx;
|
||||
image_ctx_t ctx;
|
||||
int success;
|
||||
|
||||
if((success = image_init(&ctx, width, (kml ? height : height + 30), IMAGE_RGB, IMAGE_DEFAULT)) != 0){
|
||||
@@ -271,7 +271,7 @@ void DoSigStr(char *filename, unsigned char geo, unsigned char kml,
|
||||
int indx, x, y, z = 1, x0 = 0, y0 = 0, signal, match;
|
||||
double conversion, one_over_gamma, lat, lon, minwest;
|
||||
FILE *fd;
|
||||
IMAGE_CTX ctx;
|
||||
image_ctx_t ctx;
|
||||
int success;
|
||||
|
||||
if((success = image_init(&ctx, width, (kml ? height : height + 30), IMAGE_RGB, IMAGE_DEFAULT)) != 0){
|
||||
@@ -519,7 +519,7 @@ void DoRxdPwr(char *filename, unsigned char geo, unsigned char kml,
|
||||
int indx, x, y, z = 1, x0 = 0, y0 = 0, dBm, match;
|
||||
double conversion, one_over_gamma, lat, lon, minwest;
|
||||
FILE *fd;
|
||||
IMAGE_CTX ctx;
|
||||
image_ctx_t ctx;
|
||||
int success;
|
||||
|
||||
if((success = image_init(&ctx, width, (kml ? height : height + 30), IMAGE_RGB, IMAGE_DEFAULT)) != 0){
|
||||
@@ -762,7 +762,7 @@ void DoLOS(char *filename, unsigned char geo, unsigned char kml,
|
||||
int indx, x, y, x0 = 0, y0 = 0;
|
||||
double conversion, one_over_gamma, lat, lon, minwest;
|
||||
FILE *fd;
|
||||
IMAGE_CTX ctx;
|
||||
image_ctx_t ctx;
|
||||
int success;
|
||||
|
||||
if((success = image_init(&ctx, width, (kml ? height : height + 30), IMAGE_RGB, IMAGE_DEFAULT)) != 0){
|
||||
|
Reference in New Issue
Block a user