Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies #35

Merged
merged 10 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
269 changes: 170 additions & 99 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ crate-type = ["rlib", "cdylib"]

[dependencies]
simple-logging = "2.0.2"
log = "0.4.17"
winreg = "0.10.1"
jxl-oxide = "0.5.1"
log = "0.4.21"
winreg = "0.52.0"
jxl-oxide = "0.7.1"

[dependencies.windows]
version = "0.44.0"
version = "0.54.0"
features = [
"implement",
"Win32_Graphics_Imaging",
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ A JPEG XL (*.jxl) WIC decoder to render thumbnails on Windows File Explorer or v
1. Move to your download directory
1. `regsvr32 jxl_winthumb.dll`, or to uninstall, `regsvr32 /u jxl_winthumb.dll`.

You might need to restart `explorer.exe` or any programs that use the dll before updating it. Get the list of such programs using `tasklist /m jxl_winthumb.dll` and kill them e.g. with `taskkill /f /im explorer.exe && start explorer.exe`.

## Build environment

Use the stable Rust toolchain. Current toolchain as of 23th July 2023 is 1.71.0.
Use the stable Rust toolchain. Current toolchain as of 26th February 2024 is 1.75.0.

## Helpful resources

Expand Down
10 changes: 5 additions & 5 deletions src/dll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct ClassFactory {}
impl IClassFactory_Impl for ClassFactory {
fn CreateInstance(
&self,
outer: &Option<windows::core::IUnknown>,
outer: Option<&windows::core::IUnknown>,
iid: *const GUID,
object: *mut *mut core::ffi::c_void,
) -> windows::core::Result<()> {
Expand All @@ -37,11 +37,11 @@ impl IClassFactory_Impl for ClassFactory {
match *iid {
windows::Win32::Graphics::Imaging::IWICBitmapDecoder::IID => {
let unknown: IUnknown = JXLWICBitmapDecoder::default().into();
unknown.query(&*iid, object as _).ok()
unknown.query(iid, object).ok()
}
windows::Win32::UI::Shell::PropertiesSystem::IPropertyStore::IID => {
let unknown: IUnknown = JXLPropertyStore::default().into();
unknown.query(&*iid, object as _).ok()
unknown.query(iid, object).ok()
}
_ => {
log::trace!("Unknown IID: {:?}", *iid);
Expand Down Expand Up @@ -113,7 +113,7 @@ pub extern "stdcall" fn DllMain(
pub unsafe extern "system" fn DllGetClassObject(
rclsid: *const GUID,
riid: *const GUID,
pout: *mut *const core::ffi::c_void,
pout: *mut *mut core::ffi::c_void,
) -> HRESULT {
// Sets up logging to the Cargo.toml directory for debug purposes.
#[cfg(debug_assertions)]
Expand All @@ -134,7 +134,7 @@ pub unsafe extern "system" fn DllGetClassObject(
let unknown: IUnknown = factory.into();

match *rclsid {
JXLWICBitmapDecoder::CLSID | JXLPropertyStore::CLSID => unknown.query(&*riid, pout),
JXLWICBitmapDecoder::CLSID | JXLPropertyStore::CLSID => unknown.query(riid, pout),
_ => CLASS_E_CLASSNOTAVAILABLE,
}
}
30 changes: 12 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,24 @@ impl JXLWICBitmapDecoder {
}

impl IWICBitmapDecoder_Impl for JXLWICBitmapDecoder {
fn QueryCapability(&self, _pistream: &Option<IStream>) -> windows::core::Result<u32> {
fn QueryCapability(&self, _pistream: Option<&IStream>) -> windows::core::Result<u32> {
log::trace!("QueryCapability");
Ok((WICBitmapDecoderCapabilityCanDecodeSomeImages.0
| WICBitmapDecoderCapabilityCanDecodeAllImages.0) as u32)
}

fn Initialize(
&self,
pistream: &Option<IStream>,
pistream: Option<&IStream>,
_cacheoptions: WICDecodeOptions,
) -> windows::core::Result<()> {
log::trace!("JXLWICBitmapDecoder::Initialize");

let stream = WinStream::from(pistream.to_owned().unwrap());
let stream = WinStream::from(pistream.unwrap());
let reader = BufReader::new(stream);

let image = JxlImage::from_reader(reader).map_err(|err| {
windows::core::Error::new(WINCODEC_ERR_BADIMAGE, format!("{:?}", err).as_str().into())
let image = JxlImage::builder().read(reader).map_err(|err| {
windows::core::Error::new(WINCODEC_ERR_BADIMAGE, format!("{:?}", err))
})?;

let (width, height, _left, _top) = image.image_header().metadata.apply_orientation(
Expand Down Expand Up @@ -102,7 +102,7 @@ impl IWICBitmapDecoder_Impl for JXLWICBitmapDecoder {
}
}

fn CopyPalette(&self, _pipalette: &Option<IWICPalette>) -> windows::core::Result<()> {
fn CopyPalette(&self, _pipalette: Option<&IWICPalette>) -> windows::core::Result<()> {
log::trace!("JXLWICBitmapDecoder::CopyPalette");
// TODO
WINCODEC_ERR_PALETTEUNAVAILABLE.ok()
Expand Down Expand Up @@ -183,10 +183,7 @@ impl IWICBitmapDecoder_Impl for JXLWICBitmapDecoder {
}

let render = decoded.image.render_frame(index as usize).map_err(|err| {
windows::core::Error::new(
WINCODEC_ERR_FRAMEMISSING,
format!("{:?}", err).as_str().into(),
)
windows::core::Error::new(WINCODEC_ERR_FRAMEMISSING, format!("{:?}", err))
})?;

let frame_decode = JXLWICBitmapFrameDecode::new(
Expand Down Expand Up @@ -250,16 +247,13 @@ impl IWICBitmapSource_Impl for JXLWICBitmapFrameDecode {
PixelFormat::Gray => Ok(GUID_WICPixelFormat32bppGrayFloat),
PixelFormat::Graya => Err(windows::core::Error::new(
WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT,
"Gray alpha image is currently not supported".into(),
"Gray alpha image is currently not supported",
)),
PixelFormat::Rgb => Ok(GUID_WICPixelFormat96bppRGBFloat),
PixelFormat::Rgba => Ok(GUID_WICPixelFormat128bppRGBAFloat),
jxl_oxide::PixelFormat::Cmyk | jxl_oxide::PixelFormat::Cmyka => {
Err(windows::core::Error::new(
WINCODEC_ERR_BADIMAGE,
"Cmyk is currently not supported".into(),
))
}
jxl_oxide::PixelFormat::Cmyk | jxl_oxide::PixelFormat::Cmyka => Err(
windows::core::Error::new(WINCODEC_ERR_BADIMAGE, "Cmyk is currently not supported"),
),
}
}

Expand All @@ -273,7 +267,7 @@ impl IWICBitmapSource_Impl for JXLWICBitmapFrameDecode {
Ok(())
}

fn CopyPalette(&self, _pipalette: &Option<IWICPalette>) -> windows::core::Result<()> {
fn CopyPalette(&self, _pipalette: Option<&IWICPalette>) -> windows::core::Result<()> {
log::trace!("JXLWICBitmapFrameDecode::CopyPalette");
WINCODEC_ERR_PALETTEUNAVAILABLE.ok()
}
Expand Down
27 changes: 14 additions & 13 deletions src/properties.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use std::io::BufReader;

use windows as Windows;
use windows::core::{implement, Interface, GUID, HSTRING, PCWSTR};
use windows::core::{implement, Interface, GUID, HSTRING, PCWSTR, PROPVARIANT};
use windows::Win32::{
Foundation::*,
System::Com::IStream,
System::Com::StructuredStorage::PROPVARIANT,
System::Com::{
IStream,
StructuredStorage::{InitPropVariantFromStringVector, InitPropVariantFromUInt32Vector},
},
UI::Shell::PropertiesSystem::{
IInitializeWithStream_Impl, IPropertyStoreCache, IPropertyStoreCapabilities_Impl,
IPropertyStore_Impl, InitPropVariantFromStringVector, InitPropVariantFromUInt32Vector,
PSCreateMemoryPropertyStore, PROPERTYKEY, PSC_READONLY,
IPropertyStore_Impl, PSCreateMemoryPropertyStore, PROPERTYKEY, PSC_READONLY,
},
};

Expand All @@ -33,7 +34,7 @@ impl JXLPropertyStore {
if self.props.is_none() {
return Err(windows::core::Error::new(
WINCODEC_ERR_NOTINITIALIZED,
"Property store not initialized".into(),
"Property store not initialized",
));
}

Expand All @@ -42,12 +43,12 @@ impl JXLPropertyStore {
}

impl IInitializeWithStream_Impl for JXLPropertyStore {
fn Initialize(&self, pstream: &Option<IStream>, _grfmode: u32) -> windows::core::Result<()> {
let stream = WinStream::from(pstream.to_owned().unwrap());
fn Initialize(&self, pstream: Option<&IStream>, _grfmode: u32) -> windows::core::Result<()> {
let stream = WinStream::from(pstream.unwrap());
let reader = BufReader::new(stream);

let image = JxlImage::from_reader(reader).map_err(|err| {
windows::core::Error::new(WINCODEC_ERR_BADIMAGE, format!("{:?}", err).as_str().into())
let image = JxlImage::builder().read(reader).map_err(|err| {
windows::core::Error::new(WINCODEC_ERR_BADIMAGE, format!("{:?}", err))
})?;

let (width, height, _left, _top) = image.image_header().metadata.apply_orientation(
Expand Down Expand Up @@ -125,14 +126,14 @@ impl IPropertyStore_Impl for JXLPropertyStore {
) -> windows::core::Result<()> {
Err(windows::core::Error::new(
WINCODEC_ERR_UNSUPPORTEDOPERATION,
"Setter not supported".into(),
"Setter not supported",
))
}

fn Commit(&self) -> windows::core::Result<()> {
Err(windows::core::Error::new(
WINCODEC_ERR_UNSUPPORTEDOPERATION,
"Setter not supported".into(),
"Setter not supported",
))
}
}
Expand All @@ -141,7 +142,7 @@ impl IPropertyStoreCapabilities_Impl for JXLPropertyStore {
fn IsPropertyWritable(&self, _key: *const PROPERTYKEY) -> windows::core::Result<()> {
Err(windows::core::Error::new(
WINCODEC_ERR_UNSUPPORTEDOPERATION,
"Setter not supported".into(),
"Setter not supported",
))
}
}
10 changes: 5 additions & 5 deletions src/winstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ use std::io::{ErrorKind, Read};

use windows::Win32::System::Com::IStream;

pub struct WinStream {
stream: IStream,
pub struct WinStream<'a> {
stream: &'a IStream,
}

impl From<IStream> for WinStream {
fn from(stream: IStream) -> Self {
impl<'a> From<&'a IStream> for WinStream<'a> {
fn from(stream: &'a IStream) -> Self {
Self { stream }
}
}

impl Read for WinStream {
impl<'a> Read for WinStream<'a> {
fn read(&mut self, buf: &mut [u8]) -> Result<usize, std::io::Error> {
let mut bytes_read = 0u32;
unsafe {
Expand Down
2 changes: 1 addition & 1 deletion tests/wic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use windows::Win32::UI::Shell::SHCreateMemStream;

#[test]
fn basic() {
unsafe { CoInitialize(None) }.expect("CoInitialize");
unsafe { CoInitialize(None) }.ok().expect("CoInitialize");

let mem = std::fs::read("tests/alien.jxl").expect("Read the test file");
let stream = unsafe { SHCreateMemStream(Some(&mem[..])) }.expect("Create an IStream");
Expand Down
Loading