[GSoC 2022] Multipage Image Decoder API#22128
Conversation
|
OpenCV API is primary C++ based. However we need to think about Python, Java bindings - and support them too. |
|
@alalek I am planning to do Python and Java bindings after we finalize this API interface. Thanks for the reminder! |
|
@ocpalo, thank you! Please, rename PR so that the title contains [GSoC 2022] in the beginning. |
|
I think I can remove the cv::Exception part from the API and provide error codes. This way, API would be more efficient. |
d85931b to
7a5d89e
Compare
|
@ocpalo, overall, it looks good now. I put a couple of small comments. |
|
ok, I realized that init() reassigned m_decoder, so it should be closed automatically. |
fbed6c0 to
79856ab
Compare
asmorkalov
left a comment
There was a problem hiding this comment.
The solution looks very good for me! It's the next step for HEIF support and it's analogues.
modules/imgcodecs/src/loadsave.cpp
Outdated
| } | ||
|
|
||
| Mat& ImageCollection::Impl::operator[](int index) { | ||
| if(m_pages[index].empty()) { |
There was a problem hiding this comment.
Out-of-range access check is required here.
There was a problem hiding this comment.
range is already checked at the external method ImageCollection::at() method
There was a problem hiding this comment.
There are 2 methods in the ImageCollection to read images. .at() method and operator[] operator. As in the STD containers, .at method does out-of-range access check but operator[] does not. There is no need to check here.
There was a problem hiding this comment.
at() calls operator[], but not vise versa. In case if index is -1 you'll get out of bound access for std::vector. For index, let say 1e+6 the next loop will be iterated 1e+6 times: for(int i = 0; i != index && advance(); ++i) {}. I propose to move the check from at() to operator[] or have it in both methods. In std::vector<> is reasonable to get rid of range check for performance reason. Range check is heavier than actual work. But it's not true for image codecs. Also it could be a security issue.
3c22310 to
d7a3bef
Compare
|
I made the fixes. Please take a look again @vpisarev @asmorkalov. ALso, the Windows10-x64 fail is not related with my pull request. Please rerun that workflow only if you can. I need to push commit to re-run all workflows. |
asmorkalov
left a comment
There was a problem hiding this comment.
I'll take a look on CI issue. Please ignore it for now.
modules/imgcodecs/src/loadsave.cpp
Outdated
| } | ||
|
|
||
| Mat& ImageCollection::Impl::operator[](int index) { | ||
| if(m_pages[index].empty()) { |
There was a problem hiding this comment.
at() calls operator[], but not vise versa. In case if index is -1 you'll get out of bound access for std::vector. For index, let say 1e+6 the next loop will be iterated 1e+6 times: for(int i = 0; i != index && advance(); ++i) {}. I propose to move the check from at() to operator[] or have it in both methods. In std::vector<> is reasonable to get rid of range check for performance reason. Range check is heavier than actual work. But it's not true for image codecs. Also it could be a security issue.
|
@asmorkalov Regarding this comment, I have changed the std::vector Somehow i can not reply to your comment. That is why i wrote here as seperate comment. Thanks for the dealing with the CI issue! Mat& ImageCollection::Impl::operator[](int index) {
if(m_pages.at(index).empty()) { |
|
The current iterator api does not implements operator->. Should I? struct CV_EXPORTS iterator {
Mat* operator->();
...
}
Mat* ImageCollection::iterator::operator->() {
CV_Assert(m_pCollection);
return &m_pCollection->getImpl()->operator[](m_curr);
}So one can use this to do operations on the cache Mat objects. And I realized that my @asmorkalov , Could you take a look at my last commit and tell me what do you think? I have checked the std::vector::at() implementation. This also returns reference type. I also pushed the test that Vadim sent me to see if operator++ is works as expected. Since both of you suspected that it is a bug. Edit: CI fails does not related with my commits again. |
88f0436 to
cba8d3f
Compare
|
Further explanation about
When So what happens if |
Rename - it's good idea. |
|
it makes sense to return |
|
@ocpalo Please make operator[] and at() return values constant reference and squash commits. I'll merge the patch then. |
|
Ok. Give me an hour or two. Thank you for the reviews btw. |
cba8d3f to
062cee2
Compare
|
@asmorkalov I have made the changes and pushed. Tbh, I do not understand why we force users to use If we keep cv::Mat& firstPage = collection[0]; // 1
const cv::Mat& cFirstPage = collection[0]; //2After the changes, the first one(1) would not compile. I understand the reason that it is protection for the user but we should not do that because since he is taking it by reference, it is his reponsibility to deal with this kind of stuff. |
|
It's weak protection, but it covers at least:
|
|
@ocpalo, @asmorkalov, thank you for polishing it! I think, it can be merged now |
I am trying to finalize #17753 pr. To understand the requirements and see what we can do I also take a look at #6574.
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.