Changeset 37050 for trunk/psLib
- Timestamp:
- Jul 17, 2014, 10:22:22 AM (12 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 6 edited
-
fits/psFitsImage.c (modified) (9 diffs)
-
fits/psFitsScale.c (modified) (3 diffs)
-
imageops/psImageBackground.c (modified) (2 diffs)
-
sys/psMemory.c (modified) (1 diff)
-
sys/psThread.c (modified) (1 diff)
-
sys/psThread.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/fits/psFitsImage.c
r36537 r37050 345 345 if (newScaleZero) { 346 346 // Choose an appropriate BSCALE and BZERO 347 if (!psFitsScaleDetermine(bscale, bzero, boffset, bsoften, blank, image, mask, maskVal, fits)) {348 // We can't have the write dying for this reason --- try to save it somehow!349 psWarning("Unable to determine BSCALE and BZERO for image --- refusing to quantise.");350 psErrorClear();351 return psMemIncrRefCounter((psImage*)image);352 }347 if (!psFitsScaleDetermine(bscale, bzero, boffset, bsoften, blank, image, mask, maskVal, fits)) { 348 // We can't have the write dying for this reason --- try to save it somehow! 349 psWarning("Unable to determine BSCALE and BZERO for image --- refusing to quantise."); 350 psErrorClear(); 351 return psMemIncrRefCounter((psImage*)image); 352 } 353 353 } else { 354 // Don't want to muck with the current BSCALE and BZERO. Get the current values and use those.355 int status = 0; // Status of cfitsio356 if (fits_read_key_dbl(fits->fd, "BSCALE", bscale, NULL, &status) && status != KEY_NO_EXIST) {354 // Don't want to muck with the current BSCALE and BZERO. Get the current values and use those. 355 int status = 0; // Status of cfitsio 356 if (fits_read_key_dbl(fits->fd, "BSCALE", bscale, NULL, &status) && status != KEY_NO_EXIST) { 357 357 psFitsError(status, true, "Unable to read header."); 358 358 return NULL; … … 371 371 } 372 372 373 return psFitsScaleForDisk(image, fits, *bscale, *bzero, *boffset, *bsoften, rng); 373 // XXX this test triggers the pswarp memory corruption problem. you need to include "psThread.h" above to activate this 374 // for (int nx = 0; nx < 3; nx++) { 375 // psList *pending = psThreadGetPendingQueue(); 376 // if (pending && pending->head) { 377 // fprintf (stderr, "thread jobs are still pending...\n"); 378 // } 379 // // XXX can we mess up the memory? 380 // psImage *temp1 = psImageAlloc(image->numCols, image->numRows, PS_TYPE_F32); 381 // fprintf (stderr, "corruption check set 1\n"); 382 // psMemCheckCorruption (stderr, true); 383 // psImageInit (temp1, 2.0); 384 // psFree (temp1); 385 // fprintf (stderr, "corruption check set 2\n"); 386 // psMemCheckCorruption (stderr, true); 387 // } 388 389 // fprintf (stderr, "corruption check psFitsInsertImageWithMask\n"); 390 // psMemCheckCorruption (stderr, true); 391 392 psImage *out = psFitsScaleForDisk(image, fits, *bscale, *bzero, *boffset, *bsoften, rng); 393 return out; 374 394 } 375 395 … … 638 658 long blank = 0; // Blank (undefined) value for image 639 659 psFitsFloat floatType; // Custom floating-point convention type 640 psImage *diskImage = imageToDiskRepresentation(&bscale, &bzero, &boffset, &bsoften, &blank, &floatType, fits, image, 641 mask, maskVal, NULL, true); // Image to write out 660 661 psImage *diskImage = imageToDiskRepresentation(&bscale, &bzero, &boffset, &bsoften, &blank, &floatType, 662 fits, image, mask, maskVal, NULL, true); // Image to write out 663 642 664 if (!diskImage) { 643 665 psError(PS_ERR_UNKNOWN, false, "Unable to convert image to desired disk format."); … … 666 688 goto INSERT_DONE; 667 689 } 690 668 691 if (cfitsioBzero != 0.0) { 669 692 psAssert(bzero == 0.0 && bscale == 1.0, … … 840 863 } 841 864 } 865 842 866 if (psFitsError(status, true, "Could not write image to file.")) { 843 867 success = false; … … 856 880 INSERT_DONE: 857 881 psFree(diskImage); 882 858 883 if (compress) { 859 884 // Restore compression state … … 906 931 psImage *diskImage = imageToDiskRepresentation(&bscale, &bzero, &boffset, &bsoften, &blank, &floatType, fits, input, 907 932 mask, maskVal, NULL, false); // Image to write out 933 908 934 if (!diskImage) { 909 935 psError(PS_ERR_UNKNOWN, false, "Unable to convert image to desired disk format."); … … 932 958 goto UPDATE_DONE; 933 959 } 960 934 961 if (cfitsioBzero != 0.0) { 935 962 psAssert(bzero == 0.0 && bscale == 1.0, … … 979 1006 goto UPDATE_DONE; 980 1007 } 981 1008 982 1009 // We only want cfitsio to do the scale and zero if the type conversion requires it (e.g., input type is 983 1010 // an unsigned integer type). In all other cases, we have already converted the image to use the -
trunk/psLib/src/fits/psFitsScale.c
r36760 r37050 929 929 930 930 931 psImage *psFitsScaleForDisk(const psImage *image, const psFits *fits, double bscale, double bzero, double boffset, double bsoften, 932 psRandom *rng) 931 psImage *psFitsScaleForDisk(const psImage *image, const psFits *fits, double bscale, double bzero, double boffset, double bsoften, psRandom *rng) 933 932 { 934 933 PS_ASSERT_IMAGE_NON_NULL(image, NULL); … … 971 970 psImage *out = psImageAlloc(numCols, numRows, outType); // Output image 972 971 973 if (!psMemIncrRefCounter(rng) && options->fuzz) { 974 // Don't blab about which seed we're going to get --- it's not necessary for this purpose 975 rng = psRandomAlloc(PS_RANDOM_TAUS); 976 } 977 978 #define SCALE_WRITE_OUT_CASE(IN, INTYPE, OUT, OUTTYPE) \ 979 case PS_TYPE_##OUTTYPE: { \ 980 double scale = 1.0 / bscale; \ 981 double zero = bzero; \ 972 // fprintf (stderr, "corruption check psFitsScaleForDisk 1\n"); 973 // psMemCheckCorruption (stderr, true); 974 975 if (options->fuzz && !psMemIncrRefCounter (rng)) { 976 // Don't blab about which seed we're going to get --- it's not necessary for this purpose 977 rng = psRandomAlloc(PS_RANDOM_TAUS); 978 } 979 980 #define SCALE_WRITE_OUT_CASE(IN, INTYPE, OUT, OUTTYPE) \ 981 case PS_TYPE_##OUTTYPE: { \ 982 double scale = 1.0 / bscale; \ 983 double zero = bzero; \ 982 984 /* Note: BITPIX=8 treated differently, since it uses unsigned values; the rest use signed */ \ 983 double min = bitpix == 8 ? 0 : -pow(2.0, options->bitpix - 1); \985 double min = bitpix == 8 ? 0 : -pow(2.0, options->bitpix - 1); \ 984 986 double max = bitpix == 8 ? 255 : (pow(2.0, options->bitpix - 1) - 1.0); \ 985 for (int y = 0; y < numRows; y++) { \ 986 for (int x = 0; x < numCols; x++) { \ 987 ps##INTYPE value; \ 988 if ((options->scaling == PS_FITS_SCALE_LOG_RANGE)|| \ 989 (options->scaling == PS_FITS_SCALE_LOG_MANUAL)|| \ 990 (options->scaling == PS_FITS_SCALE_LOG_STDEV_POSITIVE)|| \ 991 (options->scaling == PS_FITS_SCALE_LOG_STDEV_NEGATIVE)|| \ 992 (options->scaling == PS_FITS_SCALE_LOG_STDEV_BOTH)) { \ 993 if (isfinite((IN)->data.INTYPE[y][x])) { \ 994 value = log10( (IN)->data.INTYPE[y][x] - boffset ); \ 987 for (int y = 0; y < numRows; y++) { \ 988 for (int x = 0; x < numCols; x++) { \ 989 ps##INTYPE value; \ 990 if ((options->scaling == PS_FITS_SCALE_LOG_RANGE)|| \ 991 (options->scaling == PS_FITS_SCALE_LOG_MANUAL)|| \ 992 (options->scaling == PS_FITS_SCALE_LOG_STDEV_POSITIVE)|| \ 993 (options->scaling == PS_FITS_SCALE_LOG_STDEV_NEGATIVE)|| \ 994 (options->scaling == PS_FITS_SCALE_LOG_STDEV_BOTH)) { \ 995 if (isfinite((IN)->data.INTYPE[y][x])) { \ 996 value = log10( (IN)->data.INTYPE[y][x] - boffset ); \ 997 } \ 998 else { \ 999 value = (IN)->data.INTYPE[y][x]; \ 1000 } \ 1001 } \ 1002 else if ((options->scaling == PS_FITS_SCALE_ASINH_RANGE)|| \ 1003 (options->scaling == PS_FITS_SCALE_ASINH_MANUAL)|| \ 1004 (options->scaling == PS_FITS_SCALE_ASINH_STDEV_POSITIVE)|| \ 1005 (options->scaling == PS_FITS_SCALE_ASINH_STDEV_NEGATIVE)|| \ 1006 (options->scaling == PS_FITS_SCALE_ASINH_STDEV_BOTH)) { \ 1007 if (isfinite((IN)->data.INTYPE[y][x])) { \ 1008 value = 1.0857362 * (asinh( ((IN)->data.INTYPE[y][x] - boffset) / (2.0 * bsoften))); \ 1009 } \ 1010 else { \ 1011 value = (IN)->data.INTYPE[y][x]; \ 1012 } \ 995 1013 } \ 996 1014 else { \ 997 value = (IN)->data.INTYPE[y][x]; \1015 value = (IN)->data.INTYPE[y][x]; \ 998 1016 } \ 999 } \ 1000 else if ((options->scaling == PS_FITS_SCALE_ASINH_RANGE)|| \ 1001 (options->scaling == PS_FITS_SCALE_ASINH_MANUAL)|| \ 1002 (options->scaling == PS_FITS_SCALE_ASINH_STDEV_POSITIVE)|| \ 1003 (options->scaling == PS_FITS_SCALE_ASINH_STDEV_NEGATIVE)|| \ 1004 (options->scaling == PS_FITS_SCALE_ASINH_STDEV_BOTH)) { \ 1005 if (isfinite((IN)->data.INTYPE[y][x])) { \ 1006 value = 1.0857362 * (asinh( ((IN)->data.INTYPE[y][x] - boffset) / (2.0 * bsoften))); \ 1017 if (!isfinite(value)) { \ 1018 /* This choice of "max" for non-finite pixels is mainly cosmetic --- it has to be */ \ 1019 /* something, and "min" would produce holes in the cores of bright stars. */ \ 1020 (OUT)->data.OUTTYPE[y][x] = max; \ 1021 } else { \ 1022 value = (value - zero) * scale; \ 1023 if (options->fuzz && (value - (int)value != 0.0)) { \ 1024 /* Add random factor [0.0,1.0): adds a variance of 1/12, */ \ 1025 /* but preserves the expectation value given the floor() */ \ 1026 value += psRandomUniform(rng) ; \ 1027 } \ 1028 /* Check for underflow and overflow; set either to max */ \ 1029 (OUT)->data.OUTTYPE[y][x] = (value < min || value > max ? max : floor(value)); \ 1007 1030 } \ 1008 else { \ 1009 value = (IN)->data.INTYPE[y][x]; \ 1010 } \ 1011 } \ 1012 else { \ 1013 value = (IN)->data.INTYPE[y][x]; \ 1014 } \ 1015 if (!isfinite(value)) { \ 1016 /* This choice of "max" for non-finite pixels is mainly cosmetic --- it has to be */ \ 1017 /* something, and "min" would produce holes in the cores of bright stars. */ \ 1018 (OUT)->data.OUTTYPE[y][x] = max; \ 1019 } else { \ 1020 value = (value - zero) * scale; \ 1021 if (options->fuzz && (value - (int)value != 0.0)) { \ 1022 /* Add random factor [-0.5,0.5): adds a variance of 1/12, */ \ 1023 /* but preserves the expectation value */ \ 1024 value += psRandomUniform(rng) ; \ 1025 } \ 1026 /* Check for underflow and overflow; set either to max */ \ 1027 (OUT)->data.OUTTYPE[y][x] = (value < min || value > max ? max : floor(value)); \ 1028 } \ 1029 } \ 1030 } \ 1031 break; \ 1032 } 1033 1034 #define SCALE_WRITE_IN_CASE(IN, INTYPE, OUT) \ 1035 case PS_TYPE_##INTYPE: { \ 1036 switch (outType) { \ 1037 SCALE_WRITE_OUT_CASE(IN, INTYPE, OUT, U8);; \ 1038 SCALE_WRITE_OUT_CASE(IN, INTYPE, OUT, S16);; \ 1039 SCALE_WRITE_OUT_CASE(IN, INTYPE, OUT, S32);; \ 1040 SCALE_WRITE_OUT_CASE(IN, INTYPE, OUT, S64);; \ 1041 default: \ 1042 psAbort("Should be unreachable."); \ 1043 } \ 1044 break; \ 1045 } 1046 1031 } \ 1032 } \ 1033 break; \ 1034 } 1035 1036 #define SCALE_WRITE_IN_CASE(IN, INTYPE, OUT) \ 1037 case PS_TYPE_##INTYPE: { \ 1038 switch (outType) { \ 1039 SCALE_WRITE_OUT_CASE(IN, INTYPE, OUT, U8);; \ 1040 SCALE_WRITE_OUT_CASE(IN, INTYPE, OUT, S16);; \ 1041 SCALE_WRITE_OUT_CASE(IN, INTYPE, OUT, S32);; \ 1042 SCALE_WRITE_OUT_CASE(IN, INTYPE, OUT, S64);; \ 1043 default: \ 1044 psAbort("Should be unreachable."); \ 1045 } \ 1046 break; \ 1047 } 1048 1047 1049 switch (image->type.type) { 1048 SCALE_WRITE_IN_CASE(image, F32, out);1049 SCALE_WRITE_IN_CASE(image, F64, out);1050 SCALE_WRITE_IN_CASE(image, F32, out); 1051 SCALE_WRITE_IN_CASE(image, F64, out); 1050 1052 default: 1051 1053 psAbort("Should be unreachable."); … … 1053 1055 1054 1056 psFree(rng); 1055 1056 1057 return out; 1057 1058 } -
trunk/psLib/src/imageops/psImageBackground.c
r31152 r37050 124 124 } 125 125 } else if (nSubset >= nGoodPixels) { 126 psTrace ("psLib.imageops", 4, "case 2: nSubset >= nGoodPixels (%d x %d : %d : %d : %d)\n", (int) nx, (int) ny, (int) nSubset, (int) nGoodPixels, (int) nPixels);126 psTrace ("psLib.imageops", 4, "case 2: nSubset >= nGoodPixels (%d x %d : %d : %d : %d)\n", (int) nx, (int) ny, (int) nSubset, (int) nGoodPixels, (int) nPixels); 127 127 // in this case, we have to select from all masked pixels just to get the desired 128 128 // sample size … … 157 157 double frnd = psRandomUniform(rng); 158 158 int pixel = pixelVector->n * frnd; 159 159 // psAssert (pixel < pixelVector->nalloc, "oops, we went too far (1)"); 160 // psAssert (pixel >= 0, "oops, we went too far (2)"); 161 // psAssert (pixelVector->n - 1 < pixelVector->nalloc, "oops, we went too far (3)"); 162 // psAssert (pixelVector->n - 1 >= 0, "oops, we went too far (4)"); 163 160 164 psVectorAppend(values, pixelVector->data.F32[pixel]); 161 165 pixelVector->data.F32[pixel] = pixelVector->data.F32[pixelVector->n - 1]; -
trunk/psLib/src/sys/psMemory.c
r32746 r37050 1315 1315 checkingForCorruption = true; 1316 1316 1317 // int nPrint = 0; 1317 1318 psS32 nbad = 0; // number of bad blocks 1318 1319 for (psMemBlock *memBlock = (psMemBlock *) lastMemBlockAllocated; memBlock != NULL; memBlock = memBlock->nextBlock) { 1320 // if (nPrint < 20) { 1321 // psMemBlockPrint (stderr, memBlock); 1322 // nPrint ++; 1323 // } 1319 1324 if (isBadMemBlock(output, memBlock, __FILE__, __LINE__, __func__)) { 1320 1325 nbad++; -
trunk/psLib/src/sys/psThread.c
r34153 r37050 152 152 psThreadJob *job = psListGetAndRemove((psList *) done, PS_LIST_HEAD); 153 153 return job; 154 } 155 156 psList *psThreadGetPendingQueue () { 157 return (psList *) pending; 154 158 } 155 159 -
trunk/psLib/src/sys/psThread.h
r33089 r37050 90 90 psThreadJob *psThreadJobGetDone(void); 91 91 92 // utility function to access the pending queue 93 psList *psThreadGetPendingQueue (); 94 92 95 /// Allocate a thread task 93 96 psThreadTask *psThreadTaskAlloc(const char *type, // Type of task
Note:
See TracChangeset
for help on using the changeset viewer.
