aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2020-09-23 21:09:17 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2020-09-23 21:09:17 +0200
commit0dd5bbaf3ab1288adec3fdf6b25bc09fb98b5e15 (patch)
treedb1a04c234062575c8f5f0a4aec8c6da53ff77d1 /src
parentd51a86748a2826e5508451bfd3cc6fba14adc56f (diff)
downloadAsciiMap-0dd5bbaf3ab1288adec3fdf6b25bc09fb98b5e15.tar.gz
formatting / code styleHEADmaster
Diffstat (limited to 'src')
-rw-r--r--src/bitmap.c32
-rw-r--r--src/bitmap.h8
-rw-r--r--src/character.c6
-rw-r--r--src/main.c12
4 files changed, 22 insertions, 36 deletions
diff --git a/src/bitmap.c b/src/bitmap.c
index 0328df8..d7171f1 100644
--- a/src/bitmap.c
+++ b/src/bitmap.c
@@ -28,8 +28,7 @@ static uint32_t bitmap_flip_byte(unsigned char* _v, int _c)
uint32_t ret = 0;
uint32_t counter = (_c-1) * 8;
- for(int i = 0; i < _c; i++)
- {
+ for(int i = 0; i < _c; i++) {
ret |= (uint32_t)(_v[i] << (counter));
counter -= 8;
}
@@ -46,10 +45,7 @@ int bitmap_read(char *_file, struct bitmap_image *_bitmap)
_bitmap->tags = 0x00;
FILE *input_file;
- if(_file)
- input_file = fopen(_file,"rb");
- else
- input_file = stdin;
+ input_file = _file ? fopen(_file,"rb") : stdin;
if(!input_file)
return 1;
@@ -73,11 +69,10 @@ int bitmap_read(char *_file, struct bitmap_image *_bitmap)
return 0;
}
-static struct bitmap_file_header bitmap_read_file_header(FILE *_file)
-{
+static struct bitmap_file_header bitmap_read_file_header(FILE *_file) {
struct bitmap_file_header ret;
unsigned char fileheader[_HEADER_SIZE];
- uint32_t read_counter = 0;
+ uint32_t read_counter = 0;
ret.error = 1;
@@ -116,9 +111,8 @@ static struct bitmap_file_header bitmap_read_file_header(FILE *_file)
return ret;
}
-static struct bitmap_image bitmap_read_pixel_data(FILE *_file, struct bitmap_file_header _header)
-{
- uint32_t **bitmap_buff;
+static struct bitmap_image bitmap_read_pixel_data(FILE *_file, struct bitmap_file_header _header) {
+ uint32_t **bitmap_buff;
struct bitmap_image ret;
@@ -141,8 +135,7 @@ static struct bitmap_image bitmap_read_pixel_data(FILE *_file, struct bitmap_fil
}
//Copy Bitmap into bitmap_buff
- for(int row = 0; row < _header.biHeight; row++)
- {
+ for(int row = 0; row < _header.biHeight; row++) {
//printf("Row %i\n", row);
//fread(bitmap_buff[row], sizeof(char), row_size, bitmap);
for(int col = 0; col < _header.biWidth; col++)
@@ -158,17 +151,14 @@ static struct bitmap_image bitmap_read_pixel_data(FILE *_file, struct bitmap_fil
ret.R = malloc(sizeof(*ret.R) * ret.x);
ret.G = malloc(sizeof(*ret.G) * ret.x);
ret.B = malloc(sizeof(*ret.B) * ret.x);
- for(int i = 0; i < ret.x; i++)
- {
+ for(int i = 0; i < ret.x; i++) {
ret.R[i] = malloc(sizeof(*ret.R[i]) * ret.y);
ret.G[i] = malloc(sizeof(*ret.G[i]) * ret.y);
ret.B[i] = malloc(sizeof(*ret.B[i]) * ret.y);
}
- for(int y = 0; y < ret.y; y++)
- {
- for(int x = 0; x < ret.x; x++)
- {
+ for(int y = 0; y < ret.y; y++) {
+ for(int x = 0; x < ret.x; x++) {
int row = _header.biHeight > 0 ? (ret.y - 1) - y : y;
ret.R[x][y] = (bitmap_buff[row][x] & 0xff0000)>>16;
@@ -286,6 +276,8 @@ static uint8_t bitmap_rgb_luminance(uint8_t R, uint8_t G, uint8_t B) {
char* bitmap_strerror( int _error ) {
if ( _error >= bitmap_errors_cnt || _error < 0)
return "Unknown Error.";
+ if ( _error == 1 )
+ return strerror(errno);
return (char*) bitmap_errors[_error];
}
diff --git a/src/bitmap.h b/src/bitmap.h
index 9f8e312..c6cbd7b 100644
--- a/src/bitmap.h
+++ b/src/bitmap.h
@@ -10,6 +10,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
+#include <string.h>
+#include <errno.h>
#include "dynalloc.h"
@@ -36,8 +38,7 @@
#define BITMAP_MONOCHROME 0x01
-struct bitmap_file_header
-{
+struct bitmap_file_header {
uint8_t error;
uint16_t bfType;
@@ -57,8 +58,7 @@ struct bitmap_file_header
uint32_t tablesc;
};
-struct bitmap_image
-{
+struct bitmap_image {
unsigned int x,y;
uint8_t **R;
diff --git a/src/character.c b/src/character.c
index 5aa2e92..b70cb1e 100644
--- a/src/character.c
+++ b/src/character.c
@@ -3,16 +3,14 @@
const char *default_character_map=" .,-~\"*:;<!/?%&=$#";
//const char *default_character_map=" `.,:;/+#@";
-char calc_char(uint8_t _c , uint8_t _min, uint8_t _max, char *_custom_map)
-{
+char calc_char(uint8_t _c , uint8_t _min, uint8_t _max, char *_custom_map) {
const char *map = _custom_map == 0 ? default_character_map : _custom_map;
float c = (float)(_c) / (_max - _min);
return map [(int)( strlen( map ) * (c))];
}
-char* calc_col_ansi(uint8_t R, uint8_t G, uint8_t B, uint8_t _mode)
-{
+char* calc_col_ansi(uint8_t R, uint8_t G, uint8_t B, uint8_t _mode) {
int mode = _mode == COLOR_BG ? 4 : 3;
int num = 36 * (R/51) + 6 * (G/51) + (B/51);
char *c = malloc(12);
diff --git a/src/main.c b/src/main.c
index e9c5afe..16c6524 100644
--- a/src/main.c
+++ b/src/main.c
@@ -23,8 +23,7 @@
#define CHAR_SIZE_X 2 //How many pixels should form one ASCII char?
#define CHAR_SIZE_Y (2 * CHAR_SIZE_X)
-struct prog_param
-{
+struct prog_param {
char *filename;
char *character_map;
unsigned int charsize_x;
@@ -40,8 +39,7 @@ struct prog_param parse_args(int argc, char *argv[]);
void print_help( char* _argv_0 );
-int main(int argc, char *argv[])
-{
+int main(int argc, char *argv[]) {
struct prog_param args = parse_args(argc, argv);
struct bitmap_image bitmap;
@@ -101,8 +99,7 @@ int main(int argc, char *argv[])
return 0;
}//main
-struct prog_param parse_args(int argc, char *argv[])
-{
+struct prog_param parse_args(int argc, char *argv[]) {
struct prog_param ret;
memset(&ret, 0, sizeof ret);
@@ -177,8 +174,7 @@ struct prog_param parse_args(int argc, char *argv[])
return ret;
}
-void print_help( char* _argv_0 )
-{
+void print_help( char* _argv_0 ) {
printf(
"ASCIIMap\n"
"(c) 2019 Jonas Gunz, github.com/kompetenzbolzen/AsciiMap\n"