Skip to content

Commit 3b58449

Browse files
committed
Update for latest RGB
1 parent ff076c7 commit 3b58449

File tree

7 files changed

+16
-17
lines changed

7 files changed

+16
-17
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "imagequant"
3-
version = "4.3.1"
3+
version = "4.3.2"
44
description = "Convert 24/32-bit images to 8-bit palette with alpha channel.\nFor lossy PNG compression and high-quality GIF images\nDual-licensed like pngquant. See https://pngquant.org for details."
55
authors = ["Kornel Lesiński <[email protected]>"]
66
license = "GPL-3.0-or-later"
@@ -32,13 +32,13 @@ doctest = false
3232

3333
[dependencies]
3434
arrayvec = "0.7.4"
35-
rgb = { version = "0.8.37", features = ["argb"] }
35+
rgb = { version = "0.8.47", default-features = false, features = ["bytemuck"] }
3636
rayon = { version = "1.10.0", optional = true }
3737
thread_local = { version = "1.1.8", optional = true }
3838
once_cell = "1.19.0"
3939

4040
[dev-dependencies]
41-
lodepng = "3.10.0"
41+
lodepng = "3.10.4"
4242

4343
[workspace]
4444
members = ["imagequant-sys", "imagequant-sys/c_test"]

src/capi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn liq_get_palette_impl(r: &mut QuantizationResult) -> &Palette {
2424

2525
#[must_use]
2626
pub unsafe fn liq_image_create_rgba_rows_impl<'rows>(attr: &Attributes, rows: &'rows [*const RGBA], width: u32, height: u32, gamma: f64) -> Option<crate::image::Image<'rows>> {
27-
let rows = SeaCow::borrowed(&*(rows as *const [*const rgb::RGBA<u8>] as *const [Pointer<rgb::RGBA<u8>>]));
27+
let rows = SeaCow::borrowed(&*(rows as *const [*const rgb::Rgba<u8>] as *const [Pointer<rgb::Rgba<u8>>]));
2828
let rows_slice = rows.as_slice();
2929
if rows_slice.iter().any(|r| r.0.is_null()) {
3030
return None;

src/hist.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::quant::QuantizationResult;
88
use crate::rows::temp_buf;
99
use crate::rows::DynamicRows;
1010
use crate::Attributes;
11-
use rgb::ComponentSlice;
1211
use std::collections::{HashMap, HashSet};
1312
use std::fmt;
1413
use std::hash::Hash;
@@ -424,7 +423,8 @@ pub(crate) struct HashColor { pub rgba: RGBA, pub index: PalIndex }
424423
impl Hash for HashColor {
425424
#[inline]
426425
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
427-
u32::from_ne_bytes(self.rgba.as_slice().try_into().unwrap()).hash(state);
426+
let s: &[u8] = self.rgba.as_ref();
427+
u32::from_ne_bytes(s.try_into().unwrap()).hash(state);
428428
}
429429
}
430430

src/image.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::seacow::RowBitmap;
88
use crate::seacow::SeaCow;
99
use crate::PushInCapacity;
1010
use crate::LIQ_HIGH_MEMORY_LIMIT;
11-
use rgb::ComponentMap;
11+
use rgb::prelude::*;
1212
use std::mem::MaybeUninit;
1313

1414
/// Describes image dimensions and pixels for the library

src/kmeans.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use crate::nearest::Nearest;
44
use crate::pal::{f_pixel, PalF, PalIndex, PalPop};
55
use crate::rayoff::*;
66
use crate::Error;
7-
use rgb::alt::ARGB;
8-
use rgb::ComponentMap;
7+
use rgb::Argb;
8+
use rgb::prelude::*;
99
use std::cell::RefCell;
1010

1111
/// K-Means iteration: new palette color is computed from weighted average of colors that map best to that palette entry.
@@ -17,7 +17,7 @@ pub(crate) struct Kmeans {
1717

1818
#[derive(Copy, Clone, Default)]
1919
struct ColorAvg {
20-
pub sum: ARGB<f64>,
20+
pub sum: Argb<f64>,
2121
pub total: f64,
2222
}
2323

src/mediancut.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ use crate::pal::{PalLen, ARGBF};
44
use crate::quant::quality_to_mse;
55
use crate::PushInCapacity;
66
use crate::{Error, OrdFloat};
7-
use rgb::ComponentMap;
8-
use rgb::ComponentSlice;
7+
use rgb::prelude::*;
98
use std::cmp::Reverse;
109

1110
struct MedianCutter<'hist> {
@@ -98,7 +97,7 @@ impl<'hist> MBox<'hist> {
9897
}
9998

10099
// Sort dimensions by their variance, and then sort colors first by dimension with the highest variance
101-
let vars = self.variance.as_slice();
100+
let vars: [f32; 4] = rgb::bytemuck::cast(self.variance);
102101
let mut channels = [
103102
ChanVariance { chan: 0, variance: vars[0] },
104103
ChanVariance { chan: 1, variance: vars[1] },
@@ -108,7 +107,7 @@ impl<'hist> MBox<'hist> {
108107
channels.sort_by_key(|a| Reverse(OrdFloat::new(a.variance)));
109108

110109
for a in self.colors.iter_mut() {
111-
let chans = a.color.as_slice();
110+
let chans: [f32; 4] = rgb::bytemuck::cast(a.color.0);
112111
// Only the first channel really matters. But other channels are included, because when trying median cut
113112
// many times with different histogram weights, I don't want sort randomness to influence the outcome.
114113
a.tmp.mc_sort_value = (((chans[channels[0].chan] * 65535.) as u32) << 16)

src/pal.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use crate::OrdFloat;
22
use arrayvec::ArrayVec;
3-
use rgb::ComponentMap;
3+
use rgb::prelude::*;
44
use std::ops::{Deref, DerefMut};
55

66
/// 8-bit RGBA in sRGB. This is the only color format *publicly* used by the library.
7-
pub type RGBA = rgb::RGBA<u8>;
7+
pub type RGBA = rgb::Rgba<u8>;
88

99
#[allow(clippy::upper_case_acronyms)]
10-
pub type ARGBF = rgb::alt::ARGB<f32>;
10+
pub type ARGBF = rgb::Argb<f32>;
1111

1212
pub const INTERNAL_GAMMA: f64 = 0.57;
1313
pub const LIQ_WEIGHT_A: f32 = 0.625;

0 commit comments

Comments
 (0)