diff options
Diffstat (limited to 'jni')
-rw-r--r-- | jni/feature_mos/src/mosaic/Blend.cpp | 126 | ||||
-rw-r--r-- | jni/feature_mos/src/mosaic/Blend.h | 2 |
2 files changed, 73 insertions, 55 deletions
diff --git a/jni/feature_mos/src/mosaic/Blend.cpp b/jni/feature_mos/src/mosaic/Blend.cpp index 1f3d93c..18972ee 100644 --- a/jni/feature_mos/src/mosaic/Blend.cpp +++ b/jni/feature_mos/src/mosaic/Blend.cpp @@ -416,40 +416,49 @@ int Blend::DoMergeAndBlend(MosaicFrame **frames, int nsite, // the two component images, int tw = STRIP_CROSS_FADE_WIDTH * width; - for(int y = 0; y < imgMos.Y.height; y++) + // Proceed with the image index calculation for cross-fading + // only if the cross-fading width is larger than 0 + if (tw > 0) { - for(int x = tw; x < imgMos.Y.width - tw + 1; ) + for(int y = 0; y < imgMos.Y.height; y++) { - // Determine where the seam is... - if (imgMos.Y.ptr[y][x] != imgMos.Y.ptr[y][x+1] && - imgMos.Y.ptr[y][x] != 255 && - imgMos.Y.ptr[y][x+1] != 255) + // Since we compare two adjecant pixels to determine + // whether there is a seam, the termination condition of x + // is set to imgMos.Y.width - tw, so that x+1 below + // won't exceed the imgMos' boundary. + for(int x = tw; x < imgMos.Y.width - tw; ) { - // Find the image indices on both sides of the seam - unsigned char idx1 = imgMos.Y.ptr[y][x]; - unsigned char idx2 = imgMos.Y.ptr[y][x+1]; - - for (int o = tw; o >= 0; o--) + // Determine where the seam is... + if (imgMos.Y.ptr[y][x] != imgMos.Y.ptr[y][x+1] && + imgMos.Y.ptr[y][x] != 255 && + imgMos.Y.ptr[y][x+1] != 255) { - // Set the image index to use for cross-fading - imgMos.V.ptr[y][x - o] = idx2; - // Set the intensity weights to use for cross-fading - imgMos.U.ptr[y][x - o] = 50 + (99 - 50) * o / tw; + // Find the image indices on both sides of the seam + unsigned char idx1 = imgMos.Y.ptr[y][x]; + unsigned char idx2 = imgMos.Y.ptr[y][x+1]; + + for (int o = tw; o >= 0; o--) + { + // Set the image index to use for cross-fading + imgMos.V.ptr[y][x - o] = idx2; + // Set the intensity weights to use for cross-fading + imgMos.U.ptr[y][x - o] = 50 + (99 - 50) * o / tw; + } + + for (int o = 1; o <= tw; o++) + { + // Set the image index to use for cross-fading + imgMos.V.ptr[y][x + o] = idx1; + // Set the intensity weights to use for cross-fading + imgMos.U.ptr[y][x + o] = imgMos.U.ptr[y][x - o]; + } + + x += (tw + 1); } - - for (int o = 1; o <= tw; o++) + else { - // Set the image index to use for cross-fading - imgMos.V.ptr[y][x + o] = idx1; - // Set the intensity weights to use for cross-fading - imgMos.U.ptr[y][x + o] = imgMos.U.ptr[y][x - o]; + x++; } - - x += (tw + 1); - } - else - { - x++; } } } @@ -460,40 +469,49 @@ int Blend::DoMergeAndBlend(MosaicFrame **frames, int nsite, // the two component images, int tw = STRIP_CROSS_FADE_WIDTH * height; - for(int x = 0; x < imgMos.Y.width; x++) + // Proceed with the image index calculation for cross-fading + // only if the cross-fading width is larger than 0 + if (tw > 0) { - for(int y = tw; y < imgMos.Y.height - tw + 1; ) + for(int x = 0; x < imgMos.Y.width; x++) { - // Determine where the seam is... - if (imgMos.Y.ptr[y][x] != imgMos.Y.ptr[y+1][x] && - imgMos.Y.ptr[y][x] != 255 && - imgMos.Y.ptr[y+1][x] != 255) + // Since we compare two adjecant pixels to determine + // whether there is a seam, the termination condition of y + // is set to imgMos.Y.height - tw, so that y+1 below + // won't exceed the imgMos' boundary. + for(int y = tw; y < imgMos.Y.height - tw; ) { - // Find the image indices on both sides of the seam - unsigned char idx1 = imgMos.Y.ptr[y][x]; - unsigned char idx2 = imgMos.Y.ptr[y+1][x]; - - for (int o = tw; o >= 0; o--) + // Determine where the seam is... + if (imgMos.Y.ptr[y][x] != imgMos.Y.ptr[y+1][x] && + imgMos.Y.ptr[y][x] != 255 && + imgMos.Y.ptr[y+1][x] != 255) { - // Set the image index to use for cross-fading - imgMos.V.ptr[y - o][x] = idx2; - // Set the intensity weights to use for cross-fading - imgMos.U.ptr[y - o][x] = 50 + (99 - 50) * o / tw; + // Find the image indices on both sides of the seam + unsigned char idx1 = imgMos.Y.ptr[y][x]; + unsigned char idx2 = imgMos.Y.ptr[y+1][x]; + + for (int o = tw; o >= 0; o--) + { + // Set the image index to use for cross-fading + imgMos.V.ptr[y - o][x] = idx2; + // Set the intensity weights to use for cross-fading + imgMos.U.ptr[y - o][x] = 50 + (99 - 50) * o / tw; + } + + for (int o = 1; o <= tw; o++) + { + // Set the image index to use for cross-fading + imgMos.V.ptr[y + o][x] = idx1; + // Set the intensity weights to use for cross-fading + imgMos.U.ptr[y + o][x] = imgMos.U.ptr[y - o][x]; + } + + y += (tw + 1); } - - for (int o = 1; o <= tw; o++) + else { - // Set the image index to use for cross-fading - imgMos.V.ptr[y + o][x] = idx1; - // Set the intensity weights to use for cross-fading - imgMos.U.ptr[y + o][x] = imgMos.U.ptr[y - o][x]; + y++; } - - y += (tw + 1); - } - else - { - y++; } } } diff --git a/jni/feature_mos/src/mosaic/Blend.h b/jni/feature_mos/src/mosaic/Blend.h index a5bc05b..80bb577 100644 --- a/jni/feature_mos/src/mosaic/Blend.h +++ b/jni/feature_mos/src/mosaic/Blend.h @@ -42,7 +42,7 @@ const float STRIP_SEPARATION_THRESHOLD = 0.10; // This threshold determines the number of pixels on either side of the strip // to cross-fade using the images contributing to each seam. This threshold // is specified as a fraction of the input image frame width. -const float STRIP_CROSS_FADE_WIDTH = 0.02; +const float STRIP_CROSS_FADE_WIDTH = 0.002; /** * Class for pyramid blending a mosaic. */ |