forked from tom2238/apt-encoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapt-colorm.c
105 lines (97 loc) · 2.84 KB
/
apt-colorm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#include <math.h>
#include <getopt.h>
#include "image.h"
#include "aptcode.h"
#define _APT_FILE_NO_SET "σame"
void Usage(char *p_name);
int main(int argc, char *argv[]) {
if(argc == 1){
Usage(argv[0]);
return 0;
}
char channel_a[1024]=_APT_FILE_NO_SET;
char channel_b[1024]=_APT_FILE_NO_SET;
char output[1024]=_APT_FILE_NO_SET;
int opt = 0;
while ((opt = getopt(argc, argv, "a:b:o:h")) != -1){
switch (opt) {
case 'h': //Help
Usage(argv[0]);
return 0;
break;
case 'a': //Channel A TGA image
strncpy(channel_a,optarg,sizeof(channel_a)-1);
break;
case 'b': //Channel B TGA image
strncpy(channel_b,optarg,sizeof(channel_b)-1);
break;
case 'o': //Output TGA image
strncpy(output,optarg,sizeof(output)-1);
break;
default:
Usage(argv[0]);
return 0;
}
}
if(strncmp(channel_a,_APT_FILE_NO_SET,4) == 0) {
printf("%s: required argument and option -- '-a <filename>'\n",argv[0]);
exit(2);
}
if(strncmp(channel_b,_APT_FILE_NO_SET,4) == 0) {
printf("%s: required argument and option -- '-b <filename>'\n",argv[0]);
exit(2);
}
if(strncmp(output,_APT_FILE_NO_SET,4) == 0) {
printf("%s: required argument and option -- '-o <filename>'\n",argv[0]);
exit(2);
}
TgaImageHead ChannelA, ChannelB, OutputColor;
ChannelA = OpenTgaImage(channel_a);
ChannelB = OpenTgaImage(channel_b);
OutputColor = ChannelA;
OutputColor = WriteTgaImage(output, OutputColor);
if(ChannelA.File == NULL) { // On error
exit(1);
}
if(ChannelB.File == NULL) { // On error
exit(1);
}
if(OutputColor.File == NULL) { // On error
exit(1);
}
int i,j;
unsigned int pix_a;
unsigned int pix_b;
HsvColor hsvc;
AptColor aptc;
RgbColor rgbc;
// 24 bit RGB, but in grayscale expected
for(i=0;i<ChannelA.Width;i++) {
for(j=0;j<ChannelA.Height;j++) {
pix_a = ReadTGAPixel(ChannelA.File);
pix_b = ReadTGAPixel(ChannelB.File);
aptc.h = GetRedSubPixel(pix_a); // X
aptc.sv = GetRedSubPixel(pix_b); // Y
rgbc = AptToRgb(aptc);
WriteTGAPixel(rgbc.r,rgbc.g,rgbc.b, OutputColor.File);
}
}
fclose(ChannelA.File);
fclose(ChannelB.File);
fclose(OutputColor.File);
return 0;
}
void Usage(char *p_name) {
printf("NOAA color mode decoder\n");
printf("Usage: %s -a <filename> -b <filename> -o <filename> -h\n",p_name);
printf(" -a <filename> Input channel A TGA image (909px width, 24bit RGB)\n");
printf(" -b <filename> Input channel B TGA image (909px width, 24bit RGB)\n");
printf(" -o <filename> Output color TGA image \n");
printf(" -h Show this help\n");
printf(" Build: %s %s, GCC %s\n", __TIME__, __DATE__, __VERSION__);
}