Skip to content

port base64 encoding from 3.4#20143

Merged
opencv-pushbot merged 1 commit intoopencv:masterfrom
rogday:base64_encoding
Jul 19, 2021
Merged

port base64 encoding from 3.4#20143
opencv-pushbot merged 1 commit intoopencv:masterfrom
rogday:base64_encoding

Conversation

@rogday
Copy link
Copy Markdown
Member

@rogday rogday commented May 24, 2021

issue #14977

Test data is at opencv/opencv_extra#877

opencv_extra=base64_encoding
force_builders=Custom,ARMv7
build_image:Custom=centos:7
buildworker:Custom=linux-1

@rogday rogday force-pushed the base64_encoding branch 3 times, most recently from 72651b4 to 2d17b0f Compare June 3, 2021 16:51
emitter->write("type_id", type_name, false);
}
}
if (fmt != FileStorage::FORMAT_JSON && !FileNode::isFlow(s.flags))
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This somehow fixes JSON indentation mismatch with 3.4, but looks fragile.

@rogday rogday force-pushed the base64_encoding branch from a0fbc02 to bca4bb5 Compare June 7, 2021 14:23
@rogday rogday force-pushed the base64_encoding branch 3 times, most recently from f9a281e to 430a3ee Compare June 8, 2021 15:14
Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contribution!

#include "persistence_impl.hpp"
#include "base64_encoding.hpp"

class base64::Base64ContextEmitter
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. license header
  2. namespace cv
  3. persistence_ prefix in filename

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for review. Fixed

class base64::Base64ContextEmitter
{
public:
explicit Base64ContextEmitter(cv::FileStorage::Impl * fs)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add NULL check or prefer to pass as reference (C has pointers only):

cv::FileStorage::Impl& fs

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you suggested, I replaced pointer to reference.

if (src_cur != src_beg)
flush(); /* encode the rest binary data to base64 buffer */

if ( file_storage->fmt == cv::FileStorage::Mode::FORMAT_JSON )
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON

In general, generic classes should not know about used format.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed JSON-specific actions from constructor and destructor( writing "$base64 and " to buffer) and added need_indent field instead.

void base64::Base64Writer::check_dt(const char* dt)
{
if ( dt == 0 )
CV_Error( CV_StsBadArg, "Invalid \'dt\'." );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CV_Sts...

Avoid using of legacy C API constants. Use Error::Sts... enum

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

#ifndef OPENCV_CORE_PERSISTENCE_IMPL_HPP
#define OPENCV_CORE_PERSISTENCE_IMPL_HPP

#include "precomp.hpp"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

precomp.hpp

must be used in .cpp files only (as unconditional first include)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

def get_normal_2d_mat():
rows = 10
cols = 20
ch = 3
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ch

cn is usually used in OpenCV code.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@rogday rogday force-pushed the base64_encoding branch 3 times, most recently from 9a28098 to e7cae25 Compare June 29, 2021 09:18
@alalek
Copy link
Copy Markdown
Member

alalek commented Jul 7, 2021

Is this PR still in WIP status? (as per PR title)

@rogday rogday changed the title [WIP]: port base64 encoding from 3.4 port base64 encoding from 3.4 Jul 7, 2021
@rogday rogday force-pushed the base64_encoding branch from 55cf014 to b42623f Compare July 8, 2021 07:43
@rogday
Copy link
Copy Markdown
Member Author

rogday commented Jul 8, 2021

Is this PR still in WIP status? (as per PR title)

I squashed commits, changed the title, it's ready for merge.

@alalek alalek assigned asmorkalov and unassigned vpisarev Jul 19, 2021
@opencv-pushbot opencv-pushbot merged commit 4ab0377 into opencv:master Jul 19, 2021
@rogday rogday deleted the base64_encoding branch October 7, 2021 13:14
@alalek alalek mentioned this pull request Oct 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants