Skip to content

Commit 705ee45

Browse files
authored
Merge pull request #85 from saxbophone/develop
Version 0.15.0
2 parents c79b44f + b7becd5 commit 705ee45

File tree

12 files changed

+38
-500
lines changed

12 files changed

+38
-500
lines changed

CMakeLists.txt

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# begin basic metadata
22
cmake_minimum_required(VERSION 3.0)
33

4-
project(saxbospiral VERSION 0.14.0 LANGUAGES C)
4+
project(libsaxbospiral VERSION 0.15.0 LANGUAGES C)
55
set(CMAKE_C_STANDARD 99)
66
set(CMAKE_C_STANDARD_REQUIRED ON)
77
set(
@@ -47,11 +47,8 @@ endif()
4747
# add custom dependencies directory
4848
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
4949
# libpng
50-
find_package(PNG REQUIRED)
50+
find_package(PNG 1.2 EXACT REQUIRED)
5151
include_directories(${PNG_INCLUDE_DIR})
52-
# Argtable
53-
find_package(Argtable REQUIRED)
54-
include_directories(${ARGTABLE_INCLUDE_DIR})
5552

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

72-
add_executable(sxp sxp.c)
7369
add_executable(sxp_test tests.c)
7470

75-
target_link_libraries(sxp saxbospiral ${PNG_LIBRARY} ${ARGTABLE_LIBRARY})
7671
target_link_libraries(sxp_test saxbospiral ${PNG_LIBRARY})
7772

7873
install(
@@ -92,24 +87,5 @@ install(
9287
DESTINATION include/saxbospiral/render_backends
9388
)
9489

95-
install(PROGRAMS sxp DESTINATION bin)
96-
9790
enable_testing()
9891
add_test(unit_tests sxp_test)
99-
# fetch a shell script runner
100-
find_program(COMMAND_INTERPRETER bash)
101-
# only run functional test if we found bash
102-
if(COMMAND_INTERPRETER)
103-
add_test(
104-
NAME func_test COMMAND ${COMMAND_INTERPRETER}
105-
# each script needs to know the path to the sxp cli executable
106-
"func_test.sh" sxp "saxbospiral v${SAXBOSPIRAL_VERSION_STRING}"
107-
)
108-
add_custom_target(
109-
build_logo ${COMMAND_INTERPRETER}
110-
"build_logo.sh" sxp "saxbospiral.png" "saxbospiral v${SAXBOSPIRAL_VERSION_STRING}"
111-
)
112-
else()
113-
# warn about skipping of functional test script
114-
message(WARNING "Skipping functional test script, couldn't find Bash Shell")
115-
endif()

README.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
1-
# Saxbospiral ![saxbospiral](saxbospiral.png "saxbospiral")
1+
# Saxbospiral ![libsaxbospiral](libsaxbospiral.png "libsaxbospiral")
22

3-
Experimental generation of 2D spiralling lines based on input binary data
3+
Experimental generation of 2D spiralling lines based on input binary data.
44

5-
## Dependencies
5+
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.
66

7-
### Library
7+
## Dependencies
88

9-
For the library, you will need:
9+
You will need:
1010

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

15-
### CLI
16-
17-
For the included CLI program, you will also need:
18-
19-
- [Argtable 2](http://argtable.sourceforge.net/) - must use v2, v1 and v3 will not work
20-
2115
> ### Note:
2216
2317
> 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.
@@ -46,7 +40,7 @@ make
4640
make test
4741
```
4842

49-
## Install Library + Binaries
43+
## Install Library
5044

5145
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.
5246

build_logo.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.

func_test.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

libsaxbospiral.png

657 Bytes
Loading

saxbospiral.png

-650 Bytes
Binary file not shown.

saxbospiral/initialise.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ direction_t change_direction(direction_t current, rotation_t turn) {
1717
return (current + turn) % 4U;
1818
}
1919

20+
/*
21+
* returns a spiral struct with all fields initialised to 0
22+
*/
23+
spiral_t blank_spiral() {
24+
return (spiral_t){0, NULL, {{NULL, 0}, 0}, false, 0, 0, 0};
25+
}
26+
2027
/*
2128
* given a buffer_t full of data, and a pointer to a blank spiral_t
2229
* struct, populates the spiral struct from the data in the buffer

saxbospiral/initialise.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ extern "C"{
1414
*/
1515
direction_t change_direction(direction_t current, rotation_t turn);
1616

17+
/*
18+
* returns a spiral struct with all fields initialised to 0
19+
*/
20+
spiral_t blank_spiral();
21+
1722
/*
1823
* given a buffer_t full of data, and a pointer to a blank spiral_t
1924
* struct, populates the spiral struct from the data in the buffer

saxbospiral/render_backends/png_backend.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ static void buffer_write_data(
2222
// if buffer bytes pointer is not NULL, then re-allocate
2323
if(p->bytes != NULL) {
2424
p->bytes = realloc(p->bytes, new_size);
25-
}
26-
// otherwise, allocate
27-
else {
25+
} else {
26+
// otherwise, allocate
2827
p->bytes = malloc(new_size);
2928
}
3029
if(!p->bytes) {
@@ -45,9 +44,15 @@ void dummy_png_flush(png_structp png_ptr) {}
4544

4645
// simple libpng cleanup function - used mainly for freeing memory
4746
void cleanup_png_lib(png_structp png_ptr, png_infop info_ptr, png_bytep row) {
48-
if (info_ptr != NULL) png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
49-
if (png_ptr != NULL) png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
50-
if (row != NULL) free(row);
47+
if(info_ptr != NULL) {
48+
png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
49+
}
50+
if(png_ptr != NULL) {
51+
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
52+
}
53+
if(row != NULL) {
54+
free(row);
55+
}
5156
}
5257

5358
/*
@@ -67,7 +72,7 @@ status_t write_png_image(bitmap_t bitmap, buffer_t* buffer) {
6772
// allocate libpng memory
6873
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
6974
// catch malloc fail
70-
if (png_ptr == NULL) {
75+
if(png_ptr == NULL) {
7176
result.location = DEBUG;
7277
result.diagnostic = MALLOC_REFUSED;
7378
// cleanup
@@ -77,7 +82,7 @@ status_t write_png_image(bitmap_t bitmap, buffer_t* buffer) {
7782
// allocate libpng memory
7883
info_ptr = png_create_info_struct(png_ptr);
7984
// catch malloc fail
80-
if (info_ptr == NULL) {
85+
if(info_ptr == NULL) {
8186
result.location = DEBUG;
8287
result.diagnostic = MALLOC_REFUSED;
8388
// cleanup
@@ -135,11 +140,11 @@ status_t write_png_image(bitmap_t bitmap, buffer_t* buffer) {
135140
return result;
136141
}
137142
// Write image data
138-
for (size_t y = 0 ; y < bitmap.height; y++) {
139-
for (size_t x = 0; x < bitmap.width; x++) {
143+
for(size_t y = 0 ; y < bitmap.height; y++) {
144+
for(size_t x = 0; x < bitmap.width; x++) {
140145
// set to black if there is a point here, white if not
141146
row[x] = (bitmap.pixels[x][y] == true) ? 0 : 1;
142-
}
147+
}
143148
png_write_row(png_ptr, row);
144149
}
145150
// End write

saxbospiral/solve.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static bool spiral_collides(spiral_t* spiral, size_t index) {
3333
* if there are less than 4 lines in the spiral, then there's no way it
3434
* can collide, so return false early
3535
*/
36-
if (spiral->size < 4) {
36+
if(spiral->size < 4) {
3737
return false;
3838
} else {
3939
// initialise a counter to keep track of what line we're on
@@ -139,9 +139,7 @@ static length_t suggest_resize(
139139
* Apply the rules mentioned in collision_resolution_rules.txt to
140140
* calculate the correct length to set the previous line and return it.
141141
*/
142-
if(false) {
143-
(void)0; // no-op
144-
} else if((p.direction == UP) && (r.direction == UP)) {
142+
if((p.direction == UP) && (r.direction == UP)) {
145143
return (ra.y - pa.y) + r.length + 1;
146144
} else if((p.direction == UP) && (r.direction == DOWN)) {
147145
return (rb.y - pa.y) + r.length + 1;

0 commit comments

Comments
 (0)