Changeset 1205 for trunk/psLib/src/image/psImage.c
- Timestamp:
- Jul 9, 2004, 11:48:07 AM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/image/psImage.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/image/psImage.c
r1193 r1205 9 9 * @author Ross Harman, MHPCC 10 10 * 11 * @version $Revision: 1.3 2$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-07-0 8 01:05:00$11 * @version $Revision: 1.33 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-07-09 21:48:07 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 400 400 } 401 401 402 int psImageClip(psImage* input,float min,float vmin,float max,float vmax)403 {404 int numClipped = 0;405 unsigned int numRows;406 unsigned int numCols;407 408 if (input == NULL) {409 return 0;410 }411 412 if (max < min) {413 psError(__func__,"psImageClip can not be invoked with max < min.");414 return 0;415 }416 417 numRows = input->numRows;418 numCols = input->numCols;419 420 switch (input->type.type) {421 422 #define psImageClipCase(type)\423 case PS_TYPE_##type: { \424 ps##type minimum = (ps##type) min; \425 ps##type maximum = (ps##type) max; \426 for (unsigned int row = 0;row<numRows;row++) { \427 ps##type* inputRow = input->data.type[row]; \428 for (unsigned int col = 0; col < numCols; col++) { \429 if (inputRow[col] < minimum) { \430 inputRow[col] = (ps##type)vmin; \431 numClipped++; \432 } else if (inputRow[col] > maximum) { \433 inputRow[col] = (ps##type)vmax; \434 numClipped++; \435 } \436 } \437 } \438 } \439 break;440 #define psImageClipCaseComplex(type)\441 case PS_TYPE_##type: { \442 for (unsigned int row = 0;row<numRows;row++) { \443 ps##type* inputRow = input->data.type[row]; \444 for (unsigned int col = 0; col < numCols; col++) { \445 if (cabsf(inputRow[col]) < min) { \446 inputRow[col] = (ps##type)vmin; \447 numClipped++; \448 } else if (cabsf(inputRow[col]) > max) { \449 inputRow[col] = (ps##type)vmax; \450 numClipped++; \451 } \452 } \453 } \454 } \455 break;456 457 psImageClipCase(S8)458 psImageClipCase(S16)459 psImageClipCase(S32)460 psImageClipCase(S64)461 psImageClipCase(U8)462 psImageClipCase(U16)463 psImageClipCase(U32)464 psImageClipCase(U64)465 psImageClipCase(F32)466 psImageClipCase(F64)467 psImageClipCaseComplex(C32)468 psImageClipCaseComplex(C64)469 470 default:471 psError(__func__,"psImageClip does not support the given datatype (%d)",472 input->type.type);473 }474 475 return numClipped;476 }477 478 int psImageClipNaN(psImage* input,float value)479 {480 int numClipped = 0;481 unsigned int numRows;482 unsigned int numCols;483 484 if (input == NULL) {485 return 0;486 }487 numRows = input->numRows;488 numCols = input->numCols;489 490 switch (input->type.type) {491 492 #define psImageClipNaNCase(type) \493 case PS_TYPE_##type: \494 for (unsigned int row = 0;row<numRows;row++) { \495 ps##type* inputRow = input->data.type[row]; \496 for (unsigned int col = 0; col < numCols; col++) { \497 if (! isfinite(inputRow[col])) { \498 inputRow[col] = (ps##type)value; \499 numClipped++; \500 } \501 } \502 } \503 break;504 505 psImageClipNaNCase(F32)506 psImageClipNaNCase(F64)507 psImageClipNaNCase(C32)508 psImageClipNaNCase(C64)509 510 default:511 psError(__func__,"psImageClip does not support the given datatype (%d)",512 input->type.type);513 }514 515 return numClipped;516 }517 518 int psImageOverlaySection(psImage* image, const psImage* overlay, int col0,519 int row0, const char* op)520 {521 unsigned int imageNumRows;522 unsigned int imageNumCols;523 unsigned int overlayNumRows;524 unsigned int overlayNumCols;525 unsigned int imageRowLimit;526 unsigned int imageColLimit;527 psElemType type;528 529 if (image == NULL || overlay == NULL) {530 psError(__func__,"one of the input images was NULL.");531 return 1;532 }533 534 if (op == NULL) {535 psError(__func__,"Operation can not be NULL.");536 return 1;537 }538 539 type = image->type.type;540 541 if (type != overlay->type.type) {542 psError(__func__,"Image and overlay datatypes must match. (%d vs %d)",543 type,overlay->type.type);544 return 2;545 }546 547 imageNumRows = image->numRows;548 imageNumCols = image->numCols;549 overlayNumRows = overlay->numRows;550 overlayNumCols = overlay->numCols;551 552 /* check row0/col0 to see if it is within the image size */553 if (row0 < 0 || col0 < 0 || row0 >= imageNumRows || col0 >= imageNumCols) {554 psError(__func__, "Overlay origin of (%d,%d) is outside of the image dimensions (%d x %d).",555 col0, row0, imageNumCols, imageNumRows);556 return 3;557 }558 559 /* check if overlay is totally withing input image */560 imageRowLimit = row0+overlayNumRows;561 imageColLimit = col0+overlayNumCols;562 if (imageRowLimit > imageNumRows || imageColLimit > imageNumCols) {563 psError(__func__, "Overlay image (%d,%d -> %d,%d) is partially outside"564 " of the input image (%d x %d).",565 col0, row0, col0+overlayNumCols-1, row0+overlayNumRows-1,566 imageNumCols,imageNumRows);567 return 4;568 }569 570 switch (type) {571 572 #define psImageOverlayCase(DATATYPE) \573 case PS_TYPE_##DATATYPE: \574 for (unsigned int row=row0;row<imageRowLimit;row++) { \575 ps##DATATYPE* imageRow = image->data.DATATYPE[row]; \576 ps##DATATYPE* overlayRow = overlay->data.DATATYPE[row-row0]; \577 for (unsigned int col=col0;col<imageColLimit;col++) { \578 switch (*op) { \579 case '+': \580 imageRow[col] += overlayRow[col-col0]; \581 break; \582 case '-': \583 imageRow[col] -= overlayRow[col-col0]; \584 break; \585 case '*': \586 imageRow[col] *= overlayRow[col-col0]; \587 break; \588 case '/': \589 imageRow[col] /= overlayRow[col-col0]; \590 break; \591 case '=': \592 imageRow[col] = overlayRow[col-col0]; \593 break; \594 default: \595 psError(__func__,"Unknown operation %s",op); \596 return 5; \597 } \598 } \599 } \600 break;601 602 psImageOverlayCase(U8);603 psImageOverlayCase(U16);604 psImageOverlayCase(U32);605 psImageOverlayCase(U64);606 psImageOverlayCase(S8);607 psImageOverlayCase(S16);608 psImageOverlayCase(S32);609 psImageOverlayCase(S64);610 psImageOverlayCase(F32);611 psImageOverlayCase(F64);612 psImageOverlayCase(C32);613 psImageOverlayCase(C64);614 615 default:616 psError(__func__,"Can not operate on type %d.",type);617 }618 619 return 0;620 }
Note:
See TracChangeset
for help on using the changeset viewer.
