mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 21:27:34 +00:00
LibGfx: Read rendering intent from ICCProfile header
This commit is contained in:
parent
ac039d93f0
commit
743e9fc786
2 changed files with 44 additions and 0 deletions
|
@ -160,6 +160,22 @@ ErrorOr<ColorSpace> parse_data_color_space(ICCHeader const& header)
|
||||||
return Error::from_string_literal("ICC::Profile: Invalid data color space");
|
return Error::from_string_literal("ICC::Profile: Invalid data color space");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ErrorOr<RenderingIntent> parse_rendering_intent(ICCHeader const& header)
|
||||||
|
{
|
||||||
|
// ICC v4, 7.2.15 Rendering intent field
|
||||||
|
switch (header.rendering_intent) {
|
||||||
|
case 0:
|
||||||
|
return RenderingIntent::Perceptual;
|
||||||
|
case 1:
|
||||||
|
return RenderingIntent::MediaRelativeColorimetric;
|
||||||
|
case 2:
|
||||||
|
return RenderingIntent::Saturation;
|
||||||
|
case 3:
|
||||||
|
return RenderingIntent::ICCAbsoluteColorimetric;
|
||||||
|
}
|
||||||
|
return Error::from_string_literal("ICC::Profile: Invalid rendering intent");
|
||||||
|
}
|
||||||
|
|
||||||
ErrorOr<time_t> parse_creation_date_time(ICCHeader const& header)
|
ErrorOr<time_t> parse_creation_date_time(ICCHeader const& header)
|
||||||
{
|
{
|
||||||
// iCC v4, 7.2.8 Date and time field
|
// iCC v4, 7.2.8 Date and time field
|
||||||
|
@ -255,6 +271,22 @@ char const* color_space_name(ColorSpace color_space)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char const* rendering_intent_name(RenderingIntent rendering_intent)
|
||||||
|
{
|
||||||
|
switch (rendering_intent) {
|
||||||
|
case RenderingIntent::Perceptual:
|
||||||
|
return "Perceptual";
|
||||||
|
case RenderingIntent::MediaRelativeColorimetric:
|
||||||
|
return "Media-relative colorimetric";
|
||||||
|
case RenderingIntent::Saturation:
|
||||||
|
return "Saturation";
|
||||||
|
case RenderingIntent::ICCAbsoluteColorimetric:
|
||||||
|
return "ICC-absolute colorimetric";
|
||||||
|
default:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ErrorOr<NonnullRefPtr<Profile>> Profile::try_load_from_externally_owned_memory(ReadonlyBytes bytes)
|
ErrorOr<NonnullRefPtr<Profile>> Profile::try_load_from_externally_owned_memory(ReadonlyBytes bytes)
|
||||||
{
|
{
|
||||||
auto profile = adopt_ref(*new Profile());
|
auto profile = adopt_ref(*new Profile());
|
||||||
|
@ -269,6 +301,7 @@ ErrorOr<NonnullRefPtr<Profile>> Profile::try_load_from_externally_owned_memory(R
|
||||||
profile->m_device_class = TRY(parse_device_class(header));
|
profile->m_device_class = TRY(parse_device_class(header));
|
||||||
profile->m_data_color_space = TRY(parse_data_color_space(header));
|
profile->m_data_color_space = TRY(parse_data_color_space(header));
|
||||||
profile->m_creation_timestamp = TRY(parse_creation_date_time(header));
|
profile->m_creation_timestamp = TRY(parse_creation_date_time(header));
|
||||||
|
profile->m_rendering_intent = TRY(parse_rendering_intent(header));
|
||||||
|
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,6 +75,15 @@ enum class ColorSpace : u32 {
|
||||||
};
|
};
|
||||||
char const* color_space_name(ColorSpace);
|
char const* color_space_name(ColorSpace);
|
||||||
|
|
||||||
|
// ICC v4, 7.2.15 Rendering intent field
|
||||||
|
enum class RenderingIntent {
|
||||||
|
Perceptual,
|
||||||
|
MediaRelativeColorimetric,
|
||||||
|
Saturation,
|
||||||
|
ICCAbsoluteColorimetric,
|
||||||
|
};
|
||||||
|
char const* rendering_intent_name(RenderingIntent);
|
||||||
|
|
||||||
class Profile : public RefCounted<Profile> {
|
class Profile : public RefCounted<Profile> {
|
||||||
public:
|
public:
|
||||||
static ErrorOr<NonnullRefPtr<Profile>> try_load_from_externally_owned_memory(ReadonlyBytes bytes);
|
static ErrorOr<NonnullRefPtr<Profile>> try_load_from_externally_owned_memory(ReadonlyBytes bytes);
|
||||||
|
@ -83,12 +92,14 @@ public:
|
||||||
DeviceClass device_class() const { return m_device_class; }
|
DeviceClass device_class() const { return m_device_class; }
|
||||||
ColorSpace data_color_space() const { return m_data_color_space; }
|
ColorSpace data_color_space() const { return m_data_color_space; }
|
||||||
time_t creation_timestamp() const { return m_creation_timestamp; }
|
time_t creation_timestamp() const { return m_creation_timestamp; }
|
||||||
|
RenderingIntent rendering_intent() const { return m_rendering_intent; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Version m_version;
|
Version m_version;
|
||||||
DeviceClass m_device_class;
|
DeviceClass m_device_class;
|
||||||
ColorSpace m_data_color_space;
|
ColorSpace m_data_color_space;
|
||||||
time_t m_creation_timestamp;
|
time_t m_creation_timestamp;
|
||||||
|
RenderingIntent m_rendering_intent;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue