diff --git a/rtengine/image16.cc b/rtengine/image16.cc index 2a9fbb551..62ab5248d 100644 --- a/rtengine/image16.cc +++ b/rtengine/image16.cc @@ -130,14 +130,15 @@ void Image16::getStdImage (ColorTemp ctemp, int tran, Imagefloat* image, Preview transform (pp, tran, sx1, sy1, sx2, sy2); - int imwidth=image->width,imheight=image->height; + int imwidth=image->width; // Destination image + int imheight=image->height; // Destination image if (((tran & TR_ROT) == TR_R90)||((tran & TR_ROT) == TR_R270)) { int swap = imwidth; imwidth=imheight; imheight=swap; } - int istart = sy1; - int maxx=width,maxy=height; + int maxx=width; // Source image + int maxy=height; // Source image int mtran = tran & TR_ROT; int skip = pp.skip; @@ -147,6 +148,9 @@ void Image16::getStdImage (ColorTemp ctemp, int tran, Imagefloat* image, Preview // switched to using ints for the red/green/blue channel buffer. // Incidentally this improves accuracy too. float area=skip*skip; + float rm2=rm; + float gm2=gm; + float bm2=bm; rm/=area; gm/=area; bm/=area; @@ -167,49 +171,89 @@ void Image16::getStdImage (ColorTemp ctemp, int tran, Imagefloat* image, Preview #ifdef _OPENMP #pragma omp for #endif - for (int ix=0;ix=maxy-skip) i=maxy-skip-1; // avoid trouble - for (int j=0,jx=sx1; j=maxx-skip) jx=maxx-skip-1; // avoid trouble + // Iterating all the rows of the destination image + for (int iy=0; iy=maxy) + continue; - for (int m=0; m=maxx) + continue; + + lineR[dst_x] = r(src_y, src_x); + lineG[dst_x] = g(src_y, src_x); + lineB[dst_x] = b(src_y, src_x); + } + } + else { + // source image, first line of the current destination row + int src_y=sy1+skip*iy; + if (src_y>=maxy) + continue; + + for (int dst_x=0,src_x=sx1; dst_x=maxx) + continue; + + int src_sub_width = MIN(maxx-src_x, skip); + int src_sub_height = MIN(maxy-src_y, skip); + + float rtot,gtot,btot; // RGB accumulators + rtot=gtot=btot=0.; + + for (int src_sub_y=0; src_sub_yr(ix, j) = lineR[j]; - image->g(ix, j) = lineG[j]; - image->b(ix, j) = lineB[j]; + for (int dst_x=0,src_x=sx1; dst_xr(iy, dst_x) = lineR[dst_x]; + image->g(iy, dst_x) = lineG[dst_x]; + image->b(iy, dst_x) = lineB[dst_x]; } else if (mtran == TR_R180) - for (int j=0; jr(imheight-1-ix, imwidth-1-j) = lineR[j]; - image->g(imheight-1-ix, imwidth-1-j) = lineG[j]; - image->b(imheight-1-ix, imwidth-1-j) = lineB[j]; + for (int dst_x=0; dst_xr(imheight-1-iy, imwidth-1-dst_x) = lineR[dst_x]; + image->g(imheight-1-iy, imwidth-1-dst_x) = lineG[dst_x]; + image->b(imheight-1-iy, imwidth-1-dst_x) = lineB[dst_x]; } else if (mtran == TR_R90) - for (int j=0,jx=sx1; jr(j, imheight-1-ix) = lineR[j]; - image->g(j, imheight-1-ix) = lineG[j]; - image->b(j, imheight-1-ix) = lineB[j]; + for (int dst_x=0,src_x=sx1; dst_xr(dst_x, imheight-1-iy) = lineR[dst_x]; + image->g(dst_x, imheight-1-iy) = lineG[dst_x]; + image->b(dst_x, imheight-1-iy) = lineB[dst_x]; } else if (mtran == TR_R270) - for (int j=0,jx=sx1; jr(imwidth-1-j, ix) = lineR[j]; - image->g(imwidth-1-j, ix) = lineG[j]; - image->b(imwidth-1-j, ix) = lineB[j]; + for (int dst_x=0,src_x=sx1; dst_xr(imwidth-1-dst_x, iy) = lineR[dst_x]; + image->g(imwidth-1-dst_x, iy) = lineG[dst_x]; + image->b(imwidth-1-dst_x, iy) = lineB[dst_x]; } } #ifdef _OPENMP diff --git a/rtengine/image8.cc b/rtengine/image8.cc index dd8425e71..d24409845 100644 --- a/rtengine/image8.cc +++ b/rtengine/image8.cc @@ -99,14 +99,15 @@ void Image8::getStdImage (ColorTemp ctemp, int tran, Imagefloat* image, PreviewP transform (pp, tran, sx1, sy1, sx2, sy2); - int imwidth=image->width,imheight=image->height; + int imwidth=image->width; // Destination image + int imheight=image->height; // Destination image if (((tran & TR_ROT) == TR_R90)||((tran & TR_ROT) == TR_R270)) { int swap = imwidth; imwidth=imheight; imheight=swap; } - int istart = sy1; - int maxx=width,maxy=height; + int maxx=width; // Source image + int maxy=height; // Source image int mtran = tran & TR_ROT; int skip = pp.skip; @@ -116,6 +117,9 @@ void Image8::getStdImage (ColorTemp ctemp, int tran, Imagefloat* image, PreviewP // switched to using ints for the red/green/blue channel buffer. // Incidentally this improves accuracy too. float area=skip*skip; + float rm2=rm; + float gm2=gm; + float bm2=bm; rm/=area; gm/=area; bm/=area; @@ -136,53 +140,98 @@ void Image8::getStdImage (ColorTemp ctemp, int tran, Imagefloat* image, PreviewP #ifdef _OPENMP #pragma omp for #endif - for (int ix=0;ix=maxy-skip) i=maxy-skip-1; // avoid trouble - for (int j=0,jx=sx1; j=maxx-skip) jx=maxx-skip-1; // avoid trouble + // Iterating all the rows of the destination image + for (int iy=0; iy=maxy) + continue; - for (int m=0; m=maxx) + continue; + + convertTo(r(src_y, src_x), r_); + convertTo(g(src_y, src_x), g_); + convertTo(b(src_y, src_x), b_); + lineR[dst_x] = r_; + lineG[dst_x] = g_; + lineB[dst_x] = b_; + } + } + else { + // source image, first line of the current destination row + int src_y=sy1+skip*iy; + if (src_y>=maxy) + continue; + + for (int dst_x=0,src_x=sx1; dst_x=maxx) + continue; + + int src_sub_width = MIN(maxx-src_x, skip); + int src_sub_height = MIN(maxy-src_y, skip); + + float rtot,gtot,btot; // RGB accumulators + rtot=gtot=btot=0.; + + for (int src_sub_y=0; src_sub_yr(ix, j) = lineR[j]; - image->g(ix, j) = lineG[j]; - image->b(ix, j) = lineB[j]; + for (int dst_x=0,src_x=sx1; dst_xr(iy, dst_x) = lineR[dst_x]; + image->g(iy, dst_x) = lineG[dst_x]; + image->b(iy, dst_x) = lineB[dst_x]; } else if (mtran == TR_R180) - for (int j=0; jr(imheight-1-ix, imwidth-1-j) = lineR[j]; - image->g(imheight-1-ix, imwidth-1-j) = lineG[j]; - image->b(imheight-1-ix, imwidth-1-j) = lineB[j]; + for (int dst_x=0; dst_xr(imheight-1-iy, imwidth-1-dst_x) = lineR[dst_x]; + image->g(imheight-1-iy, imwidth-1-dst_x) = lineG[dst_x]; + image->b(imheight-1-iy, imwidth-1-dst_x) = lineB[dst_x]; } else if (mtran == TR_R90) - for (int j=0,jx=sx1; jr(j, imheight-1-ix) = lineR[j]; - image->g(j, imheight-1-ix) = lineG[j]; - image->b(j, imheight-1-ix) = lineB[j]; + for (int dst_x=0,src_x=sx1; dst_xr(dst_x, imheight-1-iy) = lineR[dst_x]; + image->g(dst_x, imheight-1-iy) = lineG[dst_x]; + image->b(dst_x, imheight-1-iy) = lineB[dst_x]; } else if (mtran == TR_R270) - for (int j=0,jx=sx1; jr(imwidth-1-j, ix) = lineR[j]; - image->g(imwidth-1-j, ix) = lineG[j]; - image->b(imwidth-1-j, ix) = lineB[j]; + for (int dst_x=0,src_x=sx1; dst_xr(imwidth-1-dst_x, iy) = lineR[dst_x]; + image->g(imwidth-1-dst_x, iy) = lineG[dst_x]; + image->b(imwidth-1-dst_x, iy) = lineB[dst_x]; } } #ifdef _OPENMP diff --git a/rtengine/imagefloat.cc b/rtengine/imagefloat.cc index 63e9b39f9..96bb85340 100644 --- a/rtengine/imagefloat.cc +++ b/rtengine/imagefloat.cc @@ -126,14 +126,15 @@ void Imagefloat::getStdImage (ColorTemp ctemp, int tran, Imagefloat* image, Prev transform (pp, tran, sx1, sy1, sx2, sy2); - int imwidth=image->width,imheight=image->height; + int imwidth=image->width; // Destination image + int imheight=image->height; // Destination image if (((tran & TR_ROT) == TR_R90)||((tran & TR_ROT) == TR_R270)) { int swap = imwidth; imwidth=imheight; imheight=swap; } - int istart = sy1; - int maxx=width,maxy=height; + int maxx=width; // Source image + int maxy=height; // Source image int mtran = tran & TR_ROT; int skip = pp.skip; @@ -141,6 +142,9 @@ void Imagefloat::getStdImage (ColorTemp ctemp, int tran, Imagefloat* image, Prev // switched to using ints for the red/green/blue channel buffer. // Incidentally this improves accuracy too. float area=skip*skip; + float rm2=rm; + float gm2=gm; + float bm2=bm; rm/=area; gm/=area; bm/=area; @@ -159,48 +163,88 @@ void Imagefloat::getStdImage (ColorTemp ctemp, int tran, Imagefloat* image, Prev #ifdef _OPENMP #pragma omp for #endif - for (int ix=0;ix=maxy-skip) i=maxy-skip-1; // avoid trouble - for (int j=0,jx=sx1; j=maxx-skip) jx=maxx-skip-1; // avoid trouble + for (int iy=0; iy=maxy) + continue; - for (int m=0; m=maxx) + continue; + + lineR[dst_x] = r(src_y, src_x); + lineG[dst_x] = g(src_y, src_x); + lineB[dst_x] = b(src_y, src_x); + } + } + else { + // source image, first line of the current destination row + int src_y=sy1+skip*iy; + if (src_y>=maxy) + continue; + + for (int dst_x=0,src_x=sx1; dst_x=maxx) + continue; + + int src_sub_width = MIN(maxx-src_x, skip); + int src_sub_height = MIN(maxy-src_y, skip); + + float rtot,gtot,btot; // RGB accumulators + rtot=gtot=btot=0.; + + for (int src_sub_y=0; src_sub_yr(ix, j) = lineR[j]; - image->g(ix, j) = lineG[j]; - image->b(ix, j) = lineB[j]; + for (int dst_x=0,src_x=sx1; dst_xr(iy, dst_x) = lineR[dst_x]; + image->g(iy, dst_x) = lineG[dst_x]; + image->b(iy, dst_x) = lineB[dst_x]; } else if (mtran == TR_R180) - for (int j=0; jr(imheight-1-ix, imwidth-1-j) = lineR[j]; - image->g(imheight-1-ix, imwidth-1-j) = lineG[j]; - image->b(imheight-1-ix, imwidth-1-j) = lineB[j]; + for (int dst_x=0; dst_xr(imheight-1-iy, imwidth-1-dst_x) = lineR[dst_x]; + image->g(imheight-1-iy, imwidth-1-dst_x) = lineG[dst_x]; + image->b(imheight-1-iy, imwidth-1-dst_x) = lineB[dst_x]; } else if (mtran == TR_R90) - for (int j=0,jx=sx1; jr(j, imheight-1-ix) = lineR[j]; - image->g(j, imheight-1-ix) = lineG[j]; - image->b(j, imheight-1-ix) = lineB[j]; + for (int dst_x=0,src_x=sx1; dst_xr(dst_x, imheight-1-iy) = lineR[dst_x]; + image->g(dst_x, imheight-1-iy) = lineG[dst_x]; + image->b(dst_x, imheight-1-iy) = lineB[dst_x]; } else if (mtran == TR_R270) - for (int j=0,jx=sx1; jr(imwidth-1-j, ix) = lineR[j]; - image->g(imwidth-1-j, ix) = lineG[j]; - image->b(imwidth-1-j, ix) = lineB[j]; + for (int dst_x=0,src_x=sx1; dst_xr(imwidth-1-dst_x, iy) = lineR[dst_x]; + image->g(imwidth-1-dst_x, iy) = lineG[dst_x]; + image->b(imwidth-1-dst_x, iy) = lineB[dst_x]; } } #ifdef _OPENMP