Skip to content

Commit

Permalink
Merge pull request #85 from saxbophone/develop
Browse files Browse the repository at this point in the history
Version 0.15.0
  • Loading branch information
saxbophone authored Oct 17, 2016
2 parents c79b44f + b7becd5 commit 705ee45
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 500 deletions.
28 changes: 2 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# begin basic metadata
cmake_minimum_required(VERSION 3.0)

project(saxbospiral VERSION 0.14.0 LANGUAGES C)
project(libsaxbospiral VERSION 0.15.0 LANGUAGES C)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(
Expand Down Expand Up @@ -47,11 +47,8 @@ endif()
# add custom dependencies directory
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
# libpng
find_package(PNG REQUIRED)
find_package(PNG 1.2 EXACT REQUIRED)
include_directories(${PNG_INCLUDE_DIR})
# Argtable
find_package(Argtable REQUIRED)
include_directories(${ARGTABLE_INCLUDE_DIR})

# C source files
file(
Expand All @@ -69,10 +66,8 @@ add_library(saxbospiral ${LIB_SAXBOSPIRAL_SOURCES})
# Link libsaxbospiral with libpng so we get libpng symbols
target_link_libraries(saxbospiral ${PNG_LIBRARY})

add_executable(sxp sxp.c)
add_executable(sxp_test tests.c)

target_link_libraries(sxp saxbospiral ${PNG_LIBRARY} ${ARGTABLE_LIBRARY})
target_link_libraries(sxp_test saxbospiral ${PNG_LIBRARY})

install(
Expand All @@ -92,24 +87,5 @@ install(
DESTINATION include/saxbospiral/render_backends
)

install(PROGRAMS sxp DESTINATION bin)

enable_testing()
add_test(unit_tests sxp_test)
# fetch a shell script runner
find_program(COMMAND_INTERPRETER bash)
# only run functional test if we found bash
if(COMMAND_INTERPRETER)
add_test(
NAME func_test COMMAND ${COMMAND_INTERPRETER}
# each script needs to know the path to the sxp cli executable
"func_test.sh" sxp "saxbospiral v${SAXBOSPIRAL_VERSION_STRING}"
)
add_custom_target(
build_logo ${COMMAND_INTERPRETER}
"build_logo.sh" sxp "saxbospiral.png" "saxbospiral v${SAXBOSPIRAL_VERSION_STRING}"
)
else()
# warn about skipping of functional test script
message(WARNING "Skipping functional test script, couldn't find Bash Shell")
endif()
18 changes: 6 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
# Saxbospiral ![saxbospiral](saxbospiral.png "saxbospiral")
# Saxbospiral ![libsaxbospiral](libsaxbospiral.png "libsaxbospiral")

Experimental generation of 2D spiralling lines based on input binary data
Experimental generation of 2D spiralling lines based on input binary data.

## Dependencies
This is a library only, if you're looking for something that is immediately usable for the end-user, you probably want to look at [sxbp](https://github.com/saxbophone/sxbp) instead.

### Library
## Dependencies

For the library, you will need:
You will need:

- A compiler that can compile ISO C99 code
- [Cmake](https://cmake.org/) - v3.0 or newer
- [libpng](http://www.libpng.org/pub/png/libpng.html) - (this often comes preinstalled with many modern unix-like systems)

### CLI

For the included CLI program, you will also need:

- [Argtable 2](http://argtable.sourceforge.net/) - must use v2, v1 and v3 will not work

> ### Note:
> These commands are for unix-like systems, without an IDE or other build system besides CMake. If building for a different system, or within an IDE or other environment, consult your IDE/System documentation on how to build CMake projects.
Expand Down Expand Up @@ -46,7 +40,7 @@ make
make test
```

## Install Library + Binaries
## Install Library

This command might require `sudo`, but check your system configuration. For example, it installs to `/usr/local/` by default, which is user-writable on OSX if you use Homebrew, so not requiring admin privileges.

Expand Down
12 changes: 0 additions & 12 deletions build_logo.sh

This file was deleted.

10 changes: 0 additions & 10 deletions func_test.sh

This file was deleted.

Binary file added libsaxbospiral.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed saxbospiral.png
Binary file not shown.
7 changes: 7 additions & 0 deletions saxbospiral/initialise.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ direction_t change_direction(direction_t current, rotation_t turn) {
return (current + turn) % 4U;
}

/*
* returns a spiral struct with all fields initialised to 0
*/
spiral_t blank_spiral() {
return (spiral_t){0, NULL, {{NULL, 0}, 0}, false, 0, 0, 0};
}

/*
* given a buffer_t full of data, and a pointer to a blank spiral_t
* struct, populates the spiral struct from the data in the buffer
Expand Down
5 changes: 5 additions & 0 deletions saxbospiral/initialise.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ extern "C"{
*/
direction_t change_direction(direction_t current, rotation_t turn);

/*
* returns a spiral struct with all fields initialised to 0
*/
spiral_t blank_spiral();

/*
* given a buffer_t full of data, and a pointer to a blank spiral_t
* struct, populates the spiral struct from the data in the buffer
Expand Down
27 changes: 16 additions & 11 deletions saxbospiral/render_backends/png_backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ static void buffer_write_data(
// if buffer bytes pointer is not NULL, then re-allocate
if(p->bytes != NULL) {
p->bytes = realloc(p->bytes, new_size);
}
// otherwise, allocate
else {
} else {
// otherwise, allocate
p->bytes = malloc(new_size);
}
if(!p->bytes) {
Expand All @@ -45,9 +44,15 @@ void dummy_png_flush(png_structp png_ptr) {}

// simple libpng cleanup function - used mainly for freeing memory
void cleanup_png_lib(png_structp png_ptr, png_infop info_ptr, png_bytep row) {
if (info_ptr != NULL) png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
if (png_ptr != NULL) png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
if (row != NULL) free(row);
if(info_ptr != NULL) {
png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
}
if(png_ptr != NULL) {
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
}
if(row != NULL) {
free(row);
}
}

/*
Expand All @@ -67,7 +72,7 @@ status_t write_png_image(bitmap_t bitmap, buffer_t* buffer) {
// allocate libpng memory
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
// catch malloc fail
if (png_ptr == NULL) {
if(png_ptr == NULL) {
result.location = DEBUG;
result.diagnostic = MALLOC_REFUSED;
// cleanup
Expand All @@ -77,7 +82,7 @@ status_t write_png_image(bitmap_t bitmap, buffer_t* buffer) {
// allocate libpng memory
info_ptr = png_create_info_struct(png_ptr);
// catch malloc fail
if (info_ptr == NULL) {
if(info_ptr == NULL) {
result.location = DEBUG;
result.diagnostic = MALLOC_REFUSED;
// cleanup
Expand Down Expand Up @@ -135,11 +140,11 @@ status_t write_png_image(bitmap_t bitmap, buffer_t* buffer) {
return result;
}
// Write image data
for (size_t y = 0 ; y < bitmap.height; y++) {
for (size_t x = 0; x < bitmap.width; x++) {
for(size_t y = 0 ; y < bitmap.height; y++) {
for(size_t x = 0; x < bitmap.width; x++) {
// set to black if there is a point here, white if not
row[x] = (bitmap.pixels[x][y] == true) ? 0 : 1;
}
}
png_write_row(png_ptr, row);
}
// End write
Expand Down
6 changes: 2 additions & 4 deletions saxbospiral/solve.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static bool spiral_collides(spiral_t* spiral, size_t index) {
* if there are less than 4 lines in the spiral, then there's no way it
* can collide, so return false early
*/
if (spiral->size < 4) {
if(spiral->size < 4) {
return false;
} else {
// initialise a counter to keep track of what line we're on
Expand Down Expand Up @@ -139,9 +139,7 @@ static length_t suggest_resize(
* Apply the rules mentioned in collision_resolution_rules.txt to
* calculate the correct length to set the previous line and return it.
*/
if(false) {
(void)0; // no-op
} else if((p.direction == UP) && (r.direction == UP)) {
if((p.direction == UP) && (r.direction == UP)) {
return (ra.y - pa.y) + r.length + 1;
} else if((p.direction == UP) && (r.direction == DOWN)) {
return (rb.y - pa.y) + r.length + 1;
Expand Down
Loading

0 comments on commit 705ee45

Please sign in to comment.