HAWKI Pipeline Reference Manual 1.8.12
|
00001 /* $Id: hawki_image.c,v 1.3 2012/12/04 09:17:04 cgarcia Exp $ 00002 * 00003 * This file is part of the HAWKI Pipeline 00004 * Copyright (C) 2002,2003 European Southern Observatory 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 */ 00020 00021 /* 00022 * $Author: cgarcia $ 00023 * $Date: 2012/12/04 09:17:04 $ 00024 * $Revision: 1.3 $ 00025 * $Name: hawki-1_8_12 $ 00026 */ 00027 00028 #ifdef HAVE_CONFIG_H 00029 #include <config.h> 00030 #endif 00031 00032 /*----------------------------------------------------------------------------- 00033 Includes 00034 -----------------------------------------------------------------------------*/ 00035 00036 #include <math.h> 00037 #include <string.h> 00038 #include <cpl.h> 00039 #include <cpl_mask.h> 00040 #include <cpl_matrix.h> 00041 00042 #include "hawki_mask.h" 00043 00044 /*----------------------------------------------------------------------------*/ 00049 /*----------------------------------------------------------------------------*/ 00050 00067 cpl_error_code hawki_image_copy_to_intersection 00068 (cpl_image * target, 00069 const cpl_image * from, 00070 cpl_size target_shift_x, 00071 cpl_size target_shift_y) 00072 { 00073 00074 cpl_size inter_x1; 00075 cpl_size inter_x2; 00076 cpl_size inter_y1; 00077 cpl_size inter_y2; 00078 00079 cpl_size from_x1 = 0; 00080 cpl_size from_x2 = cpl_image_get_size_x(from); 00081 cpl_size from_y1 = 0; 00082 cpl_size from_y2 = cpl_image_get_size_y(from); 00083 00084 cpl_size target_x1 = target_shift_x; 00085 cpl_size target_x2 = target_shift_x + cpl_image_get_size_x(target); 00086 cpl_size target_y1 = target_shift_y; 00087 cpl_size target_y2 = target_shift_y + cpl_image_get_size_y(target); 00088 00089 /* Check entries */ 00090 cpl_ensure_code(target != NULL, CPL_ERROR_NULL_INPUT); 00091 cpl_ensure_code(from != NULL, CPL_ERROR_NULL_INPUT); 00092 cpl_ensure_code(cpl_image_get_type(target) == cpl_image_get_type(from), 00093 CPL_ERROR_TYPE_MISMATCH); 00094 00095 /* Compute intersection */ 00096 inter_x1 = CX_MAX(from_x1, target_x1); 00097 inter_x2 = CX_MIN(from_x2, target_x2); 00098 inter_y1 = CX_MAX(from_y1, target_y1); 00099 inter_y2 = CX_MIN(from_y2, target_y2); 00100 00101 if(inter_x2 > inter_x1 && inter_y2 > inter_y1) 00102 { 00103 const void * from_data; 00104 void * target_data; 00105 int iy; 00106 size_t pixel_size = cpl_type_get_sizeof(cpl_image_get_type(from)); 00107 cpl_size from_nx = cpl_image_get_size_x(from); 00108 cpl_size target_nx = cpl_image_get_size_y(target); 00109 cpl_size memcopy_size; 00110 00111 memcopy_size = (inter_x2 - inter_x1) * pixel_size; 00112 00113 from_data = cpl_image_get_data_const(from); 00114 target_data = cpl_image_get_data(target); 00115 00116 for(iy=inter_y1; iy<inter_y2; ++iy) 00117 { 00118 const void * from_p; 00119 void * target_p; 00120 00121 from_p = from_data + (inter_x1 + iy * from_nx) * pixel_size; 00122 target_p = target_data + 00123 (inter_x1 - target_shift_x + 00124 (iy - target_shift_y) * target_nx) * pixel_size; 00125 memcpy(target_p, from_p, memcopy_size); 00126 } 00127 } 00128 /* If the if is not executed is because intersection is empty. 00129 * Nothing to copy */ 00130 00131 return CPL_ERROR_NONE; 00132 } 00133