Skip to content

Commit d047763

Browse files
committed
Squashed 'app/src/cpp/libcimbar/' changes from faebb87..368c2c4
368c2c4 Merge pull request #90 from sz3/bugfix-santitize-future 258991b Fix some longstanding (no)-fsanitize sloppiness e77b598 Merge pull request #89 from sz3/bugfix-flood-decode-bounds-check ead73ea fix memory corruption bug 0fe367f Fix the error check in FloodDecodePositions 97f4af3 Merge pull request #87 from sz3/build-and-css-bugfix-24-2 0f2d718 Tweak to make package-portable-linux slightly less docker dependent d2ddcc2 Use innerWidth to avert android firefox shenanigans 8f9caa1 If negative z-index is bad vibes, we should set z-index+1 various places 38b8068 Update index.html 0119374 Merge pull request #85 from sz3/pin-cmake-portable-build 452eb71 Pin "portable" linux script to use an old (known good) cmake 05d5e38 Merge pull request #82 from sz3/ios-css-bugfix 69a7d41 Fix bug/change in ios (un)focus behavior? git-subtree-dir: app/src/cpp/libcimbar git-subtree-split: 368c2c4
1 parent 0367145 commit d047763

File tree

8 files changed

+33
-28
lines changed

8 files changed

+33
-28
lines changed

package-portable-linux.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
## targeting old glibc
33
# docker run --mount type=bind,source="$(pwd)",target="/usr/src/app" -it ubuntu:16.04
44

5-
cd /usr/src/app
5+
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
6+
cd $SCRIPT_DIR
67

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

1617
# cmake (via pip)
17-
python -m pip install cmake
18+
python -m pip install cmake==3.21.4
1819

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

28-
cd /usr/src/app
29+
cd $SCRIPT_DIR
2930
mkdir build-portable/ && cd build-portable/
3031
/usr/local/bin/cmake .. -DBUILD_PORTABLE_LINUX=1
3132
make -j5 install

src/lib/bit_file/bitbuffer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ class bitbuffer
6161

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

6666
int currentByte = index/8;
6767
int currentBit = index%8;
6868

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

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

src/lib/cimb_translator/AdjacentCellFinder.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ int AdjacentCellFinder::in_row_with_margin(int index) const
4343

4444
int AdjacentCellFinder::right(int index) const
4545
{
46-
int next = index+1;
47-
if (next >= (int)_positions.size())
46+
if (index < 0 || index >= (int)_positions.size() - 1)
4847
return -1;
49-
if (_positions[next].first < _positions[index].first) // loop
48+
int next = index + 1;
49+
if (_positions[next].first < _positions[index].first)
5050
return -1;
5151
return next;
5252
}
@@ -63,16 +63,17 @@ int AdjacentCellFinder::left(int index) const
6363

6464
int AdjacentCellFinder::bottom(int index) const
6565
{
66+
if (index < 0 || index >= (int)_positions.size())
67+
return -1;
6668
int increment = _dimensions;
6769
if (in_row_with_margin(index))
6870
increment -= _markerSize;
6971
int next = index + increment;
7072
if (in_row_with_margin(next))
7173
next -= _markerSize;
72-
73-
if (next >= (int)_positions.size())
74+
if (next < 0 || next >= (int)_positions.size())
7475
return -1;
75-
if (_positions[next].first != _positions[index].first) // near anchor
76+
if (_positions[next].first != _positions[index].first)
7677
return -1;
7778
return next;
7879
}

src/lib/cimb_translator/Common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ cv::Mat load_img(string path)
5757
vector<unsigned char> data(bytes.data(), bytes.data() + bytes.size());
5858

5959
int width, height, channels;
60-
std::unique_ptr<uint8_t[]> imgdata(stbi_load_from_memory(data.data(), static_cast<int>(data.size()), &width, &height, &channels, STBI_rgb_alpha));
60+
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);
6161
if (!imgdata)
6262
return cv::Mat();
6363

src/lib/cimb_translator/FloodDecodePositions.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ int FloodDecodePositions::update(unsigned index, const CellDrift& drift, unsigne
103103
{
104104
std::array<int,4> horizon = {-1, -1, -1, -1};
105105
horizon[0] = _cellFinder.right(rridx);
106-
if (horizon[0])
106+
if (horizon[0] >= 0)
107107
horizon[1] = _cellFinder.right(horizon[0]);
108108
horizon[2] = _cellFinder.left(llidx);
109-
if (horizon[2])
109+
if (horizon[2] >= 0)
110110
horizon[3] = _cellFinder.left(horizon[2]);
111111

112112
update_adjacents(horizon, drift, error_distance, cooldown);
@@ -118,10 +118,10 @@ int FloodDecodePositions::update(unsigned index, const CellDrift& drift, unsigne
118118
{
119119
std::array<int,4> vert = {-1, -1, -1, -1};
120120
vert[0] = _cellFinder.top(uuidx);
121-
if (vert[0])
121+
if (vert[0] >= 0)
122122
vert[1] = _cellFinder.top(vert[0]);
123123
vert[2] = _cellFinder.bottom(ddidx);
124-
if (vert[2])
124+
if (vert[2] >= 0)
125125
vert[3] = _cellFinder.bottom(vert[2]);
126126

127127
update_adjacents(vert, drift, error_distance, cooldown);

src/lib/cimb_translator/test/CimbDecoderTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ TEST_CASE( "CimbDecoderTest/testAllColorDecodes", "[unit]" )
125125
DYNAMIC_SECTION( "testColor " << c << ":" << i )
126126
{
127127
cv::Mat tile = cimbar::getTile(4, i, true, 4, c);
128-
cv::Mat tenxten(10, 10, tile.type());
128+
cv::Mat tenxten(10, 10, tile.type(), {0,0,0});
129129
tile.copyTo(tenxten(cv::Rect(cv::Point(1, 1), tile.size())));
130130

131131
unsigned color = cd.decode_color(Cell(tenxten));

web/index.html

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,23 @@
3434
top: 0;
3535
}
3636

37+
#invisible_click, #canvas, #nav-container {
38+
z-index: 1;
39+
}
40+
41+
#nav-button {
42+
z-index: 2;
43+
}
3744

3845
#canvas {
3946
display: block;
47+
position: relative;
4048
}
4149

4250
#dragdrop {
4351
background-color: #3C3D82;
4452
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));
4553
margin: 0 auto;
46-
z-index: -1;
4754
color: #F0F0F0;
4855
outline: 6px solid black;
4956
box-shadow: 0px 0px 12px black, 0px 0px 18px black;
@@ -57,7 +64,6 @@
5764
left: 0;
5865
text-align: center;
5966
width: 100%;
60-
z-index: -1;
6167
}
6268

6369
#invisible_click {
@@ -91,6 +97,7 @@
9197
pointer-events: none;
9298
}
9399
#nav-container .bg {
100+
pointer-events: auto;
94101
position: absolute;
95102
left: 0;
96103
width: 100%;
@@ -113,7 +120,6 @@
113120
display: flex;
114121
flex-direction: column;
115122
justify-content: center;
116-
z-index: 1;
117123
height: 60px;
118124
width: 30px;
119125
margin-left: 15px;
@@ -192,12 +198,10 @@
192198
#nav-content {
193199
margin-top: 60px;
194200
padding: 20px;
195-
max-width: 200px;
196201
position: absolute;
197202
top: 0;
198203
left: 0;
199204
height: calc(100% - 60px);
200-
width: 90%;
201205
overflow-x: clip;
202206
background-color: #282C34;
203207
text-align: center;
@@ -268,8 +272,8 @@
268272
<input style="display:none;" type="file" name="file_input" id="file_input" onchange="Main.fileInput(this);" />
269273

270274
<div id="nav-container" class="c4">
271-
<div class="bg"></div>
272-
<button id="nav-button" tabindex="0">
275+
<div class="bg" onclick="Main.blurNav();"></div>
276+
<button id="nav-button" tabindex="0" onclick="Main.clickNav();">
273277
<span class="icon-bar"></span>
274278
<span class="icon-bar"></span>
275279
<span class="icon-bar"></span>

web/main.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ return {
4949
{
5050
// reset zoom
5151
var canvas = document.getElementById('canvas');
52-
canvas.style.zoom = (window.innerWidth / window.outerWidth);
53-
var width = window.outerWidth;
52+
var width = window.innerWidth;
5453
var height = window.outerHeight;
5554
Main.scaleCanvas(canvas, width, height);
5655
Main.alignInvisibleClick(canvas);

0 commit comments

Comments
 (0)