25 #include <cxmessages.h>
28 #include <cpl_image.h>
29 #include <cpl_propertylist.h>
30 #include <cpl_error.h>
50 cpl_propertylist *properties;
68 GiImage *
self = cx_calloc(1,
sizeof *
self);
71 self->properties = NULL;
102 self->pixels = cpl_image_new(nx, ny, self->type);
104 if (self->pixels == NULL) {
110 self->properties = cpl_propertylist_new();
112 if (self->properties == NULL) {
142 GiImage *clone = NULL;
151 if (self->pixels != NULL) {
152 cx_assert(self->type == cpl_image_get_type(self->pixels));
153 clone->pixels = cpl_image_duplicate(self->pixels);
156 if (self->properties != NULL) {
158 cpl_propertylist_duplicate(self->properties);
186 if (self->pixels != NULL) {
187 cpl_image_delete(self->pixels);
191 if (self->properties != NULL) {
192 cpl_propertylist_delete(self->properties);
193 self->properties = NULL;
247 cx_assert(
self != NULL);
253 if (self->type != cpl_image_get_type(image)) {
257 if (self->pixels != NULL) {
258 cpl_image_delete(self->pixels);
262 self->pixels = cpl_image_duplicate(image);
264 return self->pixels ? 0 : 1;
289 return self->properties;
319 if (self->properties) {
320 cpl_propertylist_delete(self->properties);
321 self->properties = NULL;
324 self->properties = cpl_propertylist_duplicate(properties);
326 return self->properties ? 0 : 1;
348 const cxchar *
const fctid =
"giraffe_image_copy_matrix";
353 cxdouble *elements = NULL;
356 cx_assert(
self != NULL);
358 if (matrix == NULL) {
362 nrow = cpl_matrix_get_nrow(matrix);
363 ncol = cpl_matrix_get_ncol(matrix);
364 cx_assert(nrow > 0 && ncol > 0);
366 elements = cpl_matrix_get_data(matrix);
367 cx_assert(elements != NULL);
369 if (self->pixels != NULL) {
370 if (cpl_image_get_size_x(self->pixels) != ncol ||
371 cpl_image_get_size_y(self->pixels) != nrow) {
372 cpl_image_delete(self->pixels);
373 self->pixels = cpl_image_new(ncol, nrow, self->type);
377 self->pixels = cpl_image_new(ncol, nrow, self->type);
380 switch (self->type) {
384 cxsize sz = nrow * ncol;
386 cxint *pixels = cpl_image_get_data_int(self->pixels);
389 for (i = 0; i < sz; i++) {
390 pixels[i] = (cxint) elements[i];
398 cxsize sz = nrow * ncol;
400 cxfloat *pixels = cpl_image_get_data_float(self->pixels);
403 for (i = 0; i < sz; i++) {
404 pixels[i] = (cxfloat) elements[i];
409 case CPL_TYPE_DOUBLE:
411 cxsize sz = nrow * ncol *
sizeof(cxdouble);
413 cxptr pixels = cpl_image_get_data(self->pixels);
416 memcpy(pixels, elements, sz);
421 cpl_error_set(fctid, CPL_ERROR_INVALID_TYPE);
452 cxint position, cxint plane)
455 cx_assert(
self != NULL);
457 if (self->pixels != NULL) {
458 cpl_image_delete(self->pixels);
462 self->pixels = cpl_image_load(filename, self->type, plane, position);
464 return self->pixels ? 0 : 1;
492 cx_assert(
self != NULL);
494 if (self->properties) {
495 cpl_propertylist_delete(self->properties);
496 self->properties = NULL;
503 self->properties = cpl_propertylist_load_regexp(filename, position,
506 if (self->properties == NULL) {
539 cx_assert(
self != NULL);
573 const cxchar *fctid =
"giraffe_image_save";
576 if (filename == NULL) {
583 cxint bits_per_pixel;
586 switch (self->type) {
588 bits_per_pixel = CPL_BPP_32_SIGNED;
592 bits_per_pixel = CPL_BPP_IEEE_FLOAT;
595 case CPL_TYPE_DOUBLE:
599 bits_per_pixel = CPL_BPP_IEEE_FLOAT;
609 cpl_error_set(fctid, CPL_ERROR_INVALID_TYPE);
614 code = cpl_image_save(self->pixels, filename, bits_per_pixel,
615 self->properties, CPL_IO_DEFAULT);
617 if (code != CPL_ERROR_NONE) {
657 const cxchar *fctid =
"giraffe_image_paste";
660 cx_assert(
self != NULL);
662 if (x < 0 || y < 0) {
663 cpl_error_set(fctid, CPL_ERROR_ILLEGAL_INPUT);
673 cxint nx = cpl_image_get_size_x(_self);
674 cxint ny = cpl_image_get_size_y(_self);
675 cxint sx = cpl_image_get_size_x(_image);
676 cxint sy = cpl_image_get_size_y(_image);
679 cxptr _spixel = cpl_image_get_data(_self);
680 cxptr _ipixel = cpl_image_get_data(_image);
682 cpl_type type = cpl_image_get_type(_self);
685 if (type != cpl_image_get_type(_image)) {
686 cpl_error_set(fctid, CPL_ERROR_TYPE_MISMATCH);
692 cpl_error_set(fctid, CPL_ERROR_ACCESS_OUT_OF_RANGE);
701 cpl_error_set(fctid, CPL_ERROR_ACCESS_OUT_OF_RANGE);
708 for (i = 0; i < sy; i++) {
710 cxint bytes = cpl_type_get_sizeof(type);
711 cxint soffset = (ys + nx * i + x) * bytes;
712 cxint ioffset = (sx * i) * bytes;
713 cxint sz = sx * bytes;
715 memcpy((cxchar*)_spixel + soffset,
716 (cxchar*)_ipixel + ioffset, sz);
745 cx_print(
"Resources for Giraffe image at %p:",
self);
746 cx_print(
" properties at %p", self->properties);
747 cx_print(
" list size: %" CPL_SIZE_FORMAT
"\n",
748 cpl_propertylist_get_size(self->properties));
749 cx_print(
" pixels at %p:", cpl_image_get_data(self->pixels));
750 cx_print(
" type: %02x", cpl_image_get_type(self->pixels));
751 cx_print(
" x-size: %" CPL_SIZE_FORMAT,
752 cpl_image_get_size_x(self->pixels));
753 cx_print(
" y-size: %" CPL_SIZE_FORMAT
"\n",
754 cpl_image_get_size_y(self->pixels));
757 cx_print(
"Invalid input image at %p",
self);
774 const cpl_frameset *set)
779 cpl_propertylist *properties = NULL;
788 if (properties == NULL) {
void giraffe_image_delete(GiImage *self)
Destroys an image.
cxint giraffe_image_load_pixels(GiImage *self, const cxchar *filename, cxint position, cxint plane)
Gets image data from a file.
cxint giraffe_image_paste(GiImage *self, const GiImage *image, cxint x, cxint y, cxbool clip)
Paste an image into another at a given position.
cpl_propertylist * giraffe_image_get_properties(const GiImage *self)
Get the properties of an image.
cxint giraffe_image_add_info(GiImage *image, const GiRecipeInfo *info, const cpl_frameset *set)
Add additional frame information to an image.
cxint giraffe_image_copy_matrix(GiImage *self, cpl_matrix *matrix)
Copies matrix elements into an image.
cxint giraffe_image_load_properties(GiImage *self, const cxchar *filename, cxint position)
Gets image properties from a file.
cxint giraffe_image_save(GiImage *self, const cxchar *filename)
Write a Giraffe image to a file.
cpl_image * giraffe_image_get(const GiImage *self)
Gets the image data.
GiImage * giraffe_image_create(cpl_type type, cxint nx, cxint ny)
Creates an image container of a given type.
GiImage * giraffe_image_new(cpl_type type)
Creates an empty image container.
void giraffe_image_print(GiImage *self)
Prints status information about a Giraffe image.
cxint giraffe_image_set(GiImage *self, cpl_image *image)
Sets the image data.
cxint giraffe_image_set_properties(GiImage *self, cpl_propertylist *properties)
Attaches a property list to an image.
cxint giraffe_image_load(GiImage *self, const cxchar *filename, cxint position)
Gets image data and properties from a file.
GiImage * giraffe_image_duplicate(const GiImage *self)
Creates a copy of an image.
cxint giraffe_add_recipe_info(cpl_propertylist *plist, const GiRecipeInfo *info)
Add recipe specific information to a property list.
cxint giraffe_add_frameset_info(cpl_propertylist *plist, const cpl_frameset *set, cxint sequence)
Add frameset specific information to a property list.