Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,3 @@ test: imgkap
else \
echo "imgkap seems broken."; \
fi

testrc: imgkap
./imgkap ./examples/osm/L16-19056-38040-8-8_16.png ./examples/osm/L16-19056-38040-8-8_16.png.kap out.kap -t testchart -c
./imgkap ./examples/osm/L16-19056-38040-8-8_16.png ./examples/osm/L16-19056-38040-8-8_16.png.kap out.kap -t testchart
Binary file added examples/osm/L16-27816-42904-16-8_16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions examples/osm/L16-27816-42904-16-8_16.png.header.kap
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
VER/2.0
CED/SE=1,RE=1,ED=01/15/2010
BSB/NA=L16-27816-42904-16-8
NU=UNKNOWN,RA=2048,4096,DU=72
KNP/SC=6074,GD=WGS 84,PR=MERCATOR,PP=0.00
PI=UNKNOWN,SP=UNKNOWN,SK=0.0,TA=90
UN=METERS,SD=MEAN SEA LEVEL,DX=2.14,DY=2.14
REF/1,0,0,26.234302,55.678711
REF/2,2048,0,26.234302,55.722656
REF/3,2048,4096,26.155438,55.722656
REF/4,0,4096,26.155438,55.678711
PLY/1,26.234302,55.678711
PLY/2,26.234302,55.722656
PLY/3,26.155438,55.722656
PLY/4,26.155438,55.678711
DTM/0.000000,0.000000
OST/1
IFM/7
Binary file added examples/osm/L16-29296-46016-8-8_16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions examples/osm/L16-29296-46016-8-8_16.png.header.kap
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
VER/2.0
CED/SE=1,RE=1,ED=01/15/2010
BSB/NA=L16-29296-46016-8-8
NU=UNKNOWN,RA=2048,2048,DU=72
KNP/SC=6412,GD=WGS 84,PR=MERCATOR,PP=0.00
PI=UNKNOWN,SP=UNKNOWN,SK=0.0,TA=90
UN=METERS,SD=MEAN SEA LEVEL,DX=2.26,DY=2.26
REF/1,0,0,18.729502,72.773438
REF/2,2048,0,18.729502,72.817383
REF/3,2048,2048,18.687879,72.817383
REF/4,0,2048,18.687879,72.773438
PLY/1,18.729502,72.773438
PLY/2,18.729502,72.817383
PLY/3,18.687879,72.817383
PLY/4,18.687879,72.773438
DTM/0.000000,0.000000
OST/1
IFM/7
41 changes: 30 additions & 11 deletions imgkap.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ void myfree(void)
}

/*------------------ Histogram algorithm ------------------*/

typedef struct
{
Color32 color;
Expand All @@ -230,7 +229,6 @@ typedef struct shistogram
struct shistogram *child ;
} histogram;


#define HistIndex2(p,l) ((((p.q.rgbRed >> l) & 0x03) << 4) | (((p.q.rgbGreen >> l) & 0x03) << 2) | ((p.q.rgbBlue >> l) & 0x03) )
#define HistSize(l) (l?sizeof(histogram):sizeof(helem))
#define HistInc(h,l) (histogram *)(((char *)h)+HistSize(l))
Expand Down Expand Up @@ -966,7 +964,6 @@ static void read_line(uint8_t *in, uint16_t bits, int width, uint8_t *colors, hi
}
}


static uint32_t GetHistogram(FIBITMAP *bitmap,uint32_t bits,uint16_t width,uint16_t height,Color32 *pal,histogram *hist)
{
uint32_t i,j;
Expand Down Expand Up @@ -1471,7 +1468,6 @@ int imgheadertokap(int typein,char *filein,int typeheader, int optkap, int optio
FILE *header;
char datej[20];


memset(palette,0,sizeof(palette));
widthin = heightin = 0;

Expand All @@ -1493,16 +1489,39 @@ int imgheadertokap(int typein,char *filein,int typeheader, int optkap, int optio
return 2;
}

if(optionrc == 1)
if (optionrc == 1)
{

bits_in = FreeImage_GetBPP(tmp_bitmap);

/* make bitmap 24, accept only 1 4 8 24 bits */
if ((bits_in > 8) && (bits_in != 24))
{
/* reduce number of colors to 127 */
bitmap = FreeImage_ColorQuantizeEx(tmp_bitmap, FIQ_NNQUANT, 127, 0, NULL);
FreeImage_Unload(tmp_bitmap);
FIBITMAP *bitmap24;
bitmap24 = FreeImage_ConvertTo24Bits (tmp_bitmap);
if (bitmap24 == NULL)
{
fprintf (stderr, "ERROR - bitmap PPP is incorrect\n");
return 2;
}
FreeImage_Unload (tmp_bitmap);
tmp_bitmap = bitmap24;
}
else

/* reduce number of colors to 127 */
bitmap = FreeImage_ColorQuantizeEx (tmp_bitmap, FIQ_NNQUANT, 127, 0,
NULL);

if (bitmap == 0)
{
bitmap = tmp_bitmap;
fprintf (stderr, "ERROR - FreeImage_ColorQuantizeEx failed\n");
return 2;
}
}
else
{
bitmap = tmp_bitmap;
}

}

Expand Down Expand Up @@ -1644,7 +1663,7 @@ int imgtokap(int typein,char *filein, double lat0, double lon0, int pixpos0x, in
double lat1loc = lat1;
double lon0loc = lon0;
double lon1loc = lon1;
double lon1locr, lon0locr, lat1locr, lat0locr;

uint16_t pixpos0xr,pixpos1xr,pixpos0yr,pixpos1yr;
int numxf = 0;
int xf[12];
Expand Down
37 changes: 37 additions & 0 deletions test_samples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

#set -x

function GenerateKap()
{
[ -e out.kap ] && rm out.kap

echo "test case $TC:"
echo "./imgkap $PNGFILE $KAPHEADERFILE out.kap -t testchart $OPTIONS"
./imgkap $PNGFILE $KAPHEADERFILE out.kap -t testchart $OPTIONS

if [ -f out.kap ]; then
echo "imgkap seems working correctly."
else
echo "imgkap seems broken."
fi
}


PNGFILE="./examples/osm/L16-27816-42904-16-8_16.png"
KAPHEADERFILE="./examples/osm/L16-27816-42904-16-8_16.png.header.kap"
OPTIONS="-c"
TC="1"
GenerateKap

PNGFILE="./examples/osm/L16-29296-46016-8-8_16.png"
KAPHEADERFILE="./examples/osm/L16-29296-46016-8-8_16.png.header.kap"
OPTIONS="-c"
TC="2"
GenerateKap

PNGFILE="./examples/osm/L16-19056-38040-8-8_16.png"
KAPHEADERFILE="./examples/osm/L16-19056-38040-8-8_16.png.header.kap"
OPTIONS="-c"
TC="3"
GenerateKap