2008-11-03 11:01:22 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2008 Chris Wilson
|
|
|
|
|
*
|
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software
|
|
|
|
|
* and its documentation for any purpose is hereby granted without
|
|
|
|
|
* fee, provided that the above copyright notice appear in all copies
|
|
|
|
|
* and that both that copyright notice and this permission notice
|
|
|
|
|
* appear in supporting documentation, and that the name of
|
|
|
|
|
* Chris Wilson not be used in advertising or publicity pertaining to
|
|
|
|
|
* distribution of the software without specific, written prior
|
|
|
|
|
* permission. Chris Wilson makes no representations about the
|
|
|
|
|
* suitability of this software for any purpose. It is provided "as
|
|
|
|
|
* is" without express or implied warranty.
|
|
|
|
|
*
|
|
|
|
|
* CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
|
|
|
|
|
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
|
* FITNESS, IN NO EVENT SHALL CHRIS WILSON BE LIABLE FOR ANY SPECIAL,
|
|
|
|
|
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
|
|
|
|
|
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
|
|
|
|
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
|
|
|
|
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*
|
|
|
|
|
* Author: Chris Wilson <chris@chris-wilson.co.uk>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "cairo-test.h"
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
|
|
/* Basic test to exercise the new mime-data embedding. */
|
|
|
|
|
|
|
|
|
|
static cairo_status_t
|
2008-11-05 17:18:51 +00:00
|
|
|
read_file (const cairo_test_context_t *ctx,
|
|
|
|
|
const char *filename,
|
|
|
|
|
unsigned char **data_out,
|
|
|
|
|
unsigned int *length_out)
|
2008-11-03 11:01:22 +00:00
|
|
|
{
|
|
|
|
|
FILE *file;
|
|
|
|
|
unsigned char *buf;
|
|
|
|
|
unsigned int len;
|
|
|
|
|
|
2008-11-05 17:18:51 +00:00
|
|
|
file = fopen (filename, "rb");
|
2008-11-03 11:01:22 +00:00
|
|
|
if (file == NULL) {
|
2008-11-05 17:18:51 +00:00
|
|
|
char path[4096];
|
2008-11-03 11:01:22 +00:00
|
|
|
|
2009-01-29 09:50:38 +00:00
|
|
|
if (errno == ENOMEM)
|
|
|
|
|
return CAIRO_STATUS_NO_MEMORY;
|
|
|
|
|
|
2008-11-03 11:01:22 +00:00
|
|
|
/* try again with srcdir */
|
2008-11-05 17:18:51 +00:00
|
|
|
snprintf (path, sizeof (path),
|
|
|
|
|
"%s/%s", ctx->srcdir, filename);
|
|
|
|
|
file = fopen (path, "rb");
|
2008-11-03 11:01:22 +00:00
|
|
|
}
|
|
|
|
|
if (file == NULL) {
|
|
|
|
|
switch (errno) {
|
|
|
|
|
case ENOMEM:
|
|
|
|
|
return CAIRO_STATUS_NO_MEMORY;
|
|
|
|
|
default:
|
|
|
|
|
return CAIRO_STATUS_FILE_NOT_FOUND;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fseek (file, 0, SEEK_END);
|
|
|
|
|
len = ftell (file);
|
|
|
|
|
fseek (file, 0, SEEK_SET);
|
|
|
|
|
|
|
|
|
|
buf = xmalloc (len);
|
|
|
|
|
*length_out = fread (buf, 1, len, file);
|
|
|
|
|
fclose (file);
|
|
|
|
|
if (*length_out != len) {
|
|
|
|
|
free (buf);
|
|
|
|
|
return CAIRO_STATUS_READ_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*data_out = buf;
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_test_status_t
|
2008-11-05 17:18:51 +00:00
|
|
|
paint_file (cairo_t *cr,
|
|
|
|
|
const char *filename, const char *mime_type,
|
|
|
|
|
int x, int y)
|
2008-11-03 11:01:22 +00:00
|
|
|
{
|
|
|
|
|
const cairo_test_context_t *ctx = cairo_test_get_context (cr);
|
|
|
|
|
cairo_surface_t *image;
|
2008-11-05 17:18:51 +00:00
|
|
|
unsigned char *mime_data;
|
|
|
|
|
unsigned int mime_length;
|
2008-11-03 11:01:22 +00:00
|
|
|
cairo_status_t status;
|
|
|
|
|
|
2008-11-05 17:18:51 +00:00
|
|
|
/* Deliberately use a non-matching MIME images, so that we can identify
|
|
|
|
|
* when the MIME representation is used in preference to the plain image
|
|
|
|
|
* surface.
|
|
|
|
|
*/
|
|
|
|
|
status = read_file (ctx, filename, &mime_data, &mime_length);
|
|
|
|
|
if (status)
|
2008-11-03 11:01:22 +00:00
|
|
|
return cairo_test_status_from_status (ctx, status);
|
|
|
|
|
|
2008-11-04 13:41:02 +00:00
|
|
|
image = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 200, 50);
|
2008-11-05 17:18:51 +00:00
|
|
|
|
|
|
|
|
status = cairo_surface_set_mime_data (image, mime_type,
|
2008-11-07 13:26:46 +00:00
|
|
|
mime_data, mime_length,
|
|
|
|
|
free, mime_data);
|
2008-11-03 11:01:22 +00:00
|
|
|
if (status) {
|
|
|
|
|
cairo_surface_destroy (image);
|
2009-01-29 09:50:38 +00:00
|
|
|
free (mime_data);
|
2008-11-03 11:01:22 +00:00
|
|
|
return cairo_test_status_from_status (ctx, status);
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-05 17:18:51 +00:00
|
|
|
cairo_set_source_surface (cr, image, x, y);
|
2008-11-03 11:01:22 +00:00
|
|
|
cairo_surface_destroy (image);
|
2008-11-05 17:18:51 +00:00
|
|
|
|
2008-11-03 11:01:22 +00:00
|
|
|
cairo_paint (cr);
|
|
|
|
|
|
|
|
|
|
return CAIRO_TEST_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-15 21:27:50 +09:30
|
|
|
static cairo_test_status_t
|
|
|
|
|
paint_jbig2_file (cairo_t *cr, int x, int y)
|
|
|
|
|
{
|
|
|
|
|
const cairo_test_context_t *ctx = cairo_test_get_context (cr);
|
|
|
|
|
cairo_surface_t *image;
|
|
|
|
|
unsigned char *mime_data;
|
|
|
|
|
unsigned int mime_length;
|
|
|
|
|
cairo_status_t status;
|
|
|
|
|
const char jbig2_image1_filename[] = "image1.jb2";
|
|
|
|
|
const char jbig2_image2_filename[] = "image2.jb2";
|
|
|
|
|
const char jbig2_global_filename[] = "global.jb2";
|
|
|
|
|
|
|
|
|
|
/* Deliberately use a non-matching MIME images, so that we can identify
|
|
|
|
|
* when the MIME representation is used in preference to the plain image
|
|
|
|
|
* surface.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* Image 1 */
|
|
|
|
|
|
|
|
|
|
status = read_file (ctx, jbig2_image1_filename, &mime_data, &mime_length);
|
|
|
|
|
if (status)
|
|
|
|
|
return cairo_test_status_from_status (ctx, status);
|
|
|
|
|
|
|
|
|
|
image = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 200, 50);
|
|
|
|
|
|
|
|
|
|
status = cairo_surface_set_mime_data (image, CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID,
|
|
|
|
|
(unsigned char *)"global", 6, NULL, NULL);
|
|
|
|
|
if (status) {
|
|
|
|
|
cairo_surface_destroy (image);
|
|
|
|
|
return cairo_test_status_from_status (ctx, status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status = cairo_surface_set_mime_data (image, CAIRO_MIME_TYPE_JBIG2,
|
|
|
|
|
mime_data, mime_length,
|
|
|
|
|
free, mime_data);
|
|
|
|
|
if (status) {
|
|
|
|
|
cairo_surface_destroy (image);
|
|
|
|
|
free (mime_data);
|
|
|
|
|
return cairo_test_status_from_status (ctx, status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cairo_set_source_surface (cr, image, x, y);
|
|
|
|
|
cairo_surface_destroy (image);
|
|
|
|
|
|
|
|
|
|
cairo_paint (cr);
|
|
|
|
|
|
|
|
|
|
/* Image 2 */
|
|
|
|
|
|
|
|
|
|
status = read_file (ctx, jbig2_image2_filename, &mime_data, &mime_length);
|
|
|
|
|
if (status)
|
|
|
|
|
return cairo_test_status_from_status (ctx, status);
|
|
|
|
|
|
|
|
|
|
image = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 200, 50);
|
|
|
|
|
|
|
|
|
|
status = cairo_surface_set_mime_data (image, CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID,
|
|
|
|
|
(unsigned char *)"global", 6, NULL, NULL);
|
|
|
|
|
if (status) {
|
|
|
|
|
cairo_surface_destroy (image);
|
|
|
|
|
return cairo_test_status_from_status (ctx, status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status = cairo_surface_set_mime_data (image, CAIRO_MIME_TYPE_JBIG2,
|
|
|
|
|
mime_data, mime_length,
|
|
|
|
|
free, mime_data);
|
|
|
|
|
if (status) {
|
|
|
|
|
cairo_surface_destroy (image);
|
|
|
|
|
free (mime_data);
|
|
|
|
|
return cairo_test_status_from_status (ctx, status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Set the global data */
|
|
|
|
|
status = read_file (ctx, jbig2_global_filename, &mime_data, &mime_length);
|
|
|
|
|
if (status)
|
|
|
|
|
return cairo_test_status_from_status (ctx, status);
|
|
|
|
|
|
|
|
|
|
status = cairo_surface_set_mime_data (image, CAIRO_MIME_TYPE_JBIG2_GLOBAL,
|
|
|
|
|
mime_data, mime_length,
|
|
|
|
|
free, mime_data);
|
|
|
|
|
if (status) {
|
|
|
|
|
cairo_surface_destroy (image);
|
|
|
|
|
free (mime_data);
|
|
|
|
|
return cairo_test_status_from_status (ctx, status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cairo_set_source_surface (cr, image, x, y + 50);
|
|
|
|
|
cairo_surface_destroy (image);
|
|
|
|
|
|
|
|
|
|
cairo_paint (cr);
|
|
|
|
|
return CAIRO_TEST_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-22 08:07:49 +10:30
|
|
|
static cairo_test_status_t
|
|
|
|
|
paint_ccitt_file (cairo_t *cr, int x, int y)
|
|
|
|
|
{
|
|
|
|
|
const cairo_test_context_t *ctx = cairo_test_get_context (cr);
|
|
|
|
|
cairo_surface_t *image;
|
|
|
|
|
unsigned char *mime_data;
|
|
|
|
|
unsigned int mime_length;
|
|
|
|
|
cairo_status_t status;
|
|
|
|
|
const char *ccitt_image_filename = "ccitt.g3";
|
|
|
|
|
const char *ccitt_image_params = "Columns=200 Rows=50 K=-1";
|
|
|
|
|
|
|
|
|
|
/* Deliberately use a non-matching MIME images, so that we can identify
|
|
|
|
|
* when the MIME representation is used in preference to the plain image
|
|
|
|
|
* surface.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
status = read_file (ctx, ccitt_image_filename, &mime_data, &mime_length);
|
|
|
|
|
if (status)
|
|
|
|
|
return cairo_test_status_from_status (ctx, status);
|
|
|
|
|
|
|
|
|
|
image = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 200, 50);
|
|
|
|
|
|
|
|
|
|
/* Set the CCITT image data */
|
|
|
|
|
status = cairo_surface_set_mime_data (image, CAIRO_MIME_TYPE_CCITT_FAX,
|
|
|
|
|
mime_data, mime_length,
|
|
|
|
|
free, mime_data);
|
|
|
|
|
if (status) {
|
|
|
|
|
cairo_surface_destroy (image);
|
|
|
|
|
free (mime_data);
|
|
|
|
|
return cairo_test_status_from_status (ctx, status);
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-09 09:43:02 -05:00
|
|
|
/* Set the CCITT image parameters */
|
2017-10-22 08:07:49 +10:30
|
|
|
status = cairo_surface_set_mime_data (image, CAIRO_MIME_TYPE_CCITT_FAX_PARAMS,
|
|
|
|
|
(unsigned char *)ccitt_image_params,
|
|
|
|
|
strlen (ccitt_image_params),
|
|
|
|
|
NULL, NULL);
|
|
|
|
|
if (status) {
|
|
|
|
|
cairo_surface_destroy (image);
|
|
|
|
|
return cairo_test_status_from_status (ctx, status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cairo_set_source_surface (cr, image, x, y);
|
|
|
|
|
cairo_surface_destroy (image);
|
|
|
|
|
|
|
|
|
|
cairo_paint (cr);
|
|
|
|
|
|
|
|
|
|
return CAIRO_TEST_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-05 17:18:51 +00:00
|
|
|
static cairo_test_status_t
|
|
|
|
|
draw (cairo_t *cr, int width, int height)
|
|
|
|
|
{
|
|
|
|
|
const char jpg_filename[] = "jpeg.jpg";
|
|
|
|
|
const char png_filename[] = "png.png";
|
2008-11-23 19:29:26 +10:30
|
|
|
const char jp2_filename[] = "jp2.jp2";
|
2008-11-05 17:18:51 +00:00
|
|
|
cairo_test_status_t status;
|
|
|
|
|
|
|
|
|
|
status = paint_file (cr, jpg_filename, CAIRO_MIME_TYPE_JPEG, 0, 0);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
|
|
status = paint_file (cr, png_filename, CAIRO_MIME_TYPE_PNG, 0, 50);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
|
2008-11-23 19:29:26 +10:30
|
|
|
status = paint_file (cr, jp2_filename, CAIRO_MIME_TYPE_JP2, 0, 100);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
|
2013-09-15 21:27:50 +09:30
|
|
|
status = paint_jbig2_file (cr, 0, 150);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
|
2017-10-22 08:07:49 +10:30
|
|
|
status = paint_ccitt_file (cr, 0, 250);
|
|
|
|
|
if (status)
|
|
|
|
|
return status;
|
|
|
|
|
|
2008-11-05 17:18:51 +00:00
|
|
|
return CAIRO_TEST_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-03 11:01:22 +00:00
|
|
|
CAIRO_TEST (mime_data,
|
|
|
|
|
"Check that the mime-data embedding works",
|
|
|
|
|
"jpeg, api", /* keywords */
|
|
|
|
|
NULL, /* requirements */
|
2017-10-22 08:07:49 +10:30
|
|
|
200, 300,
|
2008-11-03 11:01:22 +00:00
|
|
|
NULL, draw)
|