/*//////////////////////////////////////////////////////////////// // ImageObject.c // Image Object and input/output definitions for the image type // in the PostgresSQl database. Defined for use by the Computer // Vision Laboratory at Umass Amherst. // // Collin Lynch // 6/13/1999 ////////////////////////////////////////////////////////////////*/ /* Includes*/ #include #include #include "postgres.h" #include "libpq-fe.h" #include "utils/elog.h" #include "utils/palloc.h" /*Struct definition.*/ typedef struct variable_text { int4 length; char data[1]; } variable_text; typedef struct image { int4 size; /* The memory size of the image object.*/ variable_text* name; /* The Image Name.*/ variable_text* type; /* The Image Encoding Type.*/ int4 width; /* Thw width of the image.*/ int4 height; /* The height of the image.*/ } image; /*Definition of the input function.*/ image* image_in(char* imagestring) { image* result; char* name; char* encoding; int height, width, size; char* temp; name = (char *) palloc(sizeof(char) * 40); encoding = (char *)palloc(sizeof(char) * 30); temp = (char *)palloc(sizeof(char) * 2); elog(0, "a"); elog(0, imagestring); if(sscanf(imagestring, "%[^,]%*[, ]%[^,]%*[, ]%i%*[, ]%i)", name, encoding, &width, &height) != 4) { elog(0, temp); elog(1, "image_in: Parse Error."); return NULL; } elog(0, name); elog(0, encoding); itoa(width, temp); elog(0, temp); itoa(height, temp); elog(0, temp); result = (image *)palloc(sizeof(image)); elog(0, "f"); result->name = (variable_text *)palloc(VARHDRSZ + VARSIZE(name)); memmove(result->name->data, name, VARSIZE(name)); result->name->length = VARHDRSZ + VARSIZE(name); elog(0, "g"); result->type = (variable_text *)palloc(VARHDRSZ + VARSIZE(name)); memmove(result->type->data, encoding, VARSIZE(encoding)); result->type->length = VARHDRSZ + VARSIZE(encoding); elog(0, "r"); result->width = width; result->height = height; elog(0, "c"); /*Set the size of the image object.*/ result->size = (VARHDRSZ * 3) + (sizeof(int4) * 2) + VARSIZE(result->name) + VARSIZE(result->type); elog(0, "d"); elog(0, result->name->data); elog(0, result->type->data); pfree(name); pfree(encoding); return(result); } /*Definition of the output function.*/ char* image_out(image* object) { char* result; if (object == NULL) { return NULL; } result = (char *)palloc(sizeof(char) * 60); sprintf(result, "(%c.%c %f, %f)", object->name, object->type, object->width, object->height); return(result); }