Skip to content

Commit

Permalink
Squashed 'app/src/cpp/libcimbar/' changes from faebb87..368c2c4
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sz3 committed Feb 8, 2024
1 parent 0367145 commit d047763
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 28 deletions.
7 changes: 4 additions & 3 deletions 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 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
13 changes: 7 additions & 6 deletions src/lib/cimb_translator/AdjacentCellFinder.cpp
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 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
8 changes: 4 additions & 4 deletions src/lib/cimb_translator/FloodDecodePositions.cpp
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
2 changes: 1 addition & 1 deletion src/lib/cimb_translator/test/CimbDecoderTest.cpp
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 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 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 d047763

Please sign in to comment.