Pārlūkot izejas kodu

Hotfix for the last commit

Add other image modes back into ImageOut
tags/v1.8.0
Xerbo pirms 4 gadiem
vecāks
revīzija
81cee99bd3
2 mainītis faili ar 40 papildinājumiem un 11 dzēšanām
  1. +37
    -8
      main.c
  2. +3
    -3
      palette.h

+ 37
- 8
main.c Parādīt failu

@@ -181,6 +181,21 @@ int mapOverlay(char *filename, float **crow, int nrow, int zenith, int MCIR) {
// Row where to satellite reaches peak elevation
int zenith = 0;

int applyPalette(float **crow, int nrow, int width, char *palette){
if(palette == NULL) return 0;

for(int y = 0; y < nrow; y++){
for(int x = 0; x < width; x++){
float *px = &crow[y][x * 3];
px[0] = palette[(int)CLIP(px[0], 0, 255)*3 + 0];
px[1] = palette[(int)CLIP(px[1], 0, 255)*3 + 1];
px[2] = palette[(int)CLIP(px[2], 0, 255)*3 + 2];
}
}

return 1;
}

static int ImageOut(char *filename, char *chid, float **prow, int nrow, int width, int offset, char *palette, char *effects, char *mapFile) {
FILE *pngfile;

@@ -226,30 +241,44 @@ static int ImageOut(char *filename, char *chid, float **prow, int nrow, int widt
crow[i] = (float *) malloc(sizeof(float) * 2080 * 3);

for(int x = 0; x < 2080; x++)
crow[i][x*3 + 0] = crow[i][x*3 + 1] = crow[i][x*3 + 2] = prow[i][x];
crow[i][x*3] = crow[i][x*3 + 1] = crow[i][x*3 + 2] = prow[i][x];
}

applyPalette(crow, nrow, 2080, palette);

if(mapFile != NULL && mapFile[0] != '\0'){
if(mapOverlay(mapFile, crow, nrow, zenith, strcmp(chid, "MCIR") == 0) == 0){
fprintf(stderr, "Skipping MCIR generation; see above.\n");
return 0;
}
}else if(strcmp(chid, "MCIR")){
}else if(strcmp(chid, "MCIR") == 0){
fprintf(stderr, "Skipping MCIR generation; no map provided.\n");
return 0;
}

extern void falsecolor(float vis, float temp, float *r, float *g, float *b);

printf("Writing %s", filename);

int fcimage = strcmp(chid, "False Color") == 0;

// Build RGB image
for (int n = 0; n < nrow; n++) {
png_color pix[width];

for (int i = 0; i < width; i++) {
float *px = &crow[n][offset*3 + i*3];
pix[i].red = CLIP(px[0], 0, 255);
pix[i].green = CLIP(px[1], 0, 255);
pix[i].blue = CLIP(px[2], 0, 255);
if(fcimage){
float r = 0, g = 0, b = 0;
falsecolor(prow[n][i + CHA_OFFSET], prow[n][i + CHB_OFFSET], &r, &g, &b);
pix[i].red = r;
pix[i].green = g;
pix[i].blue = b;
}else{
pix[i].red = px[0];
pix[i].green = px[1];
pix[i].blue = px[2];
}
}
png_write_row(png_ptr, (png_bytep) pix);
@@ -506,9 +535,9 @@ int main(int argc, char **argv) {
// Temperature
if (CONTAINS(imgopt, 't') && chB >= 4) {
// TODO: Doesn't work with channel 4
temperature(prow, nrow, chB, CHB_OFFSET);
//temperature(prow, nrow, chB, CHB_OFFSET);
sprintf(pngfilename, "%s/%s-t.png", pngdirname, name);
ImageOut(pngfilename, "Temperature", prow, nrow, 2080, 0, TempPalette, enhancements, mapFile);
ImageOut(pngfilename, "Temperature", prow, nrow, 909, CHB_OFFSET, (char *)TempPalette, enhancements, mapFile);
}

// False color image
@@ -520,7 +549,7 @@ int main(int argc, char **argv) {
} else if (chB == 2) { // GVI (global vegetation index) false color
Ngvi(prow, nrow);
sprintf(pngfilename, "%s/%s-c.png", pngdirname, name);
ImageOut(pngfilename, "GVI False Color", prow, nrow, CH_WIDTH, CHB_OFFSET, GviPalette, enhancements, mapFile);
ImageOut(pngfilename, "GVI False Color", prow, nrow, CH_WIDTH, CHB_OFFSET, (char *)GviPalette, enhancements, mapFile);
} else {
fprintf(stderr, "Skipping False Color generation; lacking required channels.\n");
}


+ 3
- 3
palette.h Parādīt failu

@@ -17,7 +17,7 @@
*
*/

char *GviPalette = {
char GviPalette[256*3] = {
"\230t\17\233x\22\236{\27\241\200\33\244\203\37\247\210#\252\214'\255\220"
",\260\2240\264\2305\267\2358\272\240=\274\245A\300\251E\303\255I\306\262"
"M\311\266Q\314\272V\317\276Z\322\302^\325\306b\330\312g\334\317k\337\323"
@@ -48,8 +48,8 @@ char *GviPalette = {
"M\225\1I\221\2E\217\1@\214\1;\211\1""7\206\1""1\203\1-\200\0(~\1${\0\37y"
"\0\33u\0\25r\0\21p\0\14l\0\7j\0\3"
};
char *TempPalette = {
"\000\000\000\376\376\376\375\375\376\374\375\376\374\375\375\374\373\375"
char TempPalette[256*3] = {
"\376\376\376\376\376\376\375\375\376\374\375\376\374\375\375\374\373\375"
"\373\373\375\372\373\375\372\373\374\372\372\374\371\372\374\371\371\375"
"\370\371\374\367\370\375\367\370\374\367\367\374\366\367\373\366\366\373"
"\365\366\373\364\366\373\364\365\374\363\365\373\363\364\373\363\364\373"


Notiek ielāde…
Atcelt
Saglabāt