| 64 | } |
| 65 | |
| 66 | bool IPLArithmeticOperations::processInputData(IPLData* data, int imageIndex, bool) |
| 67 | { |
| 68 | IPLImage* image = data->toImage(); |
| 69 | |
| 70 | // save the first image |
| 71 | if(imageIndex == 0) |
| 72 | { |
| 73 | delete _inputA; |
| 74 | _inputA = new IPLImage(*image); |
| 75 | } |
| 76 | |
| 77 | // save the second image |
| 78 | if(imageIndex == 1) |
| 79 | { |
| 80 | delete _inputB; |
| 81 | _inputB = new IPLImage(*image); |
| 82 | } |
| 83 | |
| 84 | // only continue if we have 2 valid inputs |
| 85 | if(!(_inputA && _inputB)) |
| 86 | { |
| 87 | return false; |
| 88 | } |
| 89 | |
| 90 | // delete previous result |
| 91 | delete _result; |
| 92 | _result = NULL; |
| 93 | |
| 94 | // the result will be the max size of both inputs |
| 95 | int width = std::max(_inputA->width(), _inputB->width()); |
| 96 | int height = std::max(_inputA->height(), _inputB->height()); |
| 97 | |
| 98 | // copy constructor doesnt work: |
| 99 | // _result = new IPLImage(*image); |
| 100 | |
| 101 | // get properties |
| 102 | _operation = getProcessPropertyInt("operation"); |
| 103 | |
| 104 | int maxNrOfPlanes = std::max( _inputA->getNumberOfPlanes(), _inputB->getNumberOfPlanes()); |
| 105 | int progress = 0; |
| 106 | int maxProgress = maxNrOfPlanes*height; |
| 107 | |
| 108 | IPLDataType type = IPL_IMAGE_COLOR; |
| 109 | if(maxNrOfPlanes == 1) |
| 110 | type = IPL_IMAGE_GRAYSCALE; |
| 111 | |
| 112 | // create result |
| 113 | _result = new IPLImage(type, width, height); |
| 114 | |
| 115 | #pragma omp parallel for |
| 116 | for( int planeNr=0; planeNr < maxNrOfPlanes; planeNr++ ) |
| 117 | { |
| 118 | // prevent reading unavailable planes |
| 119 | IPLImagePlane* planeA = _inputA->plane(std::min(planeNr, _inputA->getNumberOfPlanes()-1)); |
| 120 | IPLImagePlane* planeB = _inputB->plane(std::min(planeNr, _inputB->getNumberOfPlanes()-1)); |
| 121 | IPLImagePlane* newplane = _result->plane(planeNr); |
| 122 | |
| 123 | for(int y=0; y<height; y++) |