Skip to content

Commit

Permalink
Merge pull request #24 from DoubleCouponDay/feat/hosted
Browse files Browse the repository at this point in the history
Feat/hosted
  • Loading branch information
sam authored Mar 9, 2021
2 parents b2ed72a + 12f4672 commit 30e3d48
Show file tree
Hide file tree
Showing 32 changed files with 454 additions and 223 deletions.
14 changes: 14 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

/C_part/lib/
/Rust_part/target/
/Rust_part/tests/
/Rust_part/libvec.a
/Rust_part/Cargo.lock
C_part/.xmake/
C_part/build/
C_part/test/
README.md
LICENSE
.gitignore
/.vscode/
Dockerfile
21 changes: 18 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
Rust_part/log.txt
Rust_part/test.png
Rust_part/template.svg
**/*.a
**/*.so
**/*.lib
/C_part/lib/
/C_part/bin/
conaninfo.txt
graph_info.json
conanbuildinfo.cmake
CMakeFiles/
**/CMakeCache.txt
**/Makefile
cmake_install.cmake
**/log.txt
**/conanbuildinfo.txt

# Discord token
*.discord_token
Expand All @@ -15,7 +28,7 @@ Rust_part/test.png
Rust_part/target

C_part/.xmake/
C_part/build
C_part/build/

# Prerequisites
*.d
Expand Down Expand Up @@ -81,3 +94,5 @@ conan.lock
.xmake/linux/x86_64/xmake.conf

*.lock

Rust_part/vec
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
"logger.h": "c",
"string.h": "c",
"stdio.h": "c",
"vec.h": "c"
"vec.h": "c",
"error.h": "c"
},
"C_Cpp.intelliSenseEngineFallback": "Enabled"
}
Empty file removed .xmake/windows/x64/project.lock
Empty file.
17 changes: 17 additions & 0 deletions C_part/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.13.4)
project(vec)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

file(GLOB sourceglob
"${PROJECT_SOURCE_DIR}/src/*.h" "${PROJECT_SOURCE_DIR}/src/*.c"
"${PROJECT_SOURCE_DIR}/src/utility/*.h" "${PROJECT_SOURCE_DIR}/src/utility/*.c"
"${PROJECT_SOURCE_DIR}/src/nsvg/*.h" "${PROJECT_SOURCE_DIR}/src/nsvg/*.c"
"${PROJECT_SOURCE_DIR}/src/imagefile/*.h" "${PROJECT_SOURCE_DIR}/src/imagefile/*.c")

add_library(${PROJECT_NAME} STATIC ${sourceglob})
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER "./src/entrypoint.h")

file(COPY "../template.svg" DESTINATION "./bin")
1 change: 1 addition & 0 deletions C_part/conanfile.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[requires]
libpng/1.6.37
nanosvg/20190405

[generators]
cmake
9 changes: 0 additions & 9 deletions C_part/src/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,6 @@ bool colours_are_similar(pixel color_a, pixel color_b, float max_distance)
return abc <= max_distance; // If difference less than the threshold
}

char* rgb_to_string(pixel* input) {
char* output = input->r;
output += ',';
output += input->g;
output += ',';
output += input->b;
return output;
}

image create_image(int width, int height)
{
image output = {
Expand Down
2 changes: 1 addition & 1 deletion C_part/src/imagefile/pngfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "pngfile.h"
#include "../image.h"
#include "../utility/error.h"
#include "utility/logger.h"
#include "../utility/logger.h"

/// Takes a filename (assumed to be a png file), and creates an image struct full of the png's pixels
///
Expand Down
2 changes: 1 addition & 1 deletion C_part/src/imagefile/svg.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "../utility/error.h"
#include "../nsvg/copy.h"
#include "utility/logger.h"
#include "../utility/logger.h"
#include "../chunkmap.h"

const char* OUTPUT_PATH = "output.svg";
Expand Down
6 changes: 0 additions & 6 deletions C_part/src/main.c

This file was deleted.

10 changes: 5 additions & 5 deletions C_part/src/nsvg/bobsweep.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "bobsweep.h"

#include "utility/logger.h"
#include "utility/vec.h"
#include "imagefile/pngfile.h"
#include "../utility/logger.h"
#include "../utility/vec.h"
#include "../imagefile/pngfile.h"
#include "mapping.h"
#include "mapparser.h"
#include "utility/error.h"
#include "sort.h"
#include "../utility/error.h"
#include "../sort.h"

#include <stdlib.h>
#include <stdio.h>
Expand Down
4 changes: 2 additions & 2 deletions C_part/src/nsvg/bobsweep.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <nanosvg.h>

#include "image.h"
#include "chunkmap.h"
#include "../image.h"
#include "../chunkmap.h"

void sweepfill_chunkmap(chunkmap* map, float threshold);
9 changes: 6 additions & 3 deletions C_part/src/nsvg/copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
#include <nanosvg.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#include "utility/logger.h"
#include "../utility/error.h";
#include "../utility/logger.h"
#include "../utility/error.h"

const char* TEMPLATE_PATH = "template.svg";

Expand Down Expand Up @@ -33,11 +35,12 @@ char* gettemplate(int width, int height) {
char* data = NULL;
fp = fopen(TEMPLATE_PATH, "rb");

if (!fp) {
if(fp == NULL) { //still null after trying fix
LOG_ERR("could not find svg template file.");
setError(TEMPLATE_FILE_NOT_FOUND);
return NULL;
};

fseek(fp, 0, SEEK_END);
size = ftell(fp);
fseek(fp, 0, SEEK_SET);
Expand Down
7 changes: 3 additions & 4 deletions C_part/src/nsvg/dcdfiller.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
#include <math.h>
#include <nanosvg.h>

#include "usage.h"
#include "../image.h"
#include "../chunkmap.h"
#include "utility/logger.h"
#include "utility/error.h"
#include "../utility/logger.h"
#include "../utility/error.h"
#include "copy.h"
#include "mapping.h"
#include "../sort.h"
#include "utility/vec.h"
#include "../utility/vec.h"

const float ZIP_DISTANCE = 0.5;

Expand Down
3 changes: 1 addition & 2 deletions C_part/src/nsvg/mapparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
#include <math.h>
#include <nanosvg.h>

#include "usage.h"
#include "../image.h"
#include "../chunkmap.h"
#include "utility/logger.h"
#include "../utility/logger.h"
#include "../utility/error.h"
#include "copy.h"
#include "mapping.h"
Expand Down
2 changes: 1 addition & 1 deletion C_part/src/nsvg/mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "mapping.h"
#include "../utility/error.h"
#include "utility/logger.h"
#include "../utility/logger.h"
#include "../image.h"
#include "../chunkmap.h"

Expand Down
2 changes: 1 addition & 1 deletion C_part/src/nsvg/mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "../image.h"
#include "../chunkmap.h"
#include "utility/vec.h"
#include "../utility/vec.h"

enum mapping_consts {
BEZIERCURVE_LENGTH = 8,
Expand Down
6 changes: 3 additions & 3 deletions C_part/src/nsvg/usage.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
#include "../sort.h"
#include "mapparser.h"
#include "dcdfiller.h"
#include "imagefile/pngfile.h"
#include "../imagefile/pngfile.h"
#include "bobsweep.h"
#include "utility/logger.h"
#include "../utility/logger.h"

//entry point of the file
NSVGimage* dcdfill_for_nsvg(image input, vectorize_options options) {
Expand Down Expand Up @@ -86,7 +86,7 @@ NSVGimage* bobsweep_for_nsvg(image input, vectorize_options options) {

if(isBadError()) {
LOG_ERR("quantize_image failed with %d", getLastError());
return getAndResetErrorCode();
return NULL;
}

chunkmap* map = generate_chunkmap(input, options);
Expand Down
2 changes: 1 addition & 1 deletion C_part/src/utility/error.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "error.h"

#include "utility/logger.h"
#include "logger.h"

int error_code = SUCCESS_CODE;

Expand Down
1 change: 1 addition & 0 deletions C_part/src/utility/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum vectorizing_opcodes {
LOW_BOUNDARIES_CREATED
};

int isBadError();
int getLastError();
void setError(int error);
int getAndResetErrorCode();
2 changes: 0 additions & 2 deletions C_part/src/utility/logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <time.h>
#include <stdarg.h>

#include "../../test/debug.h"

FILE* logfile = 0;
const char* LOG_PATH = "log.txt";

Expand Down
44 changes: 0 additions & 44 deletions C_part/xmake.lua

This file was deleted.

37 changes: 37 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#designed for linux build
FROM rust:1.50

RUN apt-get update && \
apt-get install apt-utils -y && \
apt-get dist-upgrade -y && \
apt-get install -y musl-tools && \
apt-get install software-properties-common -y && \
apt-get install python3=3.7.3-1 -y && \
apt-get install python-pip -y && \
python -m pip install --upgrade pip && \
python -m pip install conan && \
apt-get install cmake -y && \
apt-get install build-essential && \
rustup target add x86_64-unknown-linux-musl

# copy C source and Rust source
COPY ./ /home/sjsui/vectorizer/

# set environment variables
ENV conanpath /root/.conan/data/
ENV releasebuild true
ENV PATH $PATH:/home/sjsui/vectorizer/Rust_part/target/release

# initialize build tools
WORKDIR /home/sjsui/vectorizer/C_part/build/
RUN conan install ../ && \
conan profile update settings.compiler.libcxx=libstdc++11 default && \
cmake ../ && \
make

#build Rust code
WORKDIR /home/sjsui/vectorizer/Rust_part/
RUN cargo build -vv --release

#create entrypoint of container
CMD ["./target/release/trampoline"]
Loading

0 comments on commit 30e3d48

Please sign in to comment.