lots of changes after a lot of time

rewrote some functions to use an accompanying function that returns a string; this prepares for splitting us into a library
fixed weird bug caused by CImg update
some endls have been replaced with \n
slightly more consistent function naming
more comments

1.3 part 1 out of ?
This commit is contained in:
Aaron Liu 2024-01-24 18:43:14 -05:00
commit ac334fdfaa
No known key found for this signature in database
GPG key ID: 2D4DA57B12065A35
2 changed files with 43 additions and 22 deletions

22
.github/workflows/ci.yml vendored Normal file
View file

@ -0,0 +1,22 @@
name: TerminalImageViewer CI
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "*" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install dependencies
run: sudo apt-get install -qy imagemagick
- name: Build
run: make -C src
- name: Test
run: ./src/tiv -w 80 -h 24 /usr/share/pixmaps/debian-logo.png

View file

@ -1,23 +1,21 @@
/*
* Copyright (c) 2023 Aaron Liu
* Copyright (c) 2017-2023, Stefan Haustein, Aaron Liu
*
* This file is free software: you may copy, redistribute and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
* This file is free software: you may copy, redistribute and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright (c) 20172021, Stefan Haustein
* Alternatively, you may copy, redistribute and/or modify this file under
* the terms of the Apache License, version 2.0:
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -42,17 +40,18 @@
#include <string>
#include <vector>
// CImg, the superior grafiks library
// This #define tells CImg that we use the library without any display options --
// just for loading images.
#define cimg_display 0
#include "CImg.h"
// CImg defines its own min and max macros to compile, so we need to undef them
#undef min
#undef max
// First include for detecting console output size,
// everything else for exit codes
#ifdef _POSIX_VERSION
// Console output size detection
#include <sys/ioctl.h>
// Exit codes
#include <sysexits.h>
#endif
@ -74,9 +73,6 @@
#define EX_CONFIG 78 /* configuration error */
#endif
// using namespace std; // haha nope, bad style
// especially when we're also using the CImg namespace
// Implementation of flag representation for flags in the main() method
constexpr int FLAG_FG = 1; // emit fg color
constexpr int FLAG_BG = 2; // emit bg color
@ -85,15 +81,18 @@ constexpr int FLAG_24BIT = 8; // 24-bit color mode
constexpr int FLAG_NOOPT = 16; // Only use the same half-block character
constexpr int FLAG_TELETEXT = 32; // Use teletext characters
// Steps (@TODO: Figure out what exactly they represent)
// Color saturation value steps from 0 to 255
constexpr int COLOR_STEP_COUNT = 6;
constexpr int COLOR_STEPS[COLOR_STEP_COUNT] = {0, 0x5f, 0x87, 0xaf, 0xd7, 0xff};
// Grayscale saturation value steps from 0 to 255
constexpr int GRAYSCALE_STEP_COUNT = 24;
constexpr int GRAYSCALE_STEPS[GRAYSCALE_STEP_COUNT] = {
0x08, 0x12, 0x1c, 0x26, 0x30, 0x3a, 0x44, 0x4e, 0x58, 0x62, 0x6c, 0x76,
0x80, 0x8a, 0x94, 0x9e, 0xa8, 0xb2, 0xbc, 0xc6, 0xd0, 0xda, 0xe4, 0xee};
// An interleaved map of 4x8 bit character bitmaps (each hex digit represents a row)
// to the corresponding unicode character code point.
constexpr unsigned int BITMAPS[] = {
0x00000000, 0x00a0,