Skip to content

Commit

Permalink
fix JMTT, closed #127, closed#128
Browse files Browse the repository at this point in the history
  • Loading branch information
Haleydu committed Nov 6, 2020
1 parent 73ea032 commit 8a792ce
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.hiroshi.cimoc.fresco.processor;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;

import com.facebook.cache.common.CacheKey;
import com.facebook.cache.common.SimpleCacheKey;
Expand All @@ -12,6 +14,8 @@
import com.hiroshi.cimoc.rx.RxEvent;
import com.hiroshi.cimoc.utils.StringUtils;

import java.util.Objects;

/**
* Created by Hiroshi on 2017/3/3.
*/
Expand All @@ -26,6 +30,7 @@ public class MangaPostprocessor extends BasePostprocessor {
private int mWidth, mHeight;
private int mPosX, mPosY;
private boolean isDone = false;
private boolean jmttIsDone = false;

public MangaPostprocessor(ImageUrl image, boolean paging, boolean pagingReverse, boolean whiteEdge) {
mImage = image;
Expand All @@ -39,23 +44,33 @@ public CloseableReference<Bitmap> process(Bitmap sourceBitmap, PlatformBitmapFac
mWidth = sourceBitmap.getWidth();
mHeight = sourceBitmap.getHeight();

if (isPaging) {
CloseableReference<Bitmap> reference = bitmapFactory.createBitmap(
mWidth, mHeight, Bitmap.Config.RGB_565);

decodeJMTTImage(sourceBitmap, reference);

if (isPaging && !jmttIsDone) {
preparePaging(isPagingReverse);
isDone = true;
}
if (isWhiteEdge) {

if (isWhiteEdge && !jmttIsDone) {
prepareWhiteEdge(sourceBitmap);
isDone = true;
}

if (isDone) {
CloseableReference<Bitmap> reference = bitmapFactory.createBitmap(mWidth, mHeight, Bitmap.Config.RGB_565);
try {
processing(sourceBitmap, reference.get());
try {
if (isDone) {
if (!jmttIsDone) {
processing(sourceBitmap, reference.get());
}
return CloseableReference.cloneOrNull(reference);

} else if (jmttIsDone) {
return CloseableReference.cloneOrNull(reference);
} finally {
CloseableReference.closeSafely(reference);
}
} finally {
CloseableReference.closeSafely(reference);
}
return super.process(sourceBitmap, bitmapFactory);
}
Expand Down Expand Up @@ -244,4 +259,31 @@ private boolean isWhite(int pixel) {
return gray > 21500;
}

public void decodeJMTTImage(Bitmap sourceBitmap, CloseableReference<Bitmap> reference){
String url = mImage.getUrl();
int scramble_id = 220980;
String id = null;
int chapterId = 0;
if (url.startsWith("file://")){
id = StringUtils.match("Cimoc/download/(72)/", url, 1);
chapterId = Integer.parseInt(Objects.requireNonNull(StringUtils.match("/-photo-(\\d*)/", url, 1)));
}
if((url.contains("media/photos")
&& Integer.parseInt(url.substring(url.indexOf("photos/") + 7, url.lastIndexOf("/"))) > scramble_id)
|| (id != null && !id.equals("") && chapterId>scramble_id)){
Bitmap resultBitmap = reference.get();
float rows = 10;
float chunkHeight = mHeight / rows;
Canvas canvas = new Canvas(resultBitmap);
for (int x = 0; x < 10; x++) {
// 要裁剪的区域
Rect crop = new Rect(0, mHeight - (int) (chunkHeight * (x + 1)), mWidth, mHeight - (int) (chunkHeight * x));
// 裁剪后应放置到新图片对象的区域
Rect splic = new Rect(0, (int) chunkHeight * x, mWidth, (int) chunkHeight * (x + 1));
canvas.drawBitmap(sourceBitmap, crop, splic, null);
}
jmttIsDone=true;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import android.graphics.Rect;
import android.graphics.drawable.Animatable;
import android.net.Uri;

import androidx.annotation.IntDef;
import androidx.recyclerview.widget.RecyclerView;

import android.view.View;
import android.view.ViewGroup;

Expand Down Expand Up @@ -130,14 +132,17 @@ public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatabl
ImageRequest[] request = new ImageRequest[urls.length];
for (int i = 0; i != urls.length; ++i) {
final String url = urls[i];
if (url==null){
continue;
}
ImageRequestBuilder imageRequestBuilder = ImageRequestBuilder
.newBuilderWithSource(Uri.parse(url))
.setProgressiveRenderingEnabled(true);

// TODO 切图后可能需要修改图片高度和宽度
MangaPostprocessor processor = new MangaPostprocessor(imageUrl, isPaging, isPagingReverse, isWhiteEdge);
imageRequestBuilder.setPostprocessor(processor);
if (!isCloseAutoResizeImage) {
if (!isCloseAutoResizeImage) {
ResizeOptions options = isVertical ? new ResizeOptions(App.mWidthPixels, App.mHeightPixels) :
new ResizeOptions(App.mHeightPixels, App.mWidthPixels);
imageRequestBuilder.setResizeOptions(options);
Expand Down Expand Up @@ -242,9 +247,9 @@ public int getPositionByNum(int current, int num, boolean reverse) {
while (mDataSet.get(current).getNum() < num) {
current = reverse ? current - 1 : current + 2;
}
}catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
}finally {
} finally {
return current;
}
}
Expand Down

0 comments on commit 8a792ce

Please sign in to comment.