Cleanup
This commit is contained in:
1 parent
c07c663105
commit
660d6e32f1
6 files changed
+13
-15
No files matched your search
@@ -1,5 +1,5 @@
|
||||
use crate::{jni_throwing, with_bitmap_content};
|
||||
use anyhow::anyhow;
|
||||
use anyhow::Context;
|
||||
use image::{ImageBuffer, Luma, Pixel, Rgba};
|
||||
use jni::objects::JClass;
|
||||
use jni::sys::{jintArray, jobject};
|
||||
@@ -89,7 +89,7 @@ pub fn detectBorder(mut env: JNIEnv, _class: JClass, object: jobject) -> jintArr
|
||||
jni_throwing(&mut env, |env| {
|
||||
let slice = with_bitmap_content(env, object, |img| Ok(detect_border(&img)))?;
|
||||
let array = env.new_int_array(4)?;
|
||||
env.set_int_array_region(&array, 0, &slice.ok_or(anyhow!("Image too small!"))?)?;
|
||||
env.set_int_array_region(&array, 0, &slice.context("Image too small!")?)?;
|
||||
Ok(array.into_raw())
|
||||
})
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
#![cfg(feature = "api-level-26")]
|
||||
|
||||
use crate::{jni_throwing, with_bitmap_content};
|
||||
use anyhow::anyhow;
|
||||
use anyhow::Context;
|
||||
use image::{GenericImage, GenericImageView, ImageBuffer};
|
||||
use jni::objects::JClass;
|
||||
use jni::sys::{jint, jobject};
|
||||
@@ -22,7 +22,7 @@ pub fn copyBitmapToAHB(mut env: JNIEnv, _: JClass, bm: jobject, ahb: jobject, x:
|
||||
let view = src.view(x as u32, y as u32, w, h);
|
||||
let ptr = ahb.lock(HardwareBufferUsage::CPU_WRITE_RARELY, None, None)? as *mut u8;
|
||||
let s = unsafe { &mut *slice_from_raw_parts_mut(ptr, (stride * h * 4) as usize) };
|
||||
let dst = ImageBuffer::from_raw(stride, h, s).ok_or(anyhow!("Illegal AHB format!"));
|
||||
let dst = ImageBuffer::from_raw(stride, h, s).context("Illegal AHB format!");
|
||||
let result = dst.map(|mut dst| dst.copy_from(view.deref(), 0, 0));
|
||||
ahb.unlock()?;
|
||||
result??;
|
||||
|
||||
@@ -2,7 +2,7 @@ mod img;
|
||||
mod parser;
|
||||
|
||||
use android_logger::Config;
|
||||
use anyhow::{anyhow, ensure, Result};
|
||||
use anyhow::{ensure, Context, Result};
|
||||
use image::{ImageBuffer, Rgba};
|
||||
use jni::objects::JByteBuffer;
|
||||
use jni::sys::{jboolean, jint, jobject, JavaVM, JNI_VERSION_1_6};
|
||||
@@ -120,7 +120,7 @@ where
|
||||
// SAFETY: ktor client ensure html content is valid utf-8.
|
||||
let html = unsafe { from_utf8_unchecked(&buffer[..limit as usize]) };
|
||||
|
||||
let dom = tl::parse(html, ParserOptions::default()).map_err(|e| anyhow!(e))?;
|
||||
let dom = tl::parse(html, ParserOptions::default())?;
|
||||
ensure!(dom.version().is_some(), "{html}");
|
||||
f(&dom, html)?
|
||||
};
|
||||
@@ -168,9 +168,7 @@ where
|
||||
let buffer = unsafe { &*slice_from_raw_parts(ptr, (width * height * 4) as usize) };
|
||||
|
||||
let image = ImageBuffer::from_raw(width, height, buffer);
|
||||
let result = image
|
||||
.ok_or(anyhow!("Image buffer not RGBA8888!!!"))
|
||||
.and_then(f);
|
||||
let result = image.context("Image buffer not RGBA8888!!!").and_then(f);
|
||||
handle.unlock_pixels()?;
|
||||
result
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::{get_vdom_first_element_by_class_name, parse_marshal_inplace};
|
||||
use anyhow::anyhow;
|
||||
use anyhow::Context;
|
||||
use jni::objects::{JByteBuffer, JClass};
|
||||
use jni::sys::jint;
|
||||
use jni::JNIEnv;
|
||||
@@ -52,6 +52,6 @@ fn parse_limit(dom: &VDom, parser: &Parser) -> Option<Limits> {
|
||||
#[jni_fn("com.hippo.ehviewer.client.parser.HomeParserKt")]
|
||||
pub fn parseLimit(mut env: JNIEnv, _class: JClass, input: JByteBuffer, limit: jint) -> jint {
|
||||
parse_marshal_inplace(&mut env, input, limit, |dom, _| {
|
||||
parse_limit(dom, dom.parser()).ok_or(anyhow!("Can't parse Limit"))
|
||||
parse_limit(dom, dom.parser()).context("Can't parse Limit")
|
||||
})
|
||||
}
|
||||
@@ -3,7 +3,7 @@ use crate::{get_element_by_id, get_vdom_first_element_by_class_name};
|
||||
use crate::{get_first_element_by_class_name, query_childs_first_match_attr};
|
||||
use crate::{get_node_attr, get_node_handle_attr, regex};
|
||||
use crate::{EHGT_PREFIX, EX_PREFIX};
|
||||
use anyhow::{anyhow, bail, Result};
|
||||
use anyhow::{bail, Context, Result};
|
||||
use jni::objects::{JByteBuffer, JClass};
|
||||
use jni::sys::jint;
|
||||
use jni::JNIEnv;
|
||||
@@ -235,7 +235,7 @@ pub fn parse_info_list(dom: &VDom, parser: &Parser, str: &str) -> Result<Gallery
|
||||
galleryInfoList: info,
|
||||
})
|
||||
};
|
||||
f().ok_or(anyhow!("No content"))
|
||||
f().context("No content")
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::{parse_marshal_inplace, regex};
|
||||
use anyhow::{anyhow, Result};
|
||||
use anyhow::{Context, Result};
|
||||
use jni::objects::{JByteBuffer, JClass};
|
||||
use jni::sys::jint;
|
||||
use jni::JNIEnv;
|
||||
@@ -22,7 +22,7 @@ struct Torrent {
|
||||
}
|
||||
|
||||
fn parse_torrent_list(dom: &VDom, parser: &Parser) -> Result<Vec<Torrent>> {
|
||||
let list = dom.query_selector("table").ok_or(anyhow!("No Table"))?.filter_map(|e| {
|
||||
let list = dom.query_selector("table").context("No Table")?.filter_map(|e| {
|
||||
let html = e.get(parser)?.inner_html(parser);
|
||||
if html.contains("Expunged") {
|
||||
None
|
||||
|
||||
Reference in new issue
Block a user