Changeset 25446
- Timestamp:
- Sep 18, 2009, 1:19:57 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/pstamp/src/ppstampMakeStamp.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pstamp/src/ppstampMakeStamp.c
r25197 r25446 100 100 // Extract pixels from an image. If part of the bounds of the region are 101 101 // partially outside of the input those pixels are set to zero. 102 psImage *extractStampOld(psImage *image, psRegion region)103 { 104 int width = region.x1 - region.x0 ;105 int height = region.y1 - region.y0 ;102 static psImage *extractStamp(psImage *image, psRegion region, double value) 103 { 104 int width = region.x1 - region.x0 + 0.5; 105 int height = region.y1 - region.y0 + 0.5; 106 106 107 107 if (width < 0) { 108 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "negative width\n"); 108 109 return NULL; 109 110 } 110 111 if (height < 0) { 112 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "negative height\n"); 111 113 return NULL; 112 114 } … … 132 134 133 135 int copyWidth = lastX - srcX; 134 int rightBlank = width - copyWidth - leftBlank;135 if (copyWidth <= 0) {136 return NULL;137 }138 139 psImage *output = psImageAlloc(width, height, image->type.type);140 141 psElemType type = image->type.type;142 psS32 elementSize = PSELEMTYPE_SIZEOF(type);143 int copySize = copyWidth * elementSize;144 145 for (int dstY=0 ; dstY < height; srcY++, dstY++) {146 psU8 *pdst = output->data.U8[dstY];147 148 if ((srcY < image->row0) || (srcY >= lastY)) {149 // zero the row150 memset(pdst, 0, width*elementSize);151 } else {152 psU8 *psrc = image->data.U8[srcY] + (srcX * elementSize);153 154 if (leftBlank) {155 memset(pdst, 0, leftBlank*elementSize);156 }157 158 // copy copyWidth pixels from srcX,srcY to dstX, dstY159 pdst += dstX*elementSize;160 memcpy(pdst, psrc, copySize);161 162 if (rightBlank) {163 pdst += copyWidth * elementSize;164 memset(pdst, 0, rightBlank);165 }166 }167 }168 169 170 return output;171 }172 // Extract pixels from an image. If part of the bounds of the region are173 // partially outside of the input those pixels are set to zero.174 static psImage *extractStamp(psImage *image, psRegion region, double value)175 {176 int width = region.x1 - region.x0 + 0.5;177 int height = region.y1 - region.y0 + 0.5;178 179 if (width < 0) {180 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "negative width\n");181 return NULL;182 }183 if (height < 0) {184 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "negative height\n");185 return NULL;186 }187 188 int srcX = region.x0;189 int srcY = region.y0;190 int lastX = region.x1;191 int lastY = region.y1;192 if (lastX > (image->col0 + image->numCols)) {193 lastX = image->col0 + image->numCols;194 }195 if (lastY > (image->row0 + image->numRows)) {196 lastY = image->row0 + image->numRows;197 }198 199 int leftBlank = 0;200 int dstX = 0;201 if (srcX < image->col0) {202 leftBlank = image->col0 - srcX;203 dstX += leftBlank;204 srcX = 0;205 }206 207 int copyWidth = lastX - srcX;208 // int rightBlank = width - copyWidth - leftBlank;209 136 if (copyWidth <= 0) { 210 137 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "copyWidth is invalid: %d\n", copyWidth); … … 231 158 if (skip > 0) { 232 159 dstY = skip; 233 height -= skip;234 160 srcY = image->row0; 235 161 } … … 238 164 break; 239 165 } 240 psU8 *pdst = output->data.U8[dstY]; 166 // copy copyWidth pixels from srcX,srcY to dstX, dstY 167 psU8 *pdst = output->data.U8[dstY] + (dstX * elementSize); 241 168 242 169 psU8 *psrc = image->data.U8[srcY] + (srcX * elementSize); 243 170 244 // copy copyWidth pixels from srcX,srcY to dstX, dstY245 pdst += dstX*elementSize;246 171 memcpy(pdst, psrc, copySize); 247 172 } … … 320 245 } 321 246 322 outReadout->image = extractStamp(readout->image, extractRegion, 0);247 outReadout->image = extractStamp(readout->image, extractRegion, NAN); 323 248 if (!outReadout->image) { 324 249 psError(PS_ERR_UNKNOWN, false, "failed to create postage stamp image\n"); … … 327 252 } 328 253 if (readout->variance) { 329 outReadout->variance = extractStamp(readout->variance, extractRegion, 0);254 outReadout->variance = extractStamp(readout->variance, extractRegion, NAN); 330 255 if (!outReadout->variance) { 331 256 psError(PS_ERR_UNKNOWN, false, "failed to create postage stamp weight image\n");
Note:
See TracChangeset
for help on using the changeset viewer.
