Skip to content

Commit 5b391a6

Browse files
committed
Improve QImage support
1 parent 15c584d commit 5b391a6

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

crates/cxx-qt-lib-headers/include/gui/qimage.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ QImage
2929
qimageInitFromData(const rust::Slice<std::uint8_t const> data,
3030
rust::Str format);
3131

32+
::std::int64_t
33+
qimageCacheKey(const QImage& image);
34+
3235
} // namespace cxxqtlib1
3336
} // namespace rust
3437
#endif

crates/cxx-qt-lib/src/gui/qimage.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ qimageInitFromData(const rust::Slice<std::uint8_t const> data, rust::Str format)
4545
formatString.empty() ? nullptr : formatString.data());
4646
}
4747

48+
::std::int64_t
49+
qimageCacheKey(const QImage& image)
50+
{
51+
return static_cast<::std::int64_t>(image.cacheKey());
52+
}
4853
}
4954
}
5055

crates/cxx-qt-lib/src/gui/qimage.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,65 @@ mod ffi {
1111
unsafe extern "C++" {
1212
include!("cxx-qt-lib/qimage.h");
1313
type QImage = super::QImage;
14+
include!("cxx-qt-lib/qsize.h");
15+
type QSize = crate::QSize;
16+
include!("cxx-qt-lib/qrect.h");
17+
type QRect = crate::QRect;
18+
include!("cxx-qt-lib/qcolor.h");
19+
type QColor = crate::QColor;
1420

1521
/// Whether the QImage is null.
1622
///
1723
/// This means that the QImage has all parameters set to zero and no allocated data.
1824
#[rust_name = "is_null"]
1925
fn isNull(self: &QImage) -> bool;
26+
27+
/// Returns true if all the colors in the image are shades of gray
28+
#[rust_name = "all_gray"]
29+
fn allGray(self: &QImage) -> bool;
30+
31+
/// For 32-bit images, this function is equivalent to allGray().
32+
/// For color indexed images, this function returns true if color(i) is QRgb(i, i, i)
33+
/// for all indexes of the color table; otherwise returns false.
34+
#[rust_name = "is_gray_scale"]
35+
fn isGrayscale(self: &QImage) -> bool;
36+
37+
/// Returns true if the image has a format that respects the alpha channel, otherwise returns false.
38+
#[rust_name = "has_alpha_channel"]
39+
fn hasAlphaChannel(self: &QImage) -> bool;
40+
41+
/// Returns the size of the color table for the image.
42+
#[rust_name = "color_count"]
43+
fn colorCount(self: &QImage) -> i32;
44+
45+
/// Returns the depth of the image.
46+
fn depth(self: &QImage) -> i32;
47+
48+
/// Returns the height of the image.
49+
fn height(self: &QImage) -> i32;
50+
51+
/// Returns the width of the image.
52+
fn width(self: &QImage) -> i32;
53+
54+
/// Returns the size of the image.
55+
fn size(self: &QImage) -> QSize;
56+
57+
/// Returns the enclosing rectangle (0, 0, width(), height()) of the image.
58+
fn rect(self: &QImage) -> QRect;
59+
60+
/// Returns the color of the pixel at coordinates (x, y) as a QColor.
61+
#[rust_name = "pixel_color"]
62+
fn pixelColor(self: &QImage, x: i32, y: i32) -> QColor;
63+
64+
/// Returns the number of pixels that fit horizontally in a physical meter.
65+
#[rust_name = "dots_per_meterx"]
66+
fn dotsPerMeterX(self: &QImage) -> i32;
67+
68+
/// Returns the number of pixels that fit vertically in a physical meter.
69+
#[rust_name = "dots_per_metery"]
70+
fn dotsPerMeterY(self: &QImage) -> i32;
71+
72+
fn valid(self: &QImage, x: i32, y: i32) -> bool;
2073
}
2174

2275
#[namespace = "rust::cxxqtlib1"]
@@ -30,6 +83,10 @@ mod ffi {
3083
#[doc(hidden)]
3184
#[rust_name = "qimage_init_from_data"]
3285
fn qimageInitFromData(data: &[u8], format: &str) -> QImage;
86+
87+
#[doc(hidden)]
88+
#[rust_name = "qimage_cache_key"]
89+
fn qimageCacheKey(image: &QImage) -> i64;
3390
}
3491
}
3592

@@ -79,4 +136,8 @@ impl QImage {
79136
None
80137
}
81138
}
139+
/// Returns a number that identifies the contents of this QImage object.
140+
pub fn cache_key(&self) -> i64 {
141+
ffi::qimage_cache_key(self)
142+
}
82143
}

0 commit comments

Comments
 (0)