aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar jonas <himself@jonasgunz.de> 2019-02-04 18:37:11 +0100
committerGravatar jonas <himself@jonasgunz.de> 2019-02-04 18:37:11 +0100
commitbf33eefa42ff1654df848e0b0e1ee740afc6f38f (patch)
treeac0dc3fbfb658dafaea0f7c97a396da51604fc8d
parent4d8bb0513354011971897c3915684c6944cb3364 (diff)
downloadAsciiMap-bf33eefa42ff1654df848e0b0e1ee740afc6f38f.tar.gz
Changed luminance algorithm
-rw-r--r--Makefile4
-rw-r--r--Readme.md2
-rw-r--r--main.c29
3 files changed, 23 insertions, 12 deletions
diff --git a/Makefile b/Makefile
index 0601b90..dee2c36 100644
--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,10 @@
CC = /usr/bin/gcc
CFLAGS = -Wall -g
-LDFLAGS =
+LDFLAGS = -lm
OUTPUT = bitmap
BUILDDIR = build
-FILE = 02
+FILE = a
OBJ = main.o
diff --git a/Readme.md b/Readme.md
index 354252f..5e6d040 100644
--- a/Readme.md
+++ b/Readme.md
@@ -1,3 +1,3 @@
# AsciiMap
-Converts windows BitMap files to ASCII
+Converts 24bit Windows BitMap files to ASCII
diff --git a/main.c b/main.c
index deef073..8d4bae2 100644
--- a/main.c
+++ b/main.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
+#include <math.h>
#define _HEADER_SIZE 54 //Fileheader + infoheader
@@ -10,6 +11,7 @@
#define BF_TYPE 0x00
#define BF_SIZE 0x02
#define BF_OFF_BITS 0x0a
+
#define BI_SIZE 0x0e
#define BI_WIDTH 0x12
#define BI_HEIGHT 0x16
@@ -22,8 +24,8 @@
#define CHAR_SIZE_X 2 //How many pixels should form one ASCII char?
#define CHAR_SIZE_Y (2 * CHAR_SIZE_X)
-const char map[] = {' ', ' ', '.', ',', '`', '-', '~', '"', '*', ':', ';', '<', '!', '/','?', '%', '&', '=', '$', '#'};
-//const char map[] = {'`', '.', ',', ':', ';', '\'', '+', '#', '@'};
+const char map[] = {' ', ' ', '.', ',', '`', '-', '~', '"', '*', ':', ';', '<', '!', '/', '?', '%', '&', '=', '$', '#'};
+//const char map[] = {' ', '`', '.', ',', ':', ';', '\'', '+', '#', '@'};
//Routine for flipping bytes
uint32_t flip(unsigned char* _v, int _c);
@@ -120,6 +122,11 @@ int main(int argc, char *argv[])
printf("Compression not supported.\n");
return 1;
}
+ if(biClrUsed != 0)
+ {
+ printf("Colortable not supported.\n");
+ return 1;
+ }
//Read to start of Pixel block
//This block contains Colormasks and Colortables.
@@ -155,6 +162,9 @@ int main(int argc, char *argv[])
for(int col = 0; col < biWidth; col++)
fread(&bitmap_buff[row][col], 1, 3, bitmap);
+ for(int i = 0; i < row_size - (biWidth * 3); i++) //read excess NULL-Bytes
+ fgetc(bitmap);
+
read_counter += row_size;
}
@@ -238,8 +248,8 @@ int main(int argc, char *argv[])
fclose(out);
return 0;
-}
-//One pixel is 3Byte, One line is multiple of 4Bytes
+}//main
+
uint32_t flip(unsigned char* _v, int _c)
{
uint32_t ret = 0;
@@ -262,7 +272,6 @@ char avg(int argc, char *argv)
for(int i = 0; i < argc; i++)
sum += (uint64_t)argv[i];
-
ret = (char)(sum / argc);
return ret;
@@ -271,15 +280,17 @@ char avg(int argc, char *argv)
char calc_char(uint8_t _c , uint8_t _min, uint8_t _max)
{
float c = (float)(_c) / (_max - _min);
- return map [(int)((sizeof(map)-1) * (1-c)) ];
+ return map [(int)((sizeof(map)-1) * (c))];
}
char rgb_avg(uint32_t *arg)
{
char ret;
uint32_t R = (*arg & 0xff0000)>>16;;
- uint32_t G = (*arg & 0xff00)>>8;
- uint32_t B = *arg & 0xff;
- ret = (char)(R+R+B+G+G+G)/6;
+ uint32_t G = (*arg & 0x00ff00)>>8;
+ uint32_t B = *arg & 0x0000ff;
+
+ ret = sqrt( 0.299*pow(R,2) + 0.587*pow(G,2) + 0.114*pow(B,2) ); //(char)(R+R+B+G+G+G)/6;
+
return ret;
}