Skip to content

Commit

Permalink
Merge pull request #30 from sz3/one-last-v0.5-bugfix
Browse files Browse the repository at this point in the history
Fix memory corruption bug + misc other libcimbar updates
  • Loading branch information
sz3 committed Feb 10, 2024
2 parents f9badfa + 113e8b6 commit 870ab27
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 38 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "org.cimbar.camerafilecopy"
minSdkVersion 21
targetSdkVersion 30
versionCode 10
versionName "0.5.14"
versionCode 11
versionName "0.5.15"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
Expand Down
24 changes: 16 additions & 8 deletions app/src/cpp/cfc-cpp/jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ namespace {
std::set<std::string> _completed;

unsigned _calls = 0;
bool _transferStatus = false;
clock_t _transferSnapshotCalls = 0;
int _transferStatus = 0;
clock_t _frameDecodeSnapshot = 0;
clock_t _frameSuccessSnapshot = 0;

unsigned millis(unsigned num, unsigned denom)
{
Expand All @@ -41,7 +42,7 @@ namespace {
return (num * 100) / denom;
}

void drawGuidance(cv::Mat& mat, bool in_progress)
void drawGuidance(cv::Mat& mat, int in_progress)
{
int minsz = std::min(mat.cols, mat.rows);
int guideWidth = minsz >> 7;
Expand All @@ -50,7 +51,11 @@ namespace {
int guideOffset = minsz >> 5;
int outlineOffset = (outlineWidth - guideWidth) >> 1;

cv::Scalar color = in_progress? cv::Scalar(0,255,0) : cv::Scalar(255,255,255);
cv::Scalar color = cv::Scalar(255,255,255);
if (in_progress == 1)
color = cv::Scalar(255,100,100);
else if (in_progress == 2)
color = cv::Scalar(0,255,0);
cv::Scalar outline = cv::Scalar(0,0,0);

int xextra = 0;
Expand Down Expand Up @@ -119,7 +124,7 @@ namespace {
{
std::stringstream sstop;
sstop << "cfc using " << proc.num_threads() << " thread(s). " << proc.color_bits() << "..." << proc.backlog() << "? ";
sstop << (MultiThreadedDecoder::bytes / std::max<double>(1, MultiThreadedDecoder::decoded)) << "b v0.5.14";
sstop << (MultiThreadedDecoder::bytes / std::max<double>(1, MultiThreadedDecoder::decoded)) << "b v0.5.15";
std::stringstream ssmid;
ssmid << "#: " << MultiThreadedDecoder::perfect << " / " << MultiThreadedDecoder::decoded << " / " << MultiThreadedDecoder::scanned << " / " << _calls;
std::stringstream ssperf;
Expand Down Expand Up @@ -180,9 +185,12 @@ Java_org_cimbar_camerafilecopy_MainActivity_processImageJNI(JNIEnv *env, jobject

if (_calls & 32)
{
clock_t nextSnapshot = proc->decoded;
_transferStatus = nextSnapshot > _transferSnapshotCalls; // decode in progress!
_transferSnapshotCalls = nextSnapshot;
clock_t decodeSnapshot = proc->decoded;
clock_t perfectSnapshot = proc->perfect;
_transferStatus = perfectSnapshot > _frameSuccessSnapshot; // a bit silly, but 1 == partial decode
_transferStatus += (decodeSnapshot > _frameDecodeSnapshot); // 2 == full decode
_frameDecodeSnapshot = decodeSnapshot;
_frameSuccessSnapshot = perfectSnapshot;
}

drawProgress(mat, proc->get_progress());
Expand Down
7 changes: 4 additions & 3 deletions app/src/cpp/libcimbar/package-portable-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
## targeting old glibc
# docker run --mount type=bind,source="$(pwd)",target="/usr/src/app" -it ubuntu:16.04

cd /usr/src/app
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
cd $SCRIPT_DIR

# https://gist.github.com/jlblancoc/99521194aba975286c80f93e47966dc5
apt update
Expand All @@ -14,7 +15,7 @@ apt install -y pkgconf g++-7 python-pip
apt install -y libgles2-mesa-dev libglfw3-dev

# cmake (via pip)
python -m pip install cmake
python -m pip install cmake==3.21.4

# use gcc7
update-alternatives --install /usr/bin/cc cc /usr/bin/gcc-7 100
Expand All @@ -25,7 +26,7 @@ mkdir build-portable/ && cd build-portable/
/usr/local/bin/cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_SHARED_LIBS=OFF -DOPENCV_GENERATE_PKGCONFIG=YES -DOPENCV_FORCE_3RDPARTY_BUILD=YES
make -j5 install

cd /usr/src/app
cd $SCRIPT_DIR
mkdir build-portable/ && cd build-portable/
/usr/local/bin/cmake .. -DBUILD_PORTABLE_LINUX=1
make -j5 install
8 changes: 4 additions & 4 deletions app/src/cpp/libcimbar/src/lib/bit_file/bitbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ class bitbuffer

bool write(unsigned data, unsigned index, int length)
{
resize(index+length-1);
resize(index+length);

int currentByte = index/8;
int currentBit = index%8;

int nextWrite = std::min(length, 8-currentBit); // write this many bits
while (length > 0)
while (length > 0 and nextWrite > 0)
{
char bits = data >> (length - nextWrite);
unsigned char bits = data >> (length - nextWrite);
bits = bits << (8 - nextWrite - currentBit);
_buffer[currentByte] |= bits;

Expand All @@ -92,7 +92,7 @@ class bitbuffer
int nextRead = std::min(length, 8-currentBit); // read this many bits
while (length > 0)
{
unsigned char bits = _buffer[currentByte] << currentBit;
unsigned char bits = static_cast<unsigned char>(_buffer[currentByte]) << currentBit;
bits = bits >> (8-nextRead);
res |= bits << (length - nextRead);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ int AdjacentCellFinder::in_row_with_margin(int index) const

int AdjacentCellFinder::right(int index) const
{
int next = index+1;
if (next >= (int)_positions.size())
if (index < 0 || index >= (int)_positions.size() - 1)
return -1;
if (_positions[next].first < _positions[index].first) // loop
int next = index + 1;
if (_positions[next].first < _positions[index].first)
return -1;
return next;
}
Expand All @@ -63,16 +63,17 @@ int AdjacentCellFinder::left(int index) const

int AdjacentCellFinder::bottom(int index) const
{
if (index < 0 || index >= (int)_positions.size())
return -1;
int increment = _dimensions;
if (in_row_with_margin(index))
increment -= _markerSize;
int next = index + increment;
if (in_row_with_margin(next))
next -= _markerSize;

if (next >= (int)_positions.size())
if (next < 0 || next >= (int)_positions.size())
return -1;
if (_positions[next].first != _positions[index].first) // near anchor
if (_positions[next].first != _positions[index].first)
return -1;
return next;
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/cpp/libcimbar/src/lib/cimb_translator/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ cv::Mat load_img(string path)
vector<unsigned char> data(bytes.data(), bytes.data() + bytes.size());

int width, height, channels;
std::unique_ptr<uint8_t[]> imgdata(stbi_load_from_memory(data.data(), static_cast<int>(data.size()), &width, &height, &channels, STBI_rgb_alpha));
std::unique_ptr<uint8_t[], void (*)(void*)> imgdata(stbi_load_from_memory(data.data(), static_cast<int>(data.size()), &width, &height, &channels, STBI_rgb_alpha), ::free);
if (!imgdata)
return cv::Mat();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ int FloodDecodePositions::update(unsigned index, const CellDrift& drift, unsigne
{
std::array<int,4> horizon = {-1, -1, -1, -1};
horizon[0] = _cellFinder.right(rridx);
if (horizon[0])
if (horizon[0] >= 0)
horizon[1] = _cellFinder.right(horizon[0]);
horizon[2] = _cellFinder.left(llidx);
if (horizon[2])
if (horizon[2] >= 0)
horizon[3] = _cellFinder.left(horizon[2]);

update_adjacents(horizon, drift, error_distance, cooldown);
Expand All @@ -118,10 +118,10 @@ int FloodDecodePositions::update(unsigned index, const CellDrift& drift, unsigne
{
std::array<int,4> vert = {-1, -1, -1, -1};
vert[0] = _cellFinder.top(uuidx);
if (vert[0])
if (vert[0] >= 0)
vert[1] = _cellFinder.top(vert[0]);
vert[2] = _cellFinder.bottom(ddidx);
if (vert[2])
if (vert[2] >= 0)
vert[3] = _cellFinder.bottom(vert[2]);

update_adjacents(vert, drift, error_distance, cooldown);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ TEST_CASE( "CimbDecoderTest/testAllColorDecodes", "[unit]" )
DYNAMIC_SECTION( "testColor " << c << ":" << i )
{
cv::Mat tile = cimbar::getTile(4, i, true, 4, c);
cv::Mat tenxten(10, 10, tile.type());
cv::Mat tenxten(10, 10, tile.type(), {0,0,0});
tile.copyTo(tenxten(cv::Rect(cv::Point(1, 1), tile.size())));

unsigned color = cd.decode_color(Cell(tenxten));
Expand Down
18 changes: 11 additions & 7 deletions app/src/cpp/libcimbar/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,23 @@
top: 0;
}

#invisible_click, #canvas, #nav-container {
z-index: 1;
}

#nav-button {
z-index: 2;
}

#canvas {
display: block;
position: relative;
}

#dragdrop {
background-color: #3C3D82;
background-image: linear-gradient(135deg, rgba(249, 249, 249, 0.1) 0%, rgba(249, 249, 249, 0.1) 18%,rgba(70, 70, 70, 0.1) 18%, rgba(70, 70, 70, 0.1) 33%,rgba(229, 229, 229, 0.1) 33%, rgba(229, 229, 229, 0.1) 35%,rgba(53, 53, 53, 0.1) 35%, rgba(53, 53, 53, 0.1) 47%,rgba(156, 156, 156, 0.1) 47%, rgba(156, 156, 156, 0.1) 100%),linear-gradient(135deg, rgba(106, 106, 106, 0.08) 0%, rgba(106, 106, 106, 0.08) 9%,rgba(123, 123, 123, 0.08) 9%, rgba(123, 123, 123, 0.08) 10%,rgba(69, 69, 69, 0.08) 10%, rgba(69, 69, 69, 0.08) 38%,rgba(33, 33, 33, 0.08) 38%, rgba(33, 33, 33, 0.08) 65%,rgba(24, 24, 24, 0.08) 65%, rgba(24, 24, 24, 0.08) 77%,rgba(210, 210, 210, 0.08) 77%, rgba(210, 210, 210, 0.08) 100%),linear-gradient(45deg, rgba(70, 70, 70, 0.02) 0%, rgba(70, 70, 70, 0.02) 23%,rgba(225, 225, 225, 0.02) 23%, rgba(225, 225, 225, 0.02) 29%,rgba(118, 118, 118, 0.02) 29%, rgba(118, 118, 118, 0.02) 36%,rgba(28, 28, 28, 0.02) 36%, rgba(28, 28, 28, 0.02) 42%,rgba(142, 142, 142, 0.02) 42%, rgba(142, 142, 142, 0.02) 85%,rgba(95, 95, 95, 0.02) 85%, rgba(95, 95, 95, 0.02) 93%,rgba(32, 32, 32, 0.02) 93%, rgba(32, 32, 32, 0.02) 98%,rgba(71, 71, 71, 0.02) 98%, rgba(71, 71, 71, 0.02) 100%),linear-gradient(135deg, rgba(207, 207, 207, 0.05) 0%, rgba(207, 207, 207, 0.05) 12%,rgba(32, 32, 32, 0.05) 12%, rgba(32, 32, 32, 0.05) 27%,rgba(79, 79, 79, 0.05) 27%, rgba(79, 79, 79, 0.05) 32%,rgba(139, 139, 139, 0.05) 32%, rgba(139, 139, 139, 0.05) 43%,rgba(150, 150, 150, 0.05) 43%, rgba(150, 150, 150, 0.05) 79%,rgba(139, 139, 139, 0.05) 79%, rgba(139, 139, 139, 0.05) 87%,rgba(55, 55, 55, 0.05) 87%, rgba(55, 55, 55, 0.05) 91%,rgba(68, 68, 68, 0.05) 91%, rgba(68, 68, 68, 0.05) 100%),linear-gradient(0deg, rgba(108, 108, 108, 0.1) 0%, rgba(108, 108, 108, 0.1) 16%,rgba(163, 163, 163, 0.1) 16%, rgba(163, 163, 163, 0.1) 18%,rgba(32, 32, 32, 0.1) 18%, rgba(32, 32, 32, 0.1) 29%,rgba(122, 122, 122, 0.1) 29%, rgba(122, 122, 122, 0.1) 61%,rgba(141, 141, 141, 0.1) 61%, rgba(141, 141, 141, 0.1) 67%,rgba(53, 53, 53, 0.1) 67%, rgba(53, 53, 53, 0.1) 78%,rgba(142, 142, 142, 0.1) 78%, rgba(142, 142, 142, 0.1) 100%),linear-gradient(0deg, rgba(160, 160, 160, 0.08) 0%, rgba(160, 160, 160, 0.08) 27%,rgba(163, 163, 163, 0.08) 27%, rgba(163, 163, 163, 0.08) 29%,rgba(37, 37, 37, 0.08) 29%, rgba(37, 37, 37, 0.08) 35%,rgba(96, 96, 96, 0.08) 35%, rgba(96, 96, 96, 0.08) 73%,rgba(250, 250, 250, 0.08) 73%, rgba(250, 250, 250, 0.08) 90%,rgba(91, 91, 91, 0.08) 90%, rgba(91, 91, 91, 0.08) 100%),linear-gradient(90deg, rgba(191, 191, 191, 0.08) 0%, rgba(191, 191, 191, 0.08) 2%,rgba(170, 170, 170, 0.08) 2%, rgba(170, 170, 170, 0.08) 7%,rgba(49, 49, 49, 0.08) 7%, rgba(49, 49, 49, 0.08) 9%,rgba(131, 131, 131, 0.08) 9%, rgba(131, 131, 131, 0.08) 23%,rgba(197, 197, 197, 0.08) 23%, rgba(197, 197, 197, 0.08) 29%,rgba(154, 154, 154, 0.08) 29%, rgba(154, 154, 154, 0.08) 91%,rgba(211, 211, 211, 0.08) 91%, rgba(211, 211, 211, 0.08) 100%),linear-gradient(90deg, rgb(0,119,100),rgb(0,0,119));
margin: 0 auto;
z-index: -1;
color: #F0F0F0;
outline: 6px solid black;
box-shadow: 0px 0px 12px black, 0px 0px 18px black;
Expand All @@ -57,7 +64,6 @@
left: 0;
text-align: center;
width: 100%;
z-index: -1;
}

#invisible_click {
Expand Down Expand Up @@ -91,6 +97,7 @@
pointer-events: none;
}
#nav-container .bg {
pointer-events: auto;
position: absolute;
left: 0;
width: 100%;
Expand All @@ -113,7 +120,6 @@
display: flex;
flex-direction: column;
justify-content: center;
z-index: 1;
height: 60px;
width: 30px;
margin-left: 15px;
Expand Down Expand Up @@ -192,12 +198,10 @@
#nav-content {
margin-top: 60px;
padding: 20px;
max-width: 200px;
position: absolute;
top: 0;
left: 0;
height: calc(100% - 60px);
width: 90%;
overflow-x: clip;
background-color: #282C34;
text-align: center;
Expand Down Expand Up @@ -268,8 +272,8 @@
<input style="display:none;" type="file" name="file_input" id="file_input" onchange="Main.fileInput(this);" />

<div id="nav-container" class="c4">
<div class="bg"></div>
<button id="nav-button" tabindex="0">
<div class="bg" onclick="Main.blurNav();"></div>
<button id="nav-button" tabindex="0" onclick="Main.clickNav();">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
Expand Down
3 changes: 1 addition & 2 deletions app/src/cpp/libcimbar/web/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ return {
{
// reset zoom
var canvas = document.getElementById('canvas');
canvas.style.zoom = (window.innerWidth / window.outerWidth);
var width = window.outerWidth;
var width = window.innerWidth;
var height = window.outerHeight;
Main.scaleCanvas(canvas, width, height);
Main.alignInvisibleClick(canvas);
Expand Down

0 comments on commit 870ab27

Please sign in to comment.