This commit is contained in:
Steve Underwood 2012-08-26 18:12:44 +08:00
parent 8cb975f345
commit 887c373c92
7 changed files with 106 additions and 80 deletions

View File

@ -123,16 +123,6 @@
#define HDLC_FRAMING_OK_THRESHOLD 8
static void fax_modems_hdlc_tx_frame(void *user_data, const uint8_t *msg, int len)
{
fax_modems_state_t *s;
s = (fax_modems_state_t *) user_data;
hdlc_tx_frame(&s->hdlc_tx, msg, len);
}
/*- End of function --------------------------------------------------------*/
static void tone_detected(void *user_data, int tone, int level, int delay)
{
t30_state_t *s;

View File

@ -98,6 +98,12 @@ SPAN_DECLARE(int) t42_encode_set_row_read_handler(t42_encode_state_t *s,
t4_row_read_handler_t handler,
void *user_data);
/*! Get the logging context associated with a T.42 encode context.
\brief Get the logging context associated with a T.42 encode context.
\param s The T.42 encode context.
\return A pointer to the logging context */
SPAN_DECLARE(logging_state_t *) t42_encode_get_logging_state(t42_encode_state_t *s);
SPAN_DECLARE(int) t42_encode_restart(t42_encode_state_t *s, uint32_t image_width, uint32_t image_length);
SPAN_DECLARE(t42_encode_state_t *) t42_encode_init(t42_encode_state_t *s,
@ -135,6 +141,12 @@ SPAN_DECLARE(int) t42_decode_get_compressed_image_size(t42_decode_state_t *s);
SPAN_DECLARE(int) t42_decode_new_plane(t42_decode_state_t *s);
/*! Get the logging context associated with a T.42 decode context.
\brief Get the logging context associated with a T.42 decode context.
\param s The T.42 decode context.
\return A pointer to the logging context */
SPAN_DECLARE(logging_state_t *) t42_decode_get_logging_state(t42_decode_state_t *s);
SPAN_DECLARE(int) t42_decode_restart(t42_decode_state_t *s);
SPAN_DECLARE(t42_decode_state_t *) t42_decode_init(t42_decode_state_t *s,

View File

@ -74,10 +74,11 @@ typedef enum
typedef enum
{
T4_IMAGE_TYPE_BILEVEL = 0,
T4_IMAGE_TYPE_GRAY_8BIT = 1,
T4_IMAGE_TYPE_GRAY_12BIT = 2,
T4_IMAGE_TYPE_COLOUR_8BIT = 3,
T4_IMAGE_TYPE_COLOUR_12BIT = 4
T4_IMAGE_TYPE_COLOUR_BILEVEL = 1,
T4_IMAGE_TYPE_GRAY_8BIT = 2,
T4_IMAGE_TYPE_GRAY_12BIT = 3,
T4_IMAGE_TYPE_COLOUR_8BIT = 4,
T4_IMAGE_TYPE_COLOUR_12BIT = 5
} t4_image_types_t;
/*! Supported X resolutions, in pixels per metre. */

View File

@ -396,16 +396,16 @@ SPAN_DECLARE(void) srgb_to_lab(lab_params_t *s, uint8_t lab[], const uint8_t srg
cielab_t l;
int i;
for (i = 0; i < pixels; i++)
for (i = 0; i < 3*pixels; i += 3)
{
#if defined(T42_USE_LUTS)
r = srgb_to_linear[srgb[0]];
g = srgb_to_linear[srgb[1]];
b = srgb_to_linear[srgb[2]];
r = srgb_to_linear[srgb[i]];
g = srgb_to_linear[srgb[i + 1]];
b = srgb_to_linear[srgb[i + 2]];
#else
r = srgb[0]/256.0f;
g = srgb[1]/256.0f;
b = srgb[2]/256.0f;
r = srgb[i]/256.0f;
g = srgb[i + 1]/256.0f;
b = srgb[i + 2]/256.0f;
/* sRGB to linear RGB */
r = (r > 0.04045f) ? powf((r + 0.055f)/1.055f, 2.4f) : r/12.92f;
@ -433,7 +433,6 @@ SPAN_DECLARE(void) srgb_to_lab(lab_params_t *s, uint8_t lab[], const uint8_t srg
lab_to_itu(s, lab, &l);
srgb += 3;
lab += 3;
}
}
@ -452,7 +451,7 @@ SPAN_DECLARE(void) lab_to_srgb(lab_params_t *s, uint8_t srgb[], const uint8_t la
int val;
int i;
for (i = 0; i < pixels; i++)
for (i = 0; i < 3*pixels; i += 3)
{
itu_to_lab(s, &l, lab);
@ -477,22 +476,21 @@ SPAN_DECLARE(void) lab_to_srgb(lab_params_t *s, uint8_t srgb[], const uint8_t la
#if defined(T42_USE_LUTS)
val = r*4096.0f;
srgb[0] = linear_to_srgb[(val < 0) ? 0 : (val < 4095) ? val : 4095];
srgb[i] = linear_to_srgb[(val < 0) ? 0 : (val < 4095) ? val : 4095];
val = g*4096.0f;
srgb[1] = linear_to_srgb[(val < 0) ? 0 : (val < 4095) ? val : 4095];
srgb[i + 1] = linear_to_srgb[(val < 0) ? 0 : (val < 4095) ? val : 4095];
val = b*4096.0f;
srgb[2] = linear_to_srgb[(val < 0) ? 0 : (val < 4095) ? val : 4095];
srgb[i + 2] = linear_to_srgb[(val < 0) ? 0 : (val < 4095) ? val : 4095];
#else
/* Linear RGB to sRGB */
r = (r > 0.0031308f) ? (1.055f*powf(r, 1.0f/2.4f) - 0.055f) : r*12.92f;
g = (g > 0.0031308f) ? (1.055f*powf(g, 1.0f/2.4f) - 0.055f) : g*12.92f;
b = (b > 0.0031308f) ? (1.055f*powf(b, 1.0f/2.4f) - 0.055f) : b*12.92f;
srgb[0] = saturateu8(floorf(r*256.0f));
srgb[1] = saturateu8(floorf(g*256.0f));
srgb[2] = saturateu8(floorf(b*256.0f));
srgb[i] = saturateu8(floorf(r*256.0f));
srgb[i + 1] = saturateu8(floorf(g*256.0f));
srgb[i + 2] = saturateu8(floorf(b*256.0f));
#endif
srgb += 3;
lab += 3;
}
}
@ -1233,6 +1231,12 @@ SPAN_DECLARE(int) t42_encode_set_row_read_handler(t42_encode_state_t *s,
}
/*- End of function --------------------------------------------------------*/
SPAN_DECLARE(logging_state_t *) t42_encode_get_logging_state(t42_encode_state_t *s)
{
return &s->logging;
}
/*- End of function --------------------------------------------------------*/
SPAN_DECLARE(int) t42_encode_restart(t42_encode_state_t *s, uint32_t image_width, uint32_t image_length)
{
//s->image_width = image_width;
@ -1357,6 +1361,12 @@ SPAN_DECLARE(int) t42_decode_new_plane(t42_decode_state_t *s)
}
/*- End of function --------------------------------------------------------*/
SPAN_DECLARE(logging_state_t *) t42_decode_get_logging_state(t42_decode_state_t *s)
{
return &s->logging;
}
/*- End of function --------------------------------------------------------*/
SPAN_DECLARE(int) t42_decode_restart(t42_decode_state_t *s)
{
s->compressed_image_size = 0;

View File

@ -170,6 +170,16 @@ static int get_tiff_directory_info(t4_tx_state_t *s)
{1200.0f/CM_PER_INCH, T4_Y_RESOLUTION_1200},
{ -1.00f, -1}
};
static const char *tiff_fx_fax_profiles[] =
{
"???",
"profile S",
"profile F",
"profile J",
"profile C",
"profile L",
"profile M"
};
uint16_t res_unit;
uint8_t parm8;
uint16_t parm16;
@ -184,14 +194,14 @@ static int get_tiff_directory_info(t4_tx_state_t *s)
uint16_t samples_per_pixel;
t = &s->tiff;
parm16 = 0;
TIFFGetField(t->tiff_file, TIFFTAG_BITSPERSAMPLE, &parm16);
bits_per_sample = parm16;
parm16 = 0;
TIFFGetField(t->tiff_file, TIFFTAG_SAMPLESPERPIXEL, &parm16);
samples_per_pixel = parm16;
bits_per_sample = 1;
TIFFGetField(t->tiff_file, TIFFTAG_BITSPERSAMPLE, &bits_per_sample);
samples_per_pixel = 1;
TIFFGetField(t->tiff_file, TIFFTAG_SAMPLESPERPIXEL, &samples_per_pixel);
if (samples_per_pixel == 1 && bits_per_sample == 1)
t->image_type = T4_IMAGE_TYPE_BILEVEL;
else if (samples_per_pixel == 3 && bits_per_sample == 1)
t->image_type = T4_IMAGE_TYPE_COLOUR_BILEVEL;
else if (samples_per_pixel == 1 && bits_per_sample == 8)
t->image_type = T4_IMAGE_TYPE_GRAY_8BIT;
else if (samples_per_pixel == 1 && bits_per_sample > 8)
@ -260,19 +270,19 @@ static int get_tiff_directory_info(t4_tx_state_t *s)
}
#if defined(SPANDSP_SUPPORT_TIFF_FX)
if (TIFFGetField(t->tiff_file, TIFFTAG_PROFILETYPE, &parm32))
printf("Profile type %u\n", parm32);
span_log(&s->logging, SPAN_LOG_FLOW, "Profile type %u\n", parm32);
if (TIFFGetField(t->tiff_file, TIFFTAG_FAXPROFILE, &parm8))
printf("FAX profile %u\n", parm8);
span_log(&s->logging, SPAN_LOG_FLOW, "FAX profile %s (%u)\n", tiff_fx_fax_profiles[parm8], parm8);
if (TIFFGetField(t->tiff_file, TIFFTAG_CODINGMETHODS, &parm32))
printf("Coding methods 0x%x\n", parm32);
span_log(&s->logging, SPAN_LOG_FLOW, "Coding methods 0x%x\n", parm32);
if (TIFFGetField(t->tiff_file, TIFFTAG_VERSIONYEAR, &u))
{
memcpy(uu, u, 4);
uu[4] = '\0';
printf("Version year \"%s\"\n", uu);
span_log(&s->logging, SPAN_LOG_FLOW, "Version year \"%s\"\n", uu);
}
if (TIFFGetField(t->tiff_file, TIFFTAG_MODENUMBER, &parm8))
printf("Mode number %u\n", parm8);
span_log(&s->logging, SPAN_LOG_FLOW, "Mode number %u\n", parm8);
#endif
return 0;
}
@ -319,11 +329,11 @@ static int test_tiff_directory_info(t4_tx_state_t *s)
t4_tx_tiff_state_t *t;
t = &s->tiff;
parm16 = 0;
parm16 = 1;
TIFFGetField(t->tiff_file, TIFFTAG_BITSPERSAMPLE, &parm16);
if (parm16 != 1)
return -1;
parm16 = 0;
parm16 = 1;
TIFFGetField(t->tiff_file, TIFFTAG_SAMPLESPERPIXEL, &parm16);
if (parm16 != 1)
return -1;

View File

@ -111,7 +111,7 @@ static void create_undithered_50_by_50(image_descriptor_t *im, uint8_t buf[], in
{
for (j = 0; j < 50; j++)
{
#if 1
#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;
@ -129,7 +129,7 @@ static void create_undithered_50_by_50(image_descriptor_t *im, uint8_t buf[], in
{
for (j = 0; j < 50; j++)
{
#if 1
#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;
@ -350,7 +350,7 @@ static void get_colour8_image(image_translate_state_t *s, int compare)
{
for (j = 0; j < 50; j++)
{
#if 1
#if 0
r = ((i + j)*655) >> 8;
g = ((i + j)*655) >> 8;
b = ((i + j)*655) >> 8;
@ -399,7 +399,7 @@ static void get_colour16_image(image_translate_state_t *s, int compare)
{
for (j = 0; j < 50; j++)
{
#if 1
#if 0
r = (i + j)*655;
g = (i + j)*655;
b = (i + j)*655;
@ -638,7 +638,7 @@ static void lenna_tests(int output_width, int output_length_scaling, const char
TIFFGetField(in_file, TIFFTAG_BITSPERSAMPLE, &bits_per_sample);
samples_per_pixel = 0;
TIFFGetField(in_file, TIFFTAG_SAMPLESPERPIXEL, &samples_per_pixel);
printf("Original image is %d x %d, %f x %f resolution, %d bits per sample, %d samples per pixel\n", image_width, image_length, x_resolution, y_resolution, bits_per_sample, samples_per_pixel);
printf("Original image is %d x %d, %.2f x %.2f resolution, %d bits per sample, %d samples per pixel\n", image_width, image_length, x_resolution, y_resolution, bits_per_sample, samples_per_pixel);
if ((image = malloc(image_width*image_length*samples_per_pixel)) == NULL)
return;
for (total = 0, i = 0; i < 1000; i++)

View File

@ -54,7 +54,7 @@ int data5_ptr = 0;
int plane = 0;
int bit_mask;
uint8_t xxx[3*256];
uint8_t colour_map[3*256];
lab_params_t lab_param;
@ -141,10 +141,10 @@ int main(int argc, char *argv[])
t85_decode_state_t t85_dec;
uint64_t start;
uint64_t end;
uint16_t *yyyL;
uint16_t *yyya;
uint16_t *yyyb;
uint16_t *yyyz;
uint16_t *map_L;
uint16_t *map_a;
uint16_t *map_b;
uint16_t *map_z;
logging_state_t *logging;
printf("Demo of ITU/Lab library.\n");
@ -187,37 +187,37 @@ int main(int argc, char *argv[])
planar_config = 0;
TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &planar_config);
off = 0;
yyyL = NULL;
yyya = NULL;
yyyb = NULL;
yyyz = NULL;
if (TIFFGetField(tif, TIFFTAG_COLORMAP, &yyyL, &yyya, &yyyb, &yyyz))
map_L = NULL;
map_a = NULL;
map_b = NULL;
map_z = NULL;
if (TIFFGetField(tif, TIFFTAG_COLORMAP, &map_L, &map_a, &map_b, &map_z))
{
#if 0
/* Sweep the colormap in the proper order */
for (i = 0; i < (1 << bits_per_pixel); i++)
{
xxx[3*i] = (yyyL[i] >> 8) & 0xFF;
xxx[3*i + 1] = (yyya[i] >> 8) & 0xFF;
xxx[3*i + 2] = (yyyb[i] >> 8) & 0xFF;
printf("Map %3d - %5d %5d %5d\n", i, xxx[3*i], xxx[3*i + 1], xxx[3*i + 2]);
colour_map[3*i] = (map_L[i] >> 8) & 0xFF;
colour_map[3*i + 1] = (map_a[i] >> 8) & 0xFF;
colour_map[3*i + 2] = (map_b[i] >> 8) & 0xFF;
printf("Map %3d - %5d %5d %5d\n", i, colour_map[3*i], colour_map[3*i + 1], colour_map[3*i + 2]);
}
#else
/* Sweep the colormap in the order that seems to work for l04x_02x.tif */
for (i = 0; i < (1 << bits_per_pixel); i++)
{
xxx[i] = (yyyL[i] >> 8) & 0xFF;
xxx[256 + i] = (yyya[i] >> 8) & 0xFF;
xxx[2*256 + i] = (yyyb[i] >> 8) & 0xFF;
colour_map[i] = (map_L[i] >> 8) & 0xFF;
colour_map[256 + i] = (map_a[i] >> 8) & 0xFF;
colour_map[2*256 + i] = (map_b[i] >> 8) & 0xFF;
}
#endif
lab_params_t lab;
set_lab_illuminant(&lab, 0.9638f, 1.0f, 0.8245f);
set_lab_gamut(&lab, 0, 100, -85, 85, -75, 125, FALSE);
lab_to_srgb(&lab, xxx, xxx, 256);
lab_to_srgb(&lab, colour_map, colour_map, 256);
for (i = 0; i < (1 << bits_per_pixel); i++)
printf("Map %3d - %5d %5d %5d\n", i, xxx[3*i], xxx[3*i + 1], xxx[3*i + 2]);
printf("Map %3d - %5d %5d %5d\n", i, colour_map[3*i], colour_map[3*i + 1], colour_map[3*i + 2]);
}
else
{
@ -273,7 +273,7 @@ int main(int argc, char *argv[])
}
}
if (total_len != total_image_len)
printf("Size mismatch %d %d\n", total_len, total_image_len);
printf("Size mismatch %ld %ld\n", total_len, total_image_len);
off = total_len;
switch (compression)
{
@ -282,7 +282,7 @@ int main(int argc, char *argv[])
case COMPRESSION_CCITT_T6:
break;
case COMPRESSION_T85:
printf("T.85 image %d bytes\n", total_len);
printf("T.85 image %ld bytes\n", total_len);
for (i = 0; i < 16; i++)
printf("0x%02x\n", data[i]);
t85_decode_init(&t85_dec, t85_row_write_handler, NULL);
@ -295,7 +295,7 @@ int main(int argc, char *argv[])
t85_decode_release(&t85_dec);
return 0;
case COMPRESSION_T43:
printf("T.43 image %d bytes\n", total_len);
printf("T.43 image %ld bytes\n", total_len);
if (pack_16(data) == 0xFFA8)
{
data += 2;
@ -359,10 +359,10 @@ int main(int argc, char *argv[])
for (j = 0; j < data5_ptr; j += 3)
{
i = data5[j] & 0xFF;
//printf("%d %d %d %d %d %d\n", data5_ptr, j, i, xxx[3*i], xxx[3*i + 1], xxx[3*i + 2]);
data5[j] = xxx[3*i];
data5[j + 1] = xxx[3*i + 1];
data5[j + 2] = xxx[3*i + 2];
//printf("%d %d %d %d %d %d\n", data5_ptr, j, i, colour_map[3*i], colour_map[3*i + 1], colour_map[3*i + 2]);
data5[j] = colour_map[3*i];
data5[j + 1] = colour_map[3*i + 1];
data5[j + 2] = colour_map[3*i + 2];
}
if ((tif = TIFFOpen(OUT_FILE_NAME, "w")) == NULL)
@ -420,7 +420,7 @@ int main(int argc, char *argv[])
return 1;
off += bytes_per_row;
}
printf("total %d, off %d\n", totdata, off);
printf("total %d, off %ld\n", totdata, off);
/* We now have the image in memory in RGB form */
@ -440,17 +440,20 @@ int main(int argc, char *argv[])
else
{
start = rdtscll();
if (photometric == PHOTOMETRIC_CIELAB)
switch (photometric)
{
case PHOTOMETRIC_CIELAB:
printf("CIELAB\n");
/* The default luminant is D50 */
set_lab_illuminant(&lab_param, 96.422f, 100.000f, 82.521f);
set_lab_gamut(&lab_param, 0, 100, -128, 127, -128, 127, TRUE);
lab_to_srgb(&lab_param, data, data, w*h);
break;
case PHOTOMETRIC_ITULAB:
set_lab_illuminant(&lab_param, 0.9638f, 1.0f, 0.8245f);
set_lab_gamut(&lab_param, 0, 100, -85, 85, -75, 125, FALSE);
break;
}
set_lab_illuminant(&lab_param, 0.9638f, 1.0f, 0.8245f);
set_lab_gamut(&lab_param, 0, 100, -85, 85, -75, 125, FALSE);
if (!t42_srgb_to_itulab(logging, &lab_param, (tdata_t) &outptr, &outsize, data, off, w, h))
{
printf("Failed to convert to ITULAB\n");
@ -465,7 +468,7 @@ int main(int argc, char *argv[])
}
TIFFClose(tif);
printf("XXX - image is %d by %d, %d bytes\n", w, h, off);
printf("XXX - image is %d by %d, %ld bytes\n", w, h, off);
/* We now have the image in memory in ITULAB form */