40 #include <cpl_matrix.h>
42 #include "hawki_mask.h"
69 const cpl_image * from,
70 cpl_size target_shift_x,
71 cpl_size target_shift_y)
80 cpl_size from_x2 = cpl_image_get_size_x(from);
82 cpl_size from_y2 = cpl_image_get_size_y(from);
84 cpl_size target_x1 = target_shift_x;
85 cpl_size target_x2 = target_shift_x + cpl_image_get_size_x(target);
86 cpl_size target_y1 = target_shift_y;
87 cpl_size target_y2 = target_shift_y + cpl_image_get_size_y(target);
90 cpl_ensure_code(target != NULL, CPL_ERROR_NULL_INPUT);
91 cpl_ensure_code(from != NULL, CPL_ERROR_NULL_INPUT);
92 cpl_ensure_code(cpl_image_get_type(target) == cpl_image_get_type(from),
93 CPL_ERROR_TYPE_MISMATCH);
96 inter_x1 = CX_MAX(from_x1, target_x1);
97 inter_x2 = CX_MIN(from_x2, target_x2);
98 inter_y1 = CX_MAX(from_y1, target_y1);
99 inter_y2 = CX_MIN(from_y2, target_y2);
101 if(inter_x2 > inter_x1 && inter_y2 > inter_y1)
103 const void * from_data;
106 size_t pixel_size = cpl_type_get_sizeof(cpl_image_get_type(from));
107 cpl_size from_nx = cpl_image_get_size_x(from);
108 cpl_size target_nx = cpl_image_get_size_y(target);
109 cpl_size memcopy_size;
111 memcopy_size = (inter_x2 - inter_x1) * pixel_size;
113 from_data = cpl_image_get_data_const(from);
114 target_data = cpl_image_get_data(target);
116 for(iy=inter_y1; iy<inter_y2; ++iy)
121 from_p = from_data + (inter_x1 + iy * from_nx) * pixel_size;
122 target_p = target_data +
123 (inter_x1 - target_shift_x +
124 (iy - target_shift_y) * target_nx) * pixel_size;
125 memcpy(target_p, from_p, memcopy_size);
131 return CPL_ERROR_NONE;