33 #include <cxmessages.h>
36 #include <cpl_image.h>
37 #include <cpl_propertylist.h>
38 #include <cpl_error.h>
58 cpl_propertylist *properties;
76 GiImage *
self = cx_calloc(1,
sizeof *
self);
79 self->properties = NULL;
110 self->pixels = cpl_image_new(nx, ny, self->type);
112 if (self->pixels == NULL) {
118 self->properties = cpl_propertylist_new();
120 if (self->properties == NULL) {
150 GiImage *clone = NULL;
159 if (self->pixels != NULL) {
160 cx_assert(self->type == cpl_image_get_type(self->pixels));
161 clone->pixels = cpl_image_duplicate(self->pixels);
164 if (self->properties != NULL) {
166 cpl_propertylist_duplicate(self->properties);
194 if (self->pixels != NULL) {
195 cpl_image_delete(self->pixels);
199 if (self->properties != NULL) {
200 cpl_propertylist_delete(self->properties);
201 self->properties = NULL;
255 cx_assert(
self != NULL);
261 if (self->type != cpl_image_get_type(image)) {
265 if (self->pixels != NULL) {
266 cpl_image_delete(self->pixels);
270 self->pixels = cpl_image_duplicate(image);
272 return self->pixels ? 0 : 1;
297 return self->properties;
327 if (self->properties) {
328 cpl_propertylist_delete(self->properties);
329 self->properties = NULL;
332 self->properties = cpl_propertylist_duplicate(properties);
334 return self->properties ? 0 : 1;
356 const cxchar *
const fctid =
"giraffe_image_copy_matrix";
361 cxdouble *elements = NULL;
364 cx_assert(
self != NULL);
366 if (matrix == NULL) {
370 nrow = cpl_matrix_get_nrow(matrix);
371 ncol = cpl_matrix_get_ncol(matrix);
372 cx_assert(nrow > 0 && ncol > 0);
374 elements = cpl_matrix_get_data(matrix);
375 cx_assert(elements != NULL);
377 if (self->pixels != NULL) {
378 if (cpl_image_get_size_x(self->pixels) != ncol ||
379 cpl_image_get_size_y(self->pixels) != nrow) {
380 cpl_image_delete(self->pixels);
381 self->pixels = cpl_image_new(ncol, nrow, self->type);
385 self->pixels = cpl_image_new(ncol, nrow, self->type);
388 switch (self->type) {
392 cxsize sz = nrow * ncol;
394 cxint *pixels = cpl_image_get_data_int(self->pixels);
397 for (i = 0; i < sz; i++) {
398 pixels[i] = (cxint) elements[i];
406 cxsize sz = nrow * ncol;
408 cxfloat *pixels = cpl_image_get_data_float(self->pixels);
411 for (i = 0; i < sz; i++) {
412 pixels[i] = (cxfloat) elements[i];
417 case CPL_TYPE_DOUBLE:
419 cxsize sz = nrow * ncol *
sizeof(cxdouble);
421 cxptr pixels = cpl_image_get_data(self->pixels);
424 memcpy(pixels, elements, sz);
429 cpl_error_set(fctid, CPL_ERROR_INVALID_TYPE);
460 cxint position, cxint plane)
463 cx_assert(
self != NULL);
465 if (self->pixels != NULL) {
466 cpl_image_delete(self->pixels);
470 self->pixels = cpl_image_load(filename, self->type, plane, position);
472 return self->pixels ? 0 : 1;
500 cx_assert(
self != NULL);
502 if (self->properties) {
503 cpl_propertylist_delete(self->properties);
504 self->properties = NULL;
511 self->properties = cpl_propertylist_load_regexp(filename, position,
514 if (self->properties == NULL) {
547 cx_assert(
self != NULL);
581 const cxchar *fctid =
"giraffe_image_save";
584 if (filename == NULL) {
591 cxint bits_per_pixel;
594 switch (self->type) {
596 bits_per_pixel = CPL_BPP_32_SIGNED;
600 bits_per_pixel = CPL_BPP_IEEE_FLOAT;
603 case CPL_TYPE_DOUBLE:
607 bits_per_pixel = CPL_BPP_IEEE_FLOAT;
617 cpl_error_set(fctid, CPL_ERROR_INVALID_TYPE);
622 code = cpl_image_save(self->pixels, filename, bits_per_pixel,
623 self->properties, CPL_IO_DEFAULT);
625 if (code != CPL_ERROR_NONE) {
665 const cxchar *fctid =
"giraffe_image_paste";
668 cx_assert(
self != NULL);
670 if (x < 0 || y < 0) {
671 cpl_error_set(fctid, CPL_ERROR_ILLEGAL_INPUT);
681 cxint nx = cpl_image_get_size_x(_self);
682 cxint ny = cpl_image_get_size_y(_self);
683 cxint sx = cpl_image_get_size_x(_image);
684 cxint sy = cpl_image_get_size_y(_image);
687 cxptr _spixel = cpl_image_get_data(_self);
688 cxptr _ipixel = cpl_image_get_data(_image);
690 cpl_type type = cpl_image_get_type(_self);
693 if (type != cpl_image_get_type(_image)) {
694 cpl_error_set(fctid, CPL_ERROR_TYPE_MISMATCH);
700 cpl_error_set(fctid, CPL_ERROR_ACCESS_OUT_OF_RANGE);
709 cpl_error_set(fctid, CPL_ERROR_ACCESS_OUT_OF_RANGE);
716 for (i = 0; i < sy; i++) {
718 cxint bytes = cpl_type_get_sizeof(type);
719 cxint soffset = (ys + nx * i + x) * bytes;
720 cxint ioffset = (sx * i) * bytes;
721 cxint sz = sx * bytes;
723 memcpy((cxchar*)_spixel + soffset,
724 (cxchar*)_ipixel + ioffset, sz);
753 cx_print(
"Resources for Giraffe image at %p:",
self);
754 cx_print(
" properties at %p", self->properties);
755 cx_print(
" list size: %" CPL_SIZE_FORMAT
"\n",
756 cpl_propertylist_get_size(self->properties));
757 cx_print(
" pixels at %p:", cpl_image_get_data(self->pixels));
758 cx_print(
" type: %02x", cpl_image_get_type(self->pixels));
759 cx_print(
" x-size: %" CPL_SIZE_FORMAT,
760 cpl_image_get_size_x(self->pixels));
761 cx_print(
" y-size: %" CPL_SIZE_FORMAT
"\n",
762 cpl_image_get_size_y(self->pixels));
765 cx_print(
"Invalid input image at %p",
self);
782 const cpl_frameset *set)
787 cpl_propertylist *properties = NULL;
796 if (properties == NULL) {
void giraffe_image_print(GiImage *self)
Prints status information about a Giraffe 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_set(GiImage *self, cpl_image *image)
Sets the image data.
cxint giraffe_add_frameset_info(cpl_propertylist *plist, const cpl_frameset *set, cxint sequence)
Add frameset specific information to a property list.
cxint giraffe_image_paste(GiImage *self, const GiImage *image, cxint x, cxint y, cxbool clip)
Paste an image into another at a given position.
cxint giraffe_image_load_pixels(GiImage *self, const cxchar *filename, cxint position, cxint plane)
Gets image data from a file.
cxint giraffe_image_load(GiImage *self, const cxchar *filename, cxint position)
Gets image data and properties from a file.
cxint giraffe_image_save(GiImage *self, const cxchar *filename)
Write a Giraffe image to a file.
void giraffe_image_delete(GiImage *self)
Destroys an image.
GiImage * giraffe_image_duplicate(const GiImage *self)
Creates a copy of an image.
GiImage * giraffe_image_new(cpl_type type)
Creates an empty image container.
GiImage * giraffe_image_create(cpl_type type, cxint nx, cxint ny)
Creates an image container of a given type.
cpl_image * giraffe_image_get(const GiImage *self)
Gets the image data.
cxint giraffe_add_recipe_info(cpl_propertylist *plist, const GiRecipeInfo *info)
Add recipe specific information to a property list.
cxint giraffe_image_set_properties(GiImage *self, cpl_propertylist *properties)
Attaches a property list to an image.
cxint giraffe_image_load_properties(GiImage *self, const cxchar *filename, cxint position)
Gets image properties from a file.
cxint giraffe_image_copy_matrix(GiImage *self, cpl_matrix *matrix)
Copies matrix elements into an image.
cpl_propertylist * giraffe_image_get_properties(const GiImage *self)
Get the properties of an image.