-
Notifications
You must be signed in to change notification settings - Fork 603
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
Add get_texture_info_type to query TypeDesc of arbitrary texture metadata #3207
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2822,6 +2822,48 @@ ImageCacheImpl::get_image_info(ImageCacheFile* file, | |
#undef ATTR_DECODE | ||
} | ||
|
||
bool | ||
ImageCacheImpl::get_image_info_type(ustring filename, int subimage, | ||
int miplevel, ustring dataname, | ||
TypeDesc& datatype) | ||
{ | ||
ImageCachePerThreadInfo* thread_info = get_perthread_info(); | ||
ImageCacheFile* file = find_file(filename, thread_info, nullptr); | ||
if (!file && dataname != s_exists) { | ||
error("Invalid image file \"{}\"", filename); | ||
return false; | ||
} | ||
return get_image_info_type(file, thread_info, subimage, miplevel, dataname, | ||
datatype); | ||
} | ||
|
||
bool | ||
ImageCacheImpl::get_image_info_type(ImageCacheFile* file, | ||
ImageCachePerThreadInfo* thread_info, | ||
int subimage, int miplevel, | ||
ustring dataname, TypeDesc& datatype) | ||
{ | ||
// Output the TypeDesc of a given attribute (if found). If not found | ||
// we set it to UNKNOWN. | ||
|
||
ImageCacheStatistics& stats(thread_info->m_stats); | ||
++stats.imageinfo_queries; | ||
file = verify_file(file, thread_info, true); | ||
|
||
const ImageSpec& spec(file->spec(subimage, miplevel)); | ||
ParamValue tmpparam; | ||
const ParamValue* p = spec.find_attribute(dataname, tmpparam); | ||
|
||
if (p) { | ||
datatype = p->type(); | ||
return true; | ||
} | ||
|
||
// Does it make sense to set the type here, or should we just return | ||
// false? | ||
datatype.basetype = TypeDesc::UNKNOWN; | ||
return false; | ||
Comment on lines
+2854
to
+2865
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these lines can simply be
and the return type for This matches the way we've already done Also, the ImageSpec::getattributetype works even if it's one of the "built-in" fields, and isn't restricted to the "extra" attributes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I take back that last sentence partially -- ImageSpec::getattributetype will only work for things that are in the ImageSpec (extra_args but also some other hard fields). But what this implementation of get_image_info_type won't be able to do is retrieve any of the other kinds of queries that get_image_info knows about that don't correspond to the ImageSpec, unless you are inclined to replicate much of that logic here. |
||
} | ||
|
||
|
||
bool | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -842,6 +842,14 @@ class ImageCacheImpl final : public ImageCache { | |
int subimage, int miplevel, ustring dataname, | ||
TypeDesc datatype, void* data); | ||
|
||
virtual bool get_image_info_type(ustring filename, int subimage, | ||
int miplevel, ustring dataname, | ||
TypeDesc& datatype); | ||
virtual bool get_image_info_type(ImageCacheFile* file, | ||
Comment on lines
+845
to
+848
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's just have these return the TypeDesc directly, since that's the way the equivalent works in other places we have a "get attribute type" kind of method. You don't need the bool return since there is already a special TypeDesc value ( |
||
ImageCachePerThreadInfo* thread_info, | ||
int subimage, int miplevel, | ||
ustring dataname, TypeDesc& datatype); | ||
|
||
/// Get the ImageSpec associated with the named image. If the file | ||
/// is found and is an image format that can be read, store a copy | ||
/// of its specification in spec and return true. Return false if | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See lines 2581ff, where get_image_info checks and gives appropriate errors and early exit for a null
file
, and lines 2672ff, where it handles non-existant subimage or miplevel. I think we need to do this here as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... that comment doesn't seem to have gotten associated with the right spot in your code. :-)
I was trying to point this out in get_image_info_type, line 2853 (of your changes), right before you dereference
file
and ask for the spec for this specific subimage and miplevel.