Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Prerequisites
*.d

# Object files
*.o
*.ko
*.obj
*.elf

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf

stiv
stiv-jpeg
tiv
build/
17 changes: 17 additions & 0 deletions Build.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM ubuntu:20.04

# Install dependencies
RUN apt update
RUN apt install -y libjpeg-dev cmake make clang

VOLUME /app

WORKDIR /app

RUN echo "#!/bin/sh" > /var/lib/build.sh
RUN echo "mkdir -p /app/build" >> /var/lib/build.sh
RUN echo "cd /app/build" >> /var/lib/build.sh
RUN echo "cmake .." >> /var/lib/build.sh
RUN echo "make" >> /var/lib/build.sh

CMD ["/bin/sh", "/var/lib/build.sh"]
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.0)
project(tiv C)

add_subdirectory(libstiv)

file(GLOB_RECURSE SOURCES app/*.c)
add_executable(stiv-jpeg ${SOURCES})
target_include_directories(stiv-jpeg PRIVATE libstiv/src)
target_link_libraries(stiv-jpeg stiv_static jpeg)
target_compile_options(stiv-jpeg PRIVATE -Wall -Wextra -Werror -pedantic -std=c99 -O3 -g)
add_dependencies(stiv-jpeg stiv_static)
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ VALAC=valac
DESTDIR?=/
PREFIX?=usr
#CFLAGS += -I/opt/local/include -I/usr/local/include
CFLAGS += $(shell pkg-config --cflags libjpeg)
CFLAGS += $(shell pkg-config --cflags libjpeg) -Wall -Wextra -pedantic -std=c99 -O3 -ffast-math
#JPEGLIBS += -L/opt/local/lib -L/usr/local/lib -L/usr/local/Cellar -ljpeg
JPEGLIBS += $(shell pkg-config --libs libjpeg)

Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ $ tiv -d foo.img > .bitmap 2> .size
$ stiv `cat .size` < .bitmap
```

How to build?
---------------

First create the Dockerized build environment:
```
docker build -t libstiv:latest -f Build.Dockerfile .
```

Then build the project with:
```
docker run --rm -v $(pwd):/app -it libstiv:latest
```

Author
------

Expand Down
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
TODO
====
* Refactor as a library
* Canvas API to draw and write text
* Interactive mode (zoom, pan, brightness, ..)
* Enhace ansi mode dithering (blue is not always detected)
47 changes: 47 additions & 0 deletions app/stiv-jpeg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* tiv - terminal image viewer - copyleft 2013-2015 - pancake */

#include <stdlib.h>
#include <stiv.h>
#include <string.h>

int main(int argc, const char** argv) {
stivctx_t* ctx;
uint32_t width = 80;
stiv_mode mode = STIV_MODE_RGB;

if (argc < 2) {
printf(
"stiv-jpeg . suckless terminal image viewer\n"
"Usage: stiv [image] [width] [mode]\n"
"Modes: [ascii,ansi,grey,256,rgb]\n");
return 1;
}

if (argc > 2) {
width = atoi(argv[2]);
}

if (argc > 3) {
if (!strcmp(argv[3], "ascii"))
mode = STIV_MODE_ASCII;
else if (!strcmp(argv[3], "ansi"))
mode = STIV_MODE_ANSI;
else if (!strcmp(argv[3], "grey"))
mode = STIV_MODE_GREY;
else if (!strcmp(argv[3], "256"))
mode = STIV_MODE_256;
else if (!strcmp(argv[3], "rgb"))
mode = STIV_MODE_RGB;
}

if (!(ctx = stiv_from_jpeg(argv[1], width, 0, mode))) {
printf("Failed to load image\n");
return 1;
}

stiv_display(ctx);

stiv_free(ctx);

return 0;
}
1 change: 0 additions & 1 deletion compile

This file was deleted.

18 changes: 18 additions & 0 deletions libstiv/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.0)
project(libstiv C)

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)

file(GLOB_RECURSE SOURCES src/*.c)

add_library(stiv SHARED ${SOURCES})
target_include_directories(stiv PRIVATE src)
target_compile_options(stiv PRIVATE -Wall -Wextra -Werror -pedantic -O3 -ffast-math -fPIC)
target_link_libraries(stiv m)

add_library(stiv_static STATIC ${SOURCES})
target_include_directories(stiv_static PRIVATE src)
target_compile_options(stiv_static PRIVATE -Wall -Wextra -Werror -pedantic -O3 -ffast-math -fPIC)
target_link_libraries(stiv_static m)
Loading