Skip to content

Commit

Permalink
Won't crop if not needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
shliama committed May 2, 2016
1 parent 5a3e974 commit f24250c
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,6 @@ public void setImageToWrapCropBounds(boolean animate) {

deltaScale = Math.max(tempCropRect.width() / currentImageSides[0],
tempCropRect.height() / currentImageSides[1]);
// Ugly but there are always couple pixels that want to hide because of all these calculations
deltaScale *= 1.01;
deltaScale = deltaScale * currentScale - currentScale;
}

Expand Down
42 changes: 24 additions & 18 deletions ucrop/src/main/jni/uCrop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,31 +53,37 @@ JNIEXPORT jboolean JNICALL Java_com_yalantis_ucrop_task_BitmapCropTask_cropCImg
img.resize(size_x, size_y, size_z, size_c, interpolation_type, boundary_conditions, centering_x, centering_y, centering_z, centering_c);
}

// Create warp field.
CImg<float> warp(cimg::abs(x1 - x0 + 1), cimg::abs(y1 - y0 + 1), 1, 2);

const float
rad = angle * cimg::PI/180,
ca = std::cos(rad), sa = std::sin(rad),
ux = cimg::abs(img.width() * ca), uy = cimg::abs(img.width() * sa),
vx = cimg::abs(img.height() * sa), vy = cimg::abs(img.height() * ca),
w2 = 0.5f * img.width(), h2 = 0.5f * img.height(),
dw2 = 0.5f * (ux + vx), dh2 = 0.5f * (uy + vy);

cimg_forXY(warp, x, y) {
const float
u = x + x0 - dw2, v = y + y0 - dh2;
if (!(img.width() == width && img.height() == height && angle == 0)) {

warp(x, y, 0) = w2 + u*ca + v*sa;
warp(x, y, 1) = h2 - u*sa + v*ca;
// Create warp field.
CImg<float> warp(cimg::abs(x1 - x0 + 1), cimg::abs(y1 - y0 + 1), 1, 2);

const float
rad = angle * cimg::PI/180,
ca = std::cos(rad), sa = std::sin(rad),
ux = cimg::abs(img.width() * ca), uy = cimg::abs(img.width() * sa),
vx = cimg::abs(img.height() * sa), vy = cimg::abs(img.height() * ca),
w2 = 0.5f * img.width(), h2 = 0.5f * img.height(),
dw2 = 0.5f * (ux + vx), dh2 = 0.5f * (uy + vy);

cimg_forXY(warp, x, y) {
const float
u = x + x0 - dw2, v = y + y0 - dh2;

warp(x, y, 0) = w2 + u*ca + v*sa;
warp(x, y, 1) = h2 - u*sa + v*ca;
}

img = img.get_warp(warp, 0, 1, 2);
}

if (format == SAVE_FORMAT_JPEG) {
img.get_warp(warp, 0, 1, 2).save_jpeg(file_result_path, quality);
img.save_jpeg(file_result_path, quality);
} else if (format == SAVE_FORMAT_PNG) {
img.get_warp(warp, 0, 1, 2).save_png(file_result_path, 0);
img.save_png(file_result_path, 0);
} else {
img.get_warp(warp, 0, 1, 2).save(file_result_path);
img.save(file_result_path);
}

~img;
Expand Down
Binary file modified ucrop/src/main/jniLibs/arm64-v8a/libucrop.so
Binary file not shown.
Binary file modified ucrop/src/main/jniLibs/armeabi-v7a/libucrop.so
Binary file not shown.
Binary file modified ucrop/src/main/jniLibs/armeabi/libucrop.so
Binary file not shown.
Binary file modified ucrop/src/main/jniLibs/mips/libucrop.so
Binary file not shown.
Binary file modified ucrop/src/main/jniLibs/mips64/libucrop.so
Binary file not shown.
Binary file modified ucrop/src/main/jniLibs/x86/libucrop.so
Binary file not shown.
Binary file modified ucrop/src/main/jniLibs/x86_64/libucrop.so
Binary file not shown.

0 comments on commit f24250c

Please sign in to comment.