Skip to content

Commit

Permalink
Merge pull request #78 from kozakura913/jpeg-xl
Browse files Browse the repository at this point in the history
JpegXLデコーダの追加
  • Loading branch information
kozakura913 authored Dec 28, 2024
2 parents 8d5a8f8 + c1e52f6 commit 9529ac6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ rexif = "0.7"
avif-decoder_dep = { path="./avif-decoder_dep" ,optional = true }
chrono = "0.4"
fast_image_resize = "3.0"
jxl-oxide = {version="0.11.0",features = [ "image","lcms2" ] }

[profile.release]
strip = true
Expand Down
5 changes: 5 additions & 0 deletions src/img.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ impl RequestContext{
let codec=match &self.codec{
Ok(codec) => codec,
Err(e) => {
if self.headers.get("Content-Type").map(|s|std::str::from_utf8(s.as_bytes()))==Some(Ok("image/jxl")){
let decoder = jxl_oxide::integration::JxlDecoder::new(std::io::Cursor::new(&self.src_bytes)).expect("cannot decode image");
let img = DynamicImage::from_decoder(decoder).expect("cannot decode image");
return self.response_img(img);
}
self.headers.append("X-Proxy-Error",format!("CodecError:{:?}",e).parse().unwrap());
return (axum::http::StatusCode::BAD_GATEWAY,self.headers.clone()).into_response();
},
Expand Down
7 changes: 6 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ impl RequestContext{
}
}
impl RequestContext{
async fn encode(&mut self,resp: reqwest::Response,is_img:bool)->Result<(axum::http::StatusCode,axum::headers::HeaderMap,StreamBody<impl futures::Stream<Item = Result<axum::body::Bytes, reqwest::Error>>>),axum::response::Response>{
async fn encode(&mut self,resp: reqwest::Response,mut is_img:bool)->Result<(axum::http::StatusCode,axum::headers::HeaderMap,StreamBody<impl futures::Stream<Item = Result<axum::body::Bytes, reqwest::Error>>>),axum::response::Response>{
let mut is_svg=false;
let mut content_type=None;
if let Some(media)=self.headers.get("Content-Type"){
Expand All @@ -348,6 +348,11 @@ impl RequestContext{
_=>{}
}
}
if head.starts_with(&[0xFF,0x0A])||head.starts_with(&[0x00,0x00,0x00,0x0C,0x4A,0x58,0x4C,0x20,0x0D,0x0A,0x87,0x0A]){
is_img=true;
self.headers.remove("Content-Type");
self.headers.append("Content-Type", "image/jxl".parse().unwrap());
}
}
}
}
Expand Down

0 comments on commit 9529ac6

Please sign in to comment.