Minor tweaks from cleaning up spandsp

This commit is contained in:
Steve Underwood 2013-06-01 01:05:08 +08:00
parent a55d70ed62
commit 88587ec03b
13 changed files with 1737 additions and 160 deletions

View File

@ -257,10 +257,10 @@ then
esac
fi
#AC_DEFINE([SPANDSP_SUPPORT_T42], [1], [Support T.42 JPEG compression])
SPANDSP_SUPPORT_T42="#undef SPANDSP_SUPPORT_T42"
#AC_DEFINE([SPANDSP_SUPPORT_T43], [1], [Support T.43 JBIG gray and colour compression])
SPANDSP_SUPPORT_T43="#undef SPANDSP_SUPPORT_T43"
AC_DEFINE([SPANDSP_SUPPORT_T42], [1], [Support T.42 JPEG compression])
SPANDSP_SUPPORT_T42="#define SPANDSP_SUPPORT_T42 1"
AC_DEFINE([SPANDSP_SUPPORT_T43], [1], [Support T.43 JBIG gray and colour compression])
SPANDSP_SUPPORT_T43="#define SPANDSP_SUPPORT_T43 1"
#AC_DEFINE([SPANDSP_SUPPORT_V32BIS], [1], [Support the V.32bis modem])
SPANDSP_SUPPORT_V32BIS="#undef SPANDSP_SUPPORT_V32BIS"
#AC_DEFINE([SPANDSP_SUPPORT_V34], [1], [Support the V.34 FAX modem])

View File

@ -21,12 +21,6 @@
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Based in part on a single channel G.722 codec which is:
*
* Copyright (c) CMU 1993
* Computer Science, Speech Group
* Chengxiang Lu and Alex Hauptmann
*/
/*! \file */

View File

@ -21,15 +21,8 @@
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Based on a single channel G.722 codec which is:
*
***** Copyright (c) CMU 1993 *****
* Computer Science, Speech Group
* Chengxiang Lu and Alex Hauptmann
*/
/*! \file */
#if !defined(_SPANDSP_G722_H_)

View File

@ -690,9 +690,24 @@ SPAN_DECLARE(int) t30_set_supported_compressions(t30_state_t *s, int supported_c
| T4_SUPPORT_COMPRESSION_T6
| T4_SUPPORT_COMPRESSION_T85
| T4_SUPPORT_COMPRESSION_T85_L0
#if defined(SPANDSP_SUPPORT_T88)
| T4_SUPPORT_COMPRESSION_T88
#endif
//| T4_SUPPORT_COMPRESSION_T81
#if defined(SPANDSP_SUPPORT_T43)
| T4_SUPPORT_COMPRESSION_T43
#endif
#if defined(SPANDSP_SUPPORT_T45)
| T4_SUPPORT_COMPRESSION_T45
#endif
#if 0
| T4_SUPPORT_COMPRESSION_GRAYSCALE
| T4_SUPPORT_COMPRESSION_COLOUR
| T4_SUPPORT_COMPRESSION_12BIT
| T4_SUPPORT_COMPRESSION_COLOUR_TO_GRAY
| T4_SUPPORT_COMPRESSION_GRAY_TO_BILEVEL
| T4_SUPPORT_COMPRESSION_COLOUR_TO_BILEVEL
| T4_SUPPORT_COMPRESSION_RESCALING
#endif
| 0;
s->supported_compressions = supported_compressions;

View File

@ -48,7 +48,6 @@
#include "floating_fudge.h"
#include <tiffio.h>
#include <assert.h>
#include <jpeglib.h>
#include "spandsp/telephony.h"
#include "spandsp/fast_convert.h"
@ -719,15 +718,17 @@ static void jpg_encode_error_exit(j_common_ptr cinfo)
/*- End of function --------------------------------------------------------*/
/* This is the error catcher */
#ifndef WIN32
static struct jpeg_error_mgr encode_error_handler =
{
#if defined(_MSC_VER) || defined(__sunos) || defined(__solaris) || defined(__sun)
jpg_encode_error_exit,
0,
jpg_encode_error_exit
#else
.error_exit = jpg_encode_error_exit,
.output_message = jpg_encode_error_exit
};
#else
static struct jpeg_error_mgr encode_error_handler = {jpg_encode_error_exit,0,jpg_encode_error_exit};
#endif
};
static int t42_srgb_to_itulab_jpeg(t42_encode_state_t *s)
{
@ -1032,15 +1033,17 @@ static void jpg_decode_error_exit(j_common_ptr cinfo)
/*- End of function --------------------------------------------------------*/
/* This is the error catcher */
#ifndef WIN32
static struct jpeg_error_mgr decode_error_handler =
{
#if defined(_MSC_VER) || defined(__sunos) || defined(__solaris) || defined(__sun)
jpg_decode_error_exit,
0,
jpg_decode_error_exit
#else
.error_exit = jpg_decode_error_exit,
.output_message = jpg_decode_error_exit
};
#else
static struct jpeg_error_mgr decode_error_handler = {jpg_decode_error_exit,0,jpg_decode_error_exit};
#endif
};
static int t42_itulab_jpeg_to_srgb(t42_decode_state_t *s)
{

View File

@ -41,7 +41,6 @@
#endif
#include <time.h>
#include "floating_fudge.h"
#include <jpeglib.h>
#include <setjmp.h>
#include "spandsp/telephony.h"

View File

@ -112,6 +112,7 @@ noinst_PROGRAMS = ademco_contactid_tests \
t4_tests \
t4_t6_tests \
t42_tests \
t43_tests \
t81_t82_arith_coding_tests \
t85_tests \
time_scale_tests \
@ -325,6 +326,9 @@ t4_t6_tests_LDADD = $(LIBDIR) -lspandsp
t42_tests_SOURCES = t42_tests.c
t42_tests_LDADD = $(LIBDIR) -lspandsp
t43_tests_SOURCES = t43_tests.c
t43_tests_LDADD = $(LIBDIR) -lspandsp
t81_t82_arith_coding_tests_SOURCES = t81_t82_arith_coding_tests.c
t81_t82_arith_coding_tests_LDADD = $(LIBDIR) -lspandsp

View File

@ -490,6 +490,7 @@ int main(int argc, char *argv[])
int noise_level;
int code_to_look_up;
int scan_line_time;
int colour_enabled;
t38_stats_t t38_stats;
t30_stats_t t30_stats;
logging_state_t *logging;
@ -528,14 +529,18 @@ int main(int argc, char *argv[])
scan_line_time = 0;
decode_file_name = NULL;
code_to_look_up = -1;
colour_enabled = FALSE;
t38_transport = T38_TRANSPORT_UDPTL;
while ((opt = getopt(argc, argv, "c:d:D:efFgH:i:Ilm:M:n:p:s:S:tT:u:v:z:")) != -1)
while ((opt = getopt(argc, argv, "c:Cd:D:efFgH:i:Ilm:M:n:p:s:S:tT:u:v:z:")) != -1)
{
switch (opt)
{
case 'c':
code_to_look_up = atoi(optarg);
break;
case 'C':
colour_enabled = TRUE;
break;
case 'd':
decode_file_name = optarg;
break;
@ -845,7 +850,7 @@ int main(int argc, char *argv[])
| T4_SUPPORT_LENGTH_US_LETTER
| T4_SUPPORT_LENGTH_US_LEGAL
| T4_SUPPORT_LENGTH_UNLIMITED);
#if 0
#if 1
t30_set_supported_bilevel_resolutions(t30_state[i],
T4_SUPPORT_RESOLUTION_R8_STANDARD
| T4_SUPPORT_RESOLUTION_R8_FINE
@ -880,17 +885,20 @@ int main(int argc, char *argv[])
| T4_SUPPORT_RESOLUTION_600_1200
| T4_SUPPORT_RESOLUTION_1200_1200);
#endif
#if 1
t30_set_supported_colour_resolutions(t30_state[i], 0);
#else
t30_set_supported_colour_resolutions(t30_state[i],
T4_SUPPORT_RESOLUTION_100_100
| T4_SUPPORT_RESOLUTION_200_200
| T4_SUPPORT_RESOLUTION_300_300
| T4_SUPPORT_RESOLUTION_400_400
| T4_SUPPORT_RESOLUTION_600_600
| T4_SUPPORT_RESOLUTION_1200_1200);
#endif
if (colour_enabled)
{
t30_set_supported_colour_resolutions(t30_state[i],
T4_SUPPORT_RESOLUTION_100_100
| T4_SUPPORT_RESOLUTION_200_200
| T4_SUPPORT_RESOLUTION_300_300
| T4_SUPPORT_RESOLUTION_400_400
| T4_SUPPORT_RESOLUTION_600_600
| T4_SUPPORT_RESOLUTION_1200_1200);
}
else
{
t30_set_supported_colour_resolutions(t30_state[i], 0);
}
t30_set_supported_output_compressions(t30_state[i], T4_SUPPORT_COMPRESSION_T4_2D);
t30_set_ecm_capability(t30_state[i], use_ecm);
t30_set_supported_compressions(t30_state[i],

View File

@ -17,7 +17,7 @@
run_fax_test()
{
rm -f fax_tests_1.tif
rm -f fax_tests.tif
echo ./fax_tests ${OPTS} -i ${FILE}
./fax_tests ${OPTS} -i ${FILE} >xyzzy 2>xyzzy2
RETVAL=$?
@ -35,12 +35,87 @@ run_fax_test()
echo fax_tests failed!
exit $RETVAL
fi
rm -f fax_tests_1.tif
rm -f fax_tests.tif
echo tested ${FILE}
}
ITUTESTS_DIR=../test-data/itu/fax
run_colour_fax_test()
{
rm -f fax_tests.tif
echo ./fax_tests ${OPTS} -i ${IN_FILE}
./fax_tests ${OPTS} -i ${IN_FILE} >xyzzy 2>xyzzy2
RETVAL=$?
if [ $RETVAL != 0 ]
then
echo fax_tests failed!
exit $RETVAL
fi
# Now use tiffcmp to check the results. It will return non-zero if any page images differ. The -t
# option means the normal differences in tags will be ignored.
tiffcmp -t ${OUT_FILE} fax_tests.tif >/dev/null
RETVAL=$?
if [ $RETVAL != 0 ]
then
echo fax_tests failed!
exit $RETVAL
fi
rm -f fax_tests.tif
echo tested ${IN_FILE} to ${OUT_FILE}
}
ITUTESTS_DIR=../test-data/itu/fax
TIFFFX_DIR=../test-data/itu/tiff-fx
LOCALTESTS_DIR=../test-data/local
# Colour/gray -> bilevel by not allowing ECM
for OPTS in "-p AA" "-p TT" "-p GG" "-p TG" "-p GT"
do
IN_FILE="${LOCALTESTS_DIR}/lenna-colour.tif"
OUT_FILE="${LOCALTESTS_DIR}/lenna-colour-bilevel.tif"
run_colour_fax_test
IN_FILE="${LOCALTESTS_DIR}/lenna-bw.tif"
OUT_FILE="${LOCALTESTS_DIR}/lenna-bw-bilevel.tif"
run_colour_fax_test
IN_FILE="${TIFFFX_DIR}/c03x_02x.tif"
OUT_FILE="${TIFFFX_DIR}/c03x_02x.tif"
run_colour_fax_test
IN_FILE="${TIFFFX_DIR}/l02x_02x.tif"
OUT_FILE="${TIFFFX_DIR}/l02x_02x.tif"
run_colour_fax_test
IN_FILE="${TIFFFX_DIR}/l04x_02x.tif"
OUT_FILE="${TIFFFX_DIR}/l04x_02x.tif"
run_colour_fax_test
done
# Colour/gray -> colour/gray by allowing ECM
for OPTS in "-p AA -C -e" "-p TT -C -e" "-p GG -C -e" "-p TG -C -e" "-p GT -C -e"
do
IN_FILE="${LOCALTESTS_DIR}/lenna-colour.tif"
OUT_FILE="${LOCALTESTS_DIR}/lenna-colour.tif"
run_colour_fax_test
IN_FILE="${LOCALTESTS_DIR}/lenna-bw.tif"
OUT_FILE="${LOCALTESTS_DIR}/lenna-bw.tif"
run_colour_fax_test
IN_FILE="${TIFFFX_DIR}/c03x_02x.tif"
OUT_FILE="${TIFFFX_DIR}/c03x_02x.tif"
run_colour_fax_test
IN_FILE="${TIFFFX_DIR}/l02x_02x.tif"
OUT_FILE="${TIFFFX_DIR}/l02x_02x.tif"
run_colour_fax_test
IN_FILE="${TIFFFX_DIR}/l04x_02x.tif"
OUT_FILE="${TIFFFX_DIR}/l04x_02x.tif"
run_colour_fax_test
done
# Bi-level tests
for OPTS in "-p AA" "-p AA -e" "-p TT" "-p TT -e" "-p GG" "-p GG -e" "-p TG" "-p TG -e" "-p GT" "-p GT -e"
do
FILE="${ITUTESTS_DIR}/itutests.tif"

View File

@ -78,6 +78,7 @@ static void create_undithered_50_by_50(image_descriptor_t *im, uint8_t buf[], in
unsigned int j;
uint8_t *image8;
uint16_t *image16;
int samples_per_pixel;
im->image = (const uint8_t *) buf;
im->width = 50;
@ -88,53 +89,99 @@ static void create_undithered_50_by_50(image_descriptor_t *im, uint8_t buf[], in
switch (bytes_per_pixel)
{
case 1:
samples_per_pixel = 1;
image8 = buf;
for (i = 0; i < 50; i++)
for (i = 0; i < im->length; i++)
{
for (j = 0; j < 50; j++)
image8[50*i + j] = ((i + j)*655) >> 8;
for (j = 0; j < im->width; j++)
image8[im->width*i + j] = ((i + j)*655) >> 8;
}
break;
case 2:
samples_per_pixel = 1;
image16 = (uint16_t *) buf;
for (i = 0; i < 50; i++)
for (i = 0; i < im->length; i++)
{
for (j = 0; j < 50; j++)
image16[50*i + j] = (i + j)*655;
for (j = 0; j < im->width; j++)
image16[im->width*i + j] = (i + j)*655;
}
break;
case 3:
samples_per_pixel = 3;
image8 = buf;
for (i = 0; i < 50; i++)
for (i = 0; i < im->length; i++)
{
for (j = 0; j < 50; j++)
for (j = 0; j < im->width; j++)
{
#if 0
image8[50*3*i + 3*j + 0] = ((i + j)*655) >> 8;
image8[50*3*i + 3*j + 1] = ((i + j)*655) >> 8;
image8[50*3*i + 3*j + 2] = ((i + j)*655) >> 8;
image8[samples_per_pixel*(im->width*i + j) + 0] = ((i + j)*655) >> 8;
image8[samples_per_pixel*(im->width*i + j) + 1] = ((i + j)*655) >> 8;
image8[samples_per_pixel*(im->width*i + j) + 2] = ((i + j)*655) >> 8;
#else
image8[50*3*i + 3*j + 0] = saturateu8((((i + j)*655U)*36532U) >> 23);
image8[50*3*i + 3*j + 1] = saturateu8((((i + j)*655U)*37216U) >> 24);
image8[50*3*i + 3*j + 2] = saturateu8((((i + j)*655U)*47900U) >> 22);
image8[samples_per_pixel*(im->width*i + j) + 0] = saturateu8((((i + j)*655U)*36532U) >> 23);
image8[samples_per_pixel*(im->width*i + j) + 1] = saturateu8((((i + j)*655U)*37216U) >> 24);
image8[samples_per_pixel*(im->width*i + j) + 2] = saturateu8((((i + j)*655U)*47900U) >> 22);
#endif
}
}
break;
case 4:
samples_per_pixel = 4;
image8 = buf;
for (i = 0; i < im->length; i++)
{
for (j = 0; j < im->width; j++)
{
#if 0
image8[samples_per_pixel*(im->width*i + j) + 0] = ((i + j)*655) >> 8;
image8[samples_per_pixel*(im->width*i + j) + 1] = ((i + j)*655) >> 8;
image8[samples_per_pixel*(im->width*i + j) + 2] = ((i + j)*655) >> 8;
image8[samples_per_pixel*(im->width*i + j) + 3] = 0;
#else
image8[samples_per_pixel*(im->width*i + j) + 0] = saturateu8((((i + j)*655U)*36532U) >> 23);
image8[samples_per_pixel*(im->width*i + j) + 1] = saturateu8((((i + j)*655U)*37216U) >> 24);
image8[samples_per_pixel*(im->width*i + j) + 2] = saturateu8((((i + j)*655U)*47900U) >> 22);
image8[samples_per_pixel*(im->width*i + j) + 3] = 0;
#endif
}
}
break;
case 6:
samples_per_pixel = 3;
image16 = (uint16_t *) buf;
for (i = 0; i < 50; i++)
for (i = 0; i < im->length; i++)
{
for (j = 0; j < 50; j++)
for (j = 0; j < im->width; j++)
{
#if 0
image16[50*3*i + 3*j + 0] = (i + j)*655;
image16[50*3*i + 3*j + 1] = (i + j)*655;
image16[50*3*i + 3*j + 2] = (i + j)*655;
image16[samples_per_pixel*(im->width*i + j) + 0] = (i + j)*655;
image16[samples_per_pixel*(im->width*i + j) + 1] = (i + j)*655;
image16[samples_per_pixel*(im->width*i + j) + 2] = (i + j)*655;
#else
image16[50*3*i + 3*j + 0] = saturateu16((((i + j)*655U)*36532U) >> 15);
image16[50*3*i + 3*j + 1] = saturateu16((((i + j)*655U)*37216U) >> 16);
image16[50*3*i + 3*j + 2] = saturateu16((((i + j)*655U)*47900U) >> 14);
image16[samples_per_pixel*(im->width*i + j) + 0] = saturateu16((((i + j)*655U)*36532U) >> 15);
image16[samples_per_pixel*(im->width*i + j) + 1] = saturateu16((((i + j)*655U)*37216U) >> 16);
image16[samples_per_pixel*(im->width*i + j) + 2] = saturateu16((((i + j)*655U)*47900U) >> 14);
#endif
}
}
break;
case 8:
samples_per_pixel = 4;
image16 = (uint16_t *) buf;
for (i = 0; i < im->length; i++)
{
for (j = 0; j < im->width; j++)
{
#if 0
image16[samples_per_pixel*(im->width*i + j) + 0] = (i + j)*655;
image16[samples_per_pixel*(im->width*i + j) + 1] = (i + j)*655;
image16[samples_per_pixel*(im->width*i + j) + 2] = (i + j)*655;
image16[samples_per_pixel*(im->width*i + j) + 3] = 0;
#else
image16[samples_per_pixel*(im->width*i + j) + 0] = saturateu16((((i + j)*655U)*36532U) >> 15);
image16[samples_per_pixel*(im->width*i + j) + 1] = saturateu16((((i + j)*655U)*37216U) >> 16);
image16[samples_per_pixel*(im->width*i + j) + 2] = saturateu16((((i + j)*655U)*47900U) >> 14);
image16[samples_per_pixel*(im->width*i + j) + 3] = 0;
#endif
}
}
@ -232,7 +279,7 @@ static void get_bilevel_image(image_translate_state_t *s, int compare)
{
int i;
int len;
uint8_t row_buf[5000];
uint8_t row_buf[s->output_length*s->output_width/8];
for (i = 0; i < s->output_length; i++)
{
@ -264,7 +311,7 @@ static void get_gray8_image(image_translate_state_t *s, int compare)
unsigned int i;
unsigned int j;
int len;
uint8_t row_buf[5000];
uint8_t row_buf[s->output_length*s->output_width];
for (i = 0; i < s->output_length; i++)
{
@ -298,7 +345,7 @@ static void get_gray16_image(image_translate_state_t *s, int compare)
unsigned int i;
unsigned int j;
int len;
uint16_t row_buf[5000];
uint16_t row_buf[s->output_length*s->output_width];
for (i = 0; i < s->output_length; i++)
{
@ -309,7 +356,7 @@ static void get_gray16_image(image_translate_state_t *s, int compare)
}
if (compare)
{
for (j = 0; j < 50; j++)
for (j = 0; j < s->output_width; j++)
{
if (row_buf[j] != (i + j)*655)
{
@ -331,22 +378,24 @@ static void get_colour8_image(image_translate_state_t *s, int compare)
{
unsigned int i;
unsigned int j;
int samples_per_pixel;
int len;
int r;
int g;
int b;
uint8_t row_buf[5000];
uint8_t row_buf[3*s->output_length*s->output_width];
samples_per_pixel = 3;
for (i = 0; i < s->output_length; i++)
{
if ((len = image_translate_row(s, row_buf, 3*s->output_width)) != 3*s->output_width)
if ((len = image_translate_row(s, row_buf, samples_per_pixel*s->output_width)) != samples_per_pixel*s->output_width)
{
printf("Image finished early - %d %d\n", len, 3*s->output_width);
printf("Image finished early - %d %d\n", len, samples_per_pixel*s->output_width);
exit(2);
}
if (compare)
{
for (j = 0; j < 50; j++)
for (j = 0; j < s->output_width; j++)
{
#if 0
r = ((i + j)*655) >> 8;
@ -357,20 +406,24 @@ static void get_colour8_image(image_translate_state_t *s, int compare)
g = saturateu8((((i + j)*655U)*37216U) >> 24);
b = saturateu8((((i + j)*655U)*47900U) >> 22);
#endif
if (row_buf[3*j + 0] != r || row_buf[3*j + 1] != g || row_buf[3*j + 2] != b)
if (row_buf[samples_per_pixel*j + 0] != r
||
row_buf[samples_per_pixel*j + 1] != g
||
row_buf[samples_per_pixel*j + 2] != b)
{
printf("Image mismatch - %dx%d - (%d %d %d) (%d %d %d)\n",
j, i,
r, g, b,
row_buf[3*j + 0], row_buf[3*j + 1], row_buf[3*j + 2]);
row_buf[samples_per_pixel*j + 0], row_buf[samples_per_pixel*j + 1], row_buf[samples_per_pixel*j + 2]);
//exit(2);
}
}
}
}
if ((len = image_translate_row(s, row_buf, 2*s->output_width)) != 0)
if ((len = image_translate_row(s, row_buf, samples_per_pixel*s->output_width)) != 0)
{
printf("Image finished late - %d %d\n", len, 3*s->output_width);
printf("Image finished late - %d %d\n", len, samples_per_pixel*s->output_width);
exit(2);
}
}
@ -380,22 +433,24 @@ static void get_colour16_image(image_translate_state_t *s, int compare)
{
unsigned int i;
unsigned int j;
int samples_per_pixel;
int len;
int r;
int g;
int b;
uint16_t row_buf[5000];
uint16_t row_buf[3*s->output_length*s->output_width];
samples_per_pixel = 3;
for (i = 0; i < s->output_length; i++)
{
if ((len = image_translate_row(s, (uint8_t *) row_buf, 6*s->output_width)) != 6*s->output_width)
if ((len = image_translate_row(s, (uint8_t *) row_buf, 2*samples_per_pixel*s->output_width)) != 2*samples_per_pixel*s->output_width)
{
printf("Image finished early - %d %d\n", len, 6*s->output_width);
printf("Image finished early - %d %d\n", len, 2*samples_per_pixel*s->output_width);
exit(2);
}
if (compare)
{
for (j = 0; j < 50; j++)
for (j = 0; j < s->output_width; j++)
{
#if 0
r = (i + j)*655;
@ -406,60 +461,29 @@ static void get_colour16_image(image_translate_state_t *s, int compare)
g = saturateu16((((i + j)*655U)*37216U) >> 16);
b = saturateu16((((i + j)*655U)*47900U) >> 14);
#endif
if (row_buf[3*j + 0] != r || row_buf[3*j + 1] != g || row_buf[3*j + 2] != b)
if (row_buf[samples_per_pixel*j + 0] != r
||
row_buf[samples_per_pixel*j + 1] != g
||
row_buf[samples_per_pixel*j + 2] != b)
{
printf("Image mismatch - %dx%d - (%d %d %d) (%d %d %d)\n",
j, i,
r, g, b,
row_buf[3*j + 0], row_buf[3*j + 1], row_buf[3*j + 2]);
row_buf[samples_per_pixel*j + 0], row_buf[samples_per_pixel*j + 1], row_buf[samples_per_pixel*j + 2]);
//exit(2);
}
}
}
}
if ((len = image_translate_row(s, (uint8_t *) row_buf, 6*s->output_width)) != 0)
if ((len = image_translate_row(s, (uint8_t *) row_buf, 2*samples_per_pixel*s->output_width)) != 0)
{
printf("Image finished late - %d %d\n", len, 6*s->output_width);
printf("Image finished late - %d %d\n", len, 2*samples_per_pixel*s->output_width);
exit(2);
}
}
/*- End of function --------------------------------------------------------*/
static void translate_tests_gray16(void)
{
image_translate_state_t *s;
uint16_t image[50*50];
image_descriptor_t im;
printf("Dithering from a 16 bit per sample gray scale to bi-level\n");
create_undithered_50_by_50(&im, (uint8_t *) image, 2);
s = image_translate_init(NULL, T4_IMAGE_TYPE_BILEVEL, -1, -1, T4_IMAGE_TYPE_GRAY_12BIT, im.width, im.length, row_read, &im);
get_bilevel_image(s, TRUE);
printf("Scrunching from a 16 bit per sample gray scale to 8 bit per sample gray scale\n");
create_undithered_50_by_50(&im, (uint8_t *) image, 2);
s = image_translate_init(s, T4_IMAGE_TYPE_GRAY_8BIT, -1, -1, T4_IMAGE_TYPE_GRAY_12BIT, im.width, im.length, row_read, &im);
get_gray8_image(s, TRUE);
printf("Scrunching from a 16 bit per sample gray scale to 16 bit per sample gray scale\n");
create_undithered_50_by_50(&im, (uint8_t *) image, 2);
s = image_translate_init(s, T4_IMAGE_TYPE_GRAY_12BIT, -1, -1, T4_IMAGE_TYPE_GRAY_12BIT, im.width, im.length, row_read, &im);
get_gray16_image(s, TRUE);
printf("Scrunching from a 16 bit per sample gray scale to 3x8 bit per sample colour\n");
create_undithered_50_by_50(&im, (uint8_t *) image, 2);
s = image_translate_init(s, T4_IMAGE_TYPE_COLOUR_8BIT, -1, -1, T4_IMAGE_TYPE_GRAY_12BIT, im.width, im.length, row_read, &im);
get_colour8_image(s, TRUE);
printf("Scrunching from a 16 bit per sample gray scale to 3x16 bit per sample colour\n");
create_undithered_50_by_50(&im, (uint8_t *) image, 2);
s = image_translate_init(s, T4_IMAGE_TYPE_COLOUR_12BIT, -1, -1, T4_IMAGE_TYPE_GRAY_12BIT, im.width, im.length, row_read, &im);
get_colour16_image(s, TRUE);
image_translate_free(s);
}
/*- End of function --------------------------------------------------------*/
static void translate_tests_gray8(void)
{
image_translate_state_t *s;
@ -495,35 +519,35 @@ static void translate_tests_gray8(void)
}
/*- End of function --------------------------------------------------------*/
static void translate_tests_colour16(void)
static void translate_tests_gray16(void)
{
image_translate_state_t *s;
uint16_t image[50*50*3];
uint16_t image[50*50];
image_descriptor_t im;
printf("Dithering from a 3x16 bit per sample colour to bi-level\n");
create_undithered_50_by_50(&im, (uint8_t *) image, 6);
s = image_translate_init(NULL, T4_IMAGE_TYPE_BILEVEL, -1, -1, T4_IMAGE_TYPE_COLOUR_12BIT, im.width, im.length, row_read, &im);
printf("Dithering from a 16 bit per sample gray scale to bi-level\n");
create_undithered_50_by_50(&im, (uint8_t *) image, 2);
s = image_translate_init(NULL, T4_IMAGE_TYPE_BILEVEL, -1, -1, T4_IMAGE_TYPE_GRAY_12BIT, im.width, im.length, row_read, &im);
get_bilevel_image(s, TRUE);
printf("Scrunching from a 3x16 bit per sample colour to 8 bit per sample gray scale\n");
create_undithered_50_by_50(&im, (uint8_t *) image, 6);
s = image_translate_init(s, T4_IMAGE_TYPE_GRAY_8BIT, -1, -1, T4_IMAGE_TYPE_COLOUR_12BIT, im.width, im.length, row_read, &im);
printf("Scrunching from a 16 bit per sample gray scale to 8 bit per sample gray scale\n");
create_undithered_50_by_50(&im, (uint8_t *) image, 2);
s = image_translate_init(s, T4_IMAGE_TYPE_GRAY_8BIT, -1, -1, T4_IMAGE_TYPE_GRAY_12BIT, im.width, im.length, row_read, &im);
get_gray8_image(s, TRUE);
printf("Scrunching from a 3x16 bit per sample colour to 16 bit per sample gray scale\n");
create_undithered_50_by_50(&im, (uint8_t *) image, 6);
s = image_translate_init(s, T4_IMAGE_TYPE_GRAY_12BIT, -1, -1, T4_IMAGE_TYPE_COLOUR_12BIT, im.width, im.length, row_read, &im);
printf("Scrunching from a 16 bit per sample gray scale to 16 bit per sample gray scale\n");
create_undithered_50_by_50(&im, (uint8_t *) image, 2);
s = image_translate_init(s, T4_IMAGE_TYPE_GRAY_12BIT, -1, -1, T4_IMAGE_TYPE_GRAY_12BIT, im.width, im.length, row_read, &im);
get_gray16_image(s, TRUE);
printf("Scrunching from a 3x16 bit per sample colour to 3x8 bit per sample colour\n");
create_undithered_50_by_50(&im, (uint8_t *) image, 6);
s = image_translate_init(s, T4_IMAGE_TYPE_COLOUR_8BIT, -1, -1, T4_IMAGE_TYPE_COLOUR_12BIT, im.width, im.length, row_read, &im);
printf("Scrunching from a 16 bit per sample gray scale to 3x8 bit per sample colour\n");
create_undithered_50_by_50(&im, (uint8_t *) image, 2);
s = image_translate_init(s, T4_IMAGE_TYPE_COLOUR_8BIT, -1, -1, T4_IMAGE_TYPE_GRAY_12BIT, im.width, im.length, row_read, &im);
get_colour8_image(s, TRUE);
printf("Scrunching from a 3x16 bit per sample colour to 3x16 bit per sample colour\n");
create_undithered_50_by_50(&im, (uint8_t *) image, 6);
s = image_translate_init(s, T4_IMAGE_TYPE_COLOUR_12BIT, -1, -1, T4_IMAGE_TYPE_COLOUR_12BIT, im.width, im.length, row_read, &im);
printf("Scrunching from a 16 bit per sample gray scale to 3x16 bit per sample colour\n");
create_undithered_50_by_50(&im, (uint8_t *) image, 2);
s = image_translate_init(s, T4_IMAGE_TYPE_COLOUR_12BIT, -1, -1, T4_IMAGE_TYPE_GRAY_12BIT, im.width, im.length, row_read, &im);
get_colour16_image(s, TRUE);
image_translate_free(s);
@ -533,7 +557,7 @@ static void translate_tests_colour16(void)
static void translate_tests_colour8(void)
{
image_translate_state_t *s;
uint8_t image[50*50*3];
uint8_t image[3*50*50];
image_descriptor_t im;
printf("Dithering from a 3x8 bit per sample colour to bi-level\n");
@ -565,10 +589,45 @@ static void translate_tests_colour8(void)
}
/*- End of function --------------------------------------------------------*/
static void translate_tests_colour16(void)
{
image_translate_state_t *s;
uint16_t image[3*50*50];
image_descriptor_t im;
printf("Dithering from a 3x16 bit per sample colour to bi-level\n");
create_undithered_50_by_50(&im, (uint8_t *) image, 6);
s = image_translate_init(NULL, T4_IMAGE_TYPE_BILEVEL, -1, -1, T4_IMAGE_TYPE_COLOUR_12BIT, im.width, im.length, row_read, &im);
get_bilevel_image(s, TRUE);
printf("Scrunching from a 3x16 bit per sample colour to 8 bit per sample gray scale\n");
create_undithered_50_by_50(&im, (uint8_t *) image, 6);
s = image_translate_init(s, T4_IMAGE_TYPE_GRAY_8BIT, -1, -1, T4_IMAGE_TYPE_COLOUR_12BIT, im.width, im.length, row_read, &im);
get_gray8_image(s, TRUE);
printf("Scrunching from a 3x16 bit per sample colour to 16 bit per sample gray scale\n");
create_undithered_50_by_50(&im, (uint8_t *) image, 6);
s = image_translate_init(s, T4_IMAGE_TYPE_GRAY_12BIT, -1, -1, T4_IMAGE_TYPE_COLOUR_12BIT, im.width, im.length, row_read, &im);
get_gray16_image(s, TRUE);
printf("Scrunching from a 3x16 bit per sample colour to 3x8 bit per sample colour\n");
create_undithered_50_by_50(&im, (uint8_t *) image, 6);
s = image_translate_init(s, T4_IMAGE_TYPE_COLOUR_8BIT, -1, -1, T4_IMAGE_TYPE_COLOUR_12BIT, im.width, im.length, row_read, &im);
get_colour8_image(s, TRUE);
printf("Scrunching from a 3x16 bit per sample colour to 3x16 bit per sample colour\n");
create_undithered_50_by_50(&im, (uint8_t *) image, 6);
s = image_translate_init(s, T4_IMAGE_TYPE_COLOUR_12BIT, -1, -1, T4_IMAGE_TYPE_COLOUR_12BIT, im.width, im.length, row_read, &im);
get_colour16_image(s, TRUE);
image_translate_free(s);
}
/*- End of function --------------------------------------------------------*/
static void grow_tests_colour8(void)
{
image_translate_state_t *s;
uint8_t image[50*50*3];
uint8_t image[3*50*50];
image_descriptor_t im;
printf("Image growth tests\n");
@ -597,20 +656,20 @@ static void lenna_tests(int output_width, int output_length_scaling, const char
int image_width;
int image_length;
int output_length;
uint8_t *image;
uint8_t *image2;
int len;
int total;
int16_t bits_per_sample;
int16_t samples_per_pixel;
int i;
int n;
uint8_t *image;
uint8_t *image2;
int16_t bits_per_sample;
int16_t samples_per_pixel;
uint16_t res_unit;
image_translate_state_t *s;
image_translate_state_t *s2;
image_descriptor_t im;
float x_resolution;
float y_resolution;
uint16_t res_unit;
if (output_length_scaling >= 0)
printf("Dithering Lenna from colour to bi-level test\n");
@ -651,7 +710,7 @@ static void lenna_tests(int output_width, int output_length_scaling, const char
break;
}
}
printf("Image size %d %d\n", total, image_width*image_length*samples_per_pixel);
printf("Input image size %d %d\n", total, image_width*image_length*samples_per_pixel);
TIFFClose(in_file);
if (output_length_scaling > 0)

View File

@ -157,7 +157,8 @@ int main(int argc, char *argv[])
TIFF_FX_init();
#endif
set_lab_illuminant(&lab_param, 0.9638f, 1.0f, 0.8245f);
/* The default luminant is D50 */
set_lab_illuminant(&lab_param, 96.422f, 100.000f, 82.521f);
set_lab_gamut(&lab_param, 0, 100, -85, 85, -75, 125, FALSE);
source_file = (argc > 1) ? argv[1] : IN_FILE_NAME;
@ -218,7 +219,8 @@ int main(int argc, char *argv[])
#endif
lab_params_t lab;
set_lab_illuminant(&lab, 0.9638f, 1.0f, 0.8245f);
/* The default luminant is D50 */
set_lab_illuminant(&lab, 96.422f, 100.000f, 82.521f);
set_lab_gamut(&lab, 0, 100, -85, 85, -75, 125, FALSE);
lab_to_srgb(&lab, colour_map, colour_map, 256);
for (i = 0; i < (1 << bits_per_pixel); i++)
@ -447,12 +449,13 @@ int main(int argc, char *argv[])
if (photometric == PHOTOMETRIC_ITULAB)
{
printf("YYY ITULAB\n");
if (!t42_itulab_to_itulab(logging, (tdata_t) &outptr, &outsize, data, off, w, h))
#if 0
if (!t42_itulab_to_itulab(logging, (tdata_t) &outptr, &outsize, data, off, w, h, 3))
{
printf("Failed to convert to ITULAB\n");
return 1;
}
#endif
free(data);
data = (uint8_t *) outptr;
off = outsize;
@ -470,11 +473,12 @@ int main(int argc, char *argv[])
lab_to_srgb(&lab_param, data, data, w*h);
break;
case PHOTOMETRIC_ITULAB:
set_lab_illuminant(&lab_param, 0.9638f, 1.0f, 0.8245f);
/* The default luminant is D50 */
set_lab_illuminant(&lab_param, 96.422f, 100.000f, 82.521f);
set_lab_gamut(&lab_param, 0, 100, -85, 85, -75, 125, FALSE);
break;
}
if (!t42_srgb_to_itulab(logging, &lab_param, (tdata_t) &outptr, &outsize, data, off, w, h))
//if (!t42_srgb_to_itulab_jpeg(logging, &lab_param, (tdata_t) &outptr, &outsize, data, off, w, h, 3))
{
printf("Failed to convert to ITULAB\n");
return 1;
@ -532,7 +536,8 @@ int main(int argc, char *argv[])
bytes_per_row = (bits_per_pixel + 7)/8;
bytes_per_row *= w*samples_per_pixel;
totdata = h*bytes_per_row;
set_lab_illuminant(&lab_param, 0.9638f, 1.0f, 0.8245f);
/* The default luminant is D50 */
set_lab_illuminant(&lab_param, 96.422f, 100.000f, 82.521f);
set_lab_gamut(&lab_param, 0, 100, -85, 85, -75, 125, FALSE);
#if 0
start = rdtscll();
@ -551,7 +556,7 @@ int main(int argc, char *argv[])
#else
data2 = malloc(totdata);
start = rdtscll();
if (!t42_itulab_to_srgb(logging, &lab_param, data2, &off, data, off, &w, &h))
//if (!t42_itulab_jpeg_to_srgb(logging, &lab_param, data2, &off, data, off, &w, &h, &samples_per_pixel))
{
printf("Failed to convert from ITULAB\n");
return 1;

File diff suppressed because it is too large Load Diff

View File

@ -37,8 +37,12 @@
#include "udptl.h"
#if !defined(FALSE)
#define FALSE 0
#endif
#if !defined(TRUE)
#define TRUE (!FALSE)
#endif
static int decode_length(const uint8_t *buf, int limit, int *len, int *pvalue)
{
@ -58,7 +62,7 @@ static int decode_length(const uint8_t *buf, int limit, int *len, int *pvalue)
return 0;
}
*pvalue = (buf[(*len)++] & 0x3F) << 14;
/* Indicate we have a fragment */
/* Indicate that we have a fragment */
return 1;
}
/*- End of function --------------------------------------------------------*/
@ -66,11 +70,13 @@ static int decode_length(const uint8_t *buf, int limit, int *len, int *pvalue)
static int decode_open_type(const uint8_t *buf, int limit, int *len, const uint8_t **p_object, int *p_num_octets)
{
int octet_cnt;
#if 0
int octet_idx;
int stat;
const uint8_t **pbuf;
for (octet_idx = 0, *p_num_octets = 0; ; octet_idx += octet_cnt)
*p_num_octets = 0;
for (octet_idx = 0; ; octet_idx += octet_cnt)
{
if ((stat = decode_length(buf, limit, len, &octet_cnt)) < 0)
return -1;
@ -89,6 +95,21 @@ static int decode_open_type(const uint8_t *buf, int limit, int *len, const uint8
if (stat == 0)
break;
}
#else
/* We do not deal with fragments, so there is no point in looping through them. Just say that something
fragmented is bad. */
if (decode_length(buf, limit, len, &octet_cnt) != 0)
return -1;
*p_num_octets = octet_cnt;
if (octet_cnt > 0)
{
/* Make sure the buffer contains at least the number of bits requested */
if ((*len + octet_cnt) > limit)
return -1;
*p_object = &buf[*len];
*len += octet_cnt;
}
#endif
return 0;
}
/*- End of function --------------------------------------------------------*/
@ -153,7 +174,6 @@ static int encode_open_type(uint8_t *buf, int *len, const uint8_t *data, int num
int udptl_rx_packet(udptl_state_t *s, const uint8_t buf[], int len)
{
int stat;
int stat2;
int i;
int j;
int k;
@ -216,16 +236,16 @@ int udptl_rx_packet(udptl_state_t *s, const uint8_t buf[], int len)
total_count = 0;
do
{
if ((stat2 = decode_length(buf, len, &ptr, &count)) < 0)
if ((stat = decode_length(buf, len, &ptr, &count)) < 0)
return -1;
for (i = 0; i < count; i++)
{
if ((stat = decode_open_type(buf, len, &ptr, &bufs[total_count + i], &lengths[total_count + i])) != 0)
if (decode_open_type(buf, len, &ptr, &bufs[total_count + i], &lengths[total_count + i]) != 0)
return -1;
}
total_count += count;
}
while (stat2 > 0);
while (stat > 0);
/* We should now be exactly at the end of the packet. If not, this is a fault. */
if (ptr != len)
return -1;
@ -246,7 +266,8 @@ int udptl_rx_packet(udptl_state_t *s, const uint8_t buf[], int len)
/* Save the new packet. Redundancy mode won't use this, but some systems will switch into
FEC mode after sending some redundant packets, and this may then be important. */
x = (seq_no - i) & UDPTL_BUF_MASK;
memcpy(s->rx[x].buf, bufs[i - 1], lengths[i - 1]);
if (lengths[i - 1] > 0)
memcpy(s->rx[x].buf, bufs[i - 1], lengths[i - 1]);
s->rx[x].buf_len = lengths[i - 1];
s->rx[x].fec_len[0] = 0;
s->rx[x].fec_span = 0;