Skip to content

Commit

Permalink
Fix driver compatibility with R15B
Browse files Browse the repository at this point in the history
  • Loading branch information
dgud committed Jan 9, 2012
1 parent 21f0823 commit 4f3a3ff
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 67 deletions.
69 changes: 45 additions & 24 deletions plugins_src/accel/perlin_noise_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
#include <windows.h>
#endif

#if (ERL_DRV_EXTENDED_MAJOR_VERSION < 2)
/* R14B or earlier types */
#define ErlDrvSizeT int
#define ErlDrvSSizeT int
#endif

#include <math.h>
#include <string.h>

Expand Down Expand Up @@ -57,9 +63,9 @@ double snoise4( double x, double y, double z, double w );
*/
static ErlDrvData perlin_noise_start(ErlDrvPort port, char *buff);
static void perlin_noise_stop(ErlDrvData handle);
static int control(ErlDrvData handle, unsigned int command,
char* buff, int count,
char** res, int res_size);
static ErlDrvSSizeT control(ErlDrvData handle, unsigned int command,
char* buff, ErlDrvSizeT count,
char** res, ErlDrvSizeT res_size);

/*
* Internal routines
Expand All @@ -82,7 +88,17 @@ ErlDrvEntry perlin_file_driver_entry = {
NULL, /* void * that is not used (BC) */
control, /* F_PTR control, port_control callback */
NULL, /* F_PTR timeout, driver_set_timer callback */
NULL /* F_PTR outputv, reserved */
NULL, /* F_PTR outputv, reserved */
NULL, /* async */
NULL, /* flush */
NULL, /* call */
NULL, /* Event */
ERL_DRV_EXTENDED_MARKER,
ERL_DRV_EXTENDED_MAJOR_VERSION,
ERL_DRV_EXTENDED_MINOR_VERSION,
ERL_DRV_FLAG_USE_PORT_LOCKING, /* Port lock */
NULL, /* Reserved Handle */
NULL, /* Process Exited */
};

/*
Expand Down Expand Up @@ -114,52 +130,57 @@ static void perlin_noise_stop(ErlDrvData handle)

}

static int control(ErlDrvData handle, unsigned int command,
char* buff, int count,
char** res, int res_size)
static ErlDrvSSizeT control(ErlDrvData handle, unsigned int command,
char* buff, ErlDrvSizeT count,
char** res, ErlDrvSizeT res_size)
{
ErlDrvBinary* bin;

switch (command) {

case PNOISE3: {
double f[3];
double f[3], *ptr;
memcpy(f, buff, sizeof(double)*3);
bin = driver_alloc_binary(sizeof(double));
* (double *) bin->orig_bytes = pnoise(f[0], f[1], f[2]);
ptr = (double *) bin->orig_bytes;
*ptr = pnoise(f[0], f[1], f[2]);
*res = (char *) bin;
return sizeof(double);
}

case SNOISE1: {
double f[1];
double f[1], *ptr;
memcpy(f, buff, sizeof(double)*1);
bin = driver_alloc_binary(sizeof(double));
* (double *) bin->orig_bytes = snoise1(f[0]);
ptr = (double *) bin->orig_bytes;
*ptr = snoise1(f[0]);
*res = (char *) bin;
return sizeof(double);
}
case SNOISE2: {
double f[2];
double f[2], *ptr;
memcpy(f, buff, sizeof(double)*2);
bin = driver_alloc_binary(sizeof(double));
* (double *) bin->orig_bytes = snoise2(f[0], f[1]);
ptr = (double *) bin->orig_bytes;
*ptr = snoise2(f[0], f[1]);
*res = (char *) bin;
return sizeof(double);
}
case SNOISE3: {
double f[3];
double f[3], *ptr;
memcpy(f, buff, sizeof(double)*3);
bin = driver_alloc_binary(sizeof(double));
* (double *) bin->orig_bytes = snoise3(f[0], f[1], f[2]);
ptr = (double *) bin->orig_bytes;
*ptr = snoise3(f[0], f[1], f[2]);
*res = (char *) bin;
return sizeof(double);
}
case SNOISE4: {
double f[4];
double f[4], *ptr;
memcpy(f, buff, sizeof(double)*4);
bin = driver_alloc_binary(sizeof(double));
* (double *) bin->orig_bytes = snoise4(f[0], f[1], f[2], f[3]);
ptr = (double *) bin->orig_bytes;
*ptr = snoise4(f[0], f[1], f[2], f[3]);
*res = (char *) bin;
return sizeof(double);
}
Expand All @@ -169,7 +190,7 @@ static int control(ErlDrvData handle, unsigned int command,
int sz = * ((unsigned int*) buff);
unsigned char *noise;
bin = driver_alloc_binary(sz);
noise = bin->orig_bytes;
noise = (unsigned char*) bin->orig_bytes;
for(i=0; i < sz ; i++) {
double iv = (double)i/(sz-1);

Expand All @@ -187,7 +208,7 @@ static int control(ErlDrvData handle, unsigned int command,
int i,j;
unsigned char *noise;
bin = driver_alloc_binary(sz*sz);
noise = bin->orig_bytes;
noise = (unsigned char*) bin->orig_bytes;

for(i=0; i < sz ; i++) {
for(j=0; j < sz ; j++) {
Expand All @@ -212,7 +233,7 @@ static int control(ErlDrvData handle, unsigned int command,
int i,j,k;
unsigned char *noise;
bin = driver_alloc_binary(sz*sz*sz);
noise = bin->orig_bytes;
noise = (unsigned char*) bin->orig_bytes;

for(i=0; i < sz ; i++) {
for(j=0; j < sz ; j++) {
Expand All @@ -237,7 +258,7 @@ static int control(ErlDrvData handle, unsigned int command,
int sz = * ((unsigned int*) buff);
unsigned char *noise;
bin = driver_alloc_binary(sz);
noise = bin->orig_bytes;
noise = (unsigned char*) bin->orig_bytes;
for(i=0; i < sz ; i++) {
double
iv = (double)i/(sz-1);
Expand All @@ -255,7 +276,7 @@ static int control(ErlDrvData handle, unsigned int command,
int i,j;
unsigned char *noise;
bin = driver_alloc_binary(sz*sz*4);
noise = bin->orig_bytes;
noise = (unsigned char*) bin->orig_bytes;

for(i=0; i < sz ; i++) {
for(j=0; j < sz ; j++) {
Expand All @@ -276,10 +297,10 @@ static int control(ErlDrvData handle, unsigned int command,
case SNOISE_MAP3: {
int sz = * ((unsigned int*) buff);
int i,j,k;
unsigned char *noise, * ptr;
unsigned char *noise;

bin = driver_alloc_binary(sz*sz*sz*4);
noise = bin->orig_bytes;
noise = (unsigned char*) bin->orig_bytes;

for(i=0; i < sz ; i++) {
double iv = (double)i/(sz-1);
Expand Down
32 changes: 24 additions & 8 deletions plugins_src/accel/wings_pick_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@
#endif
#include <string.h>

#if (ERL_DRV_EXTENDED_MAJOR_VERSION < 2)
/* R14B or earlier types */
#define ErlDrvSizeT int
#define ErlDrvSSizeT int
#endif

/*
* Interface routines.
*/
static ErlDrvData wings_file_start(ErlDrvPort port, char *buff);
static void wings_file_stop(ErlDrvData handle);
static int control(ErlDrvData handle, unsigned int command,
char* buff, int count,
char** res, int res_size);
static ErlDrvSSizeT control(ErlDrvData handle, unsigned int command,
char* buff, ErlDrvSizeT count,
char** res, ErlDrvSizeT res_size);
static void outputv(ErlDrvData drv_data, ErlIOVec* ev);

/*
Expand All @@ -47,7 +53,17 @@ ErlDrvEntry wings_file_driver_entry = {
NULL, /* void * that is not used (BC) */
control, /* F_PTR control, port_control callback */
NULL, /* F_PTR timeout, driver_set_timer callback */
outputv /* F_PTR outputv, reserved */
outputv, /* F_PTR outputv, reserved */
NULL, /* async */
NULL, /* flush */
NULL, /* call */
NULL, /* Event */
ERL_DRV_EXTENDED_MARKER,
ERL_DRV_EXTENDED_MAJOR_VERSION,
ERL_DRV_EXTENDED_MINOR_VERSION,
ERL_DRV_FLAG_USE_PORT_LOCKING, /* Port lock */
NULL, /* Reserved Handle */
NULL, /* Process Exited */
};

struct vertex_struct {
Expand Down Expand Up @@ -107,14 +123,14 @@ static void wings_file_stop(ErlDrvData handle)
* Handle commands.
*/

static int
static ErlDrvSSizeT
control(ErlDrvData handle, unsigned int command,
char* buf, int count,
char** res, int res_size)
char* buf, ErlDrvSizeT count,
char** res, ErlDrvSizeT res_size)
{
switch (command) {
case 0: { /* Define matrix */
memcpy((void *) m, (void *) buf, count);
memcpy((void *) m, (void *) buf, count);
#if 0
{
int i, j;
Expand Down
37 changes: 26 additions & 11 deletions plugins_src/jpeg/wings_jpeg_image_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,25 @@
#include "jpeglib.h"
#include "jerror.h"

#if (ERL_DRV_EXTENDED_MAJOR_VERSION < 2)
/* R14B or earlier types */
#define ErlDrvSizeT int
#define ErlDrvSSizeT int
#endif

/*
* Interface routines
*/
static ErlDrvData jpeg_image_start(ErlDrvPort port, char *buff);
static void jpeg_image_stop(ErlDrvData handle);
static int jpeg_image_control(ErlDrvData handle, unsigned int command,
char* buff, int count,
char** res, int res_size);
static ErlDrvSSizeT jpeg_image_control(ErlDrvData handle, unsigned int command,
char* buff, ErlDrvSizeT count,
char** res, ErlDrvSizeT res_size);

/*
* Internal functions.
*/
static void jpeg_buffer_src(j_decompress_ptr cinfo, char* buf, int count);
static void jpeg_buffer_src(j_decompress_ptr cinfo, char* buf, ErlDrvSizeT count);
static void jpeg_buffer_dest(j_compress_ptr cinfo, ErlDrvBinary* bin);
static ErlDrvBinary* jpeg_buffer_dest_get_bin(j_compress_ptr cinfo);

Expand All @@ -58,7 +64,17 @@ ErlDrvEntry jpeg_image_driver_entry = {
NULL, /* void * that is not used (BC) */
jpeg_image_control, /* F_PTR control, port_control callback */
NULL, /* F_PTR timeout, driver_set_timer callback */
NULL /* F_PTR outputv, reserved */
NULL, /* F_PTR outputv, reserved */
NULL, /* async */
NULL, /* flush */
NULL, /* call */
NULL, /* Event */
ERL_DRV_EXTENDED_MARKER,
ERL_DRV_EXTENDED_MAJOR_VERSION,
ERL_DRV_EXTENDED_MINOR_VERSION,
ERL_DRV_FLAG_USE_PORT_LOCKING, /* Port lock */
NULL, /* Reserved Handle */
NULL, /* Process Exited */
};

/*
Expand Down Expand Up @@ -118,18 +134,18 @@ my_error_exit(j_common_ptr cinfo)
longjmp(myerr->setjmp_buffer, 1);
}

static int
static ErlDrvSSizeT
jpeg_image_control(ErlDrvData handle, unsigned int command,
char* buf, int count,
char** res, int res_size)
char* buf, ErlDrvSizeT count,
char** res, ErlDrvSizeT res_size)
{
JSAMPROW row;
ErlDrvBinary* bin = 0;

switch (command) {
case 0: { /* Read */
struct jpeg_decompress_struct cinfo;
int row_stride; /* physical row width in output buffer */
ErlDrvSizeT row_stride; /* physical row width in output buffer */
int i;
unsigned char* rbuf;
struct my_error_mgr jerr;
Expand Down Expand Up @@ -203,7 +219,6 @@ jpeg_image_control(ErlDrvData handle, unsigned int command,
cinfo.in_color_space = JCS_RGB;
jpeg_set_defaults(&cinfo);
buf += 12;
count -= 12;

jpeg_start_compress(&cinfo, TRUE);
row_stride = cinfo.input_components * cinfo.image_width;
Expand Down Expand Up @@ -286,7 +301,7 @@ term_source (j_decompress_ptr cinfo)
*/

static void
jpeg_buffer_src(j_decompress_ptr cinfo, char* buf, int count)
jpeg_buffer_src(j_decompress_ptr cinfo, char* buf, ErlDrvSizeT count)
{
MemSourceMgr* src;

Expand Down
31 changes: 24 additions & 7 deletions plugins_src/mac_file/mac_wings_file_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,21 @@

#define PATH_MAX 1024


#if (ERL_DRV_EXTENDED_MAJOR_VERSION < 2)
/* R14B or earlier types */
#define ErlDrvSizeT int
#define ErlDrvSSizeT int
#endif

/*
** Interface routines
*/
static ErlDrvData mac_wings_file_start(ErlDrvPort port, char *buff);
static void mac_wings_file_stop(ErlDrvData handle);
static int mac_wings_file_control(ErlDrvData handle, unsigned int command,
char* buff, int count,
char** res, int res_size);
static ErlDrvSSizeT mac_wings_file_control(ErlDrvData handle, unsigned int command,
char* buff, ErlDrvSizeT count,
char** res, ErlDrvSizeT res_size);

/*
** Internal routines
Expand All @@ -54,7 +61,17 @@ ErlDrvEntry mac_wings_file_driver_entry = {
NULL, /* void * that is not used (BC) */
mac_wings_file_control, /* F_PTR control, port_control callback */
NULL, /* F_PTR timeout, driver_set_timer callback */
NULL /* F_PTR outputv, reserved */
NULL, /* F_PTR outputv, reserved */
NULL, /* async */
NULL, /* flush */
NULL, /* call */
NULL, /* Event */
ERL_DRV_EXTENDED_MARKER,
ERL_DRV_EXTENDED_MAJOR_VERSION,
ERL_DRV_EXTENDED_MINOR_VERSION,
ERL_DRV_FLAG_USE_PORT_LOCKING, /* Port lock */
NULL, /* Reserved Handle */
NULL, /* Process Exited */
};

/*
Expand Down Expand Up @@ -92,9 +109,9 @@ static void mac_wings_file_stop(ErlDrvData handle)
** operations, but as the wings application is single threaded
** it doesn't matter.
*/
static int mac_wings_file_control(ErlDrvData handle, unsigned int command,
char* buff, int count,
char** res, int res_size)
static ErlDrvSSizeT mac_wings_file_control(ErlDrvData handle, unsigned int command,
char* buff, ErlDrvSizeT count,
char** res, ErlDrvSizeT res_size)
{
int result;
char *rbuff = 0;
Expand Down
Loading

0 comments on commit 4f3a3ff

Please sign in to comment.