コード例 #1
0
ファイル: pdf-stream.c プロジェクト: PuzzleFlow/mupdf
/*
 * Create a filter given a name and param dictionary.
 */
static fz_stream *
build_filter(fz_context *ctx, fz_stream *chain, pdf_document *doc, pdf_obj *f, pdf_obj *p, int num, int gen, fz_compression_params *params)
{
	fz_compression_params local_params;

	if (params == NULL)
		params = &local_params;

	build_compression_params(ctx, f, p, params);

	/* If we were using params we were passed in, and we successfully
	 * recognised the image type, we can use the existing filter and
	 * shortstop here. */
	if (params != &local_params && params->type != FZ_IMAGE_RAW)
		return chain;

	if (params->type != FZ_IMAGE_RAW)
		return fz_open_image_decomp_stream(ctx, chain, params, NULL);

	if (pdf_name_eq(ctx, f, PDF_NAME_ASCIIHexDecode) || pdf_name_eq(ctx, f, PDF_NAME_AHx))
		return fz_open_ahxd(ctx, chain);

	else if (pdf_name_eq(ctx, f, PDF_NAME_ASCII85Decode) || pdf_name_eq(ctx, f, PDF_NAME_A85))
		return fz_open_a85d(ctx, chain);

	else if (pdf_name_eq(ctx, f, PDF_NAME_JBIG2Decode))
	{
		fz_jbig2_globals *globals = NULL;
		pdf_obj *obj = pdf_dict_get(ctx, p, PDF_NAME_JBIG2Globals);
		if (pdf_is_indirect(ctx, obj))
			globals = pdf_load_jbig2_globals(ctx, doc, obj);
		/* fz_open_jbig2d takes possession of globals */
		return fz_open_jbig2d(ctx, chain, globals);
	}

	else if (pdf_name_eq(ctx, f, PDF_NAME_JPXDecode))
		return chain; /* JPX decoding is special cased in the image loading code */

	else if (pdf_name_eq(ctx, f, PDF_NAME_Crypt))
	{
		pdf_obj *name;

		if (!doc->crypt)
		{
			fz_warn(ctx, "crypt filter in unencrypted document");
			return chain;
		}

		name = pdf_dict_get(ctx, p, PDF_NAME_Name);
		if (pdf_is_name(ctx, name))
			return pdf_open_crypt_with_filter(ctx, chain, doc->crypt, name, num, gen);

		return chain;
	}

	fz_warn(ctx, "unknown filter name (%s)", pdf_to_name(ctx, f));
	return chain;
}
コード例 #2
0
ファイル: pdf_stream.c プロジェクト: Ernest0x/mupdf
/*
 * Create a filter given a name and param dictionary.
 */
static fz_stream *
build_filter(fz_stream *chain, pdf_document * xref, pdf_obj * f, pdf_obj * p, int num, int gen, pdf_image_params *params)
{
    fz_context *ctx = chain->ctx;
    char *s = pdf_to_name(f);

    int predictor = pdf_to_int(pdf_dict_gets(p, "Predictor"));
    int columns = pdf_to_int(pdf_dict_gets(p, "Columns"));
    int colors = pdf_to_int(pdf_dict_gets(p, "Colors"));
    int bpc = pdf_to_int(pdf_dict_gets(p, "BitsPerComponent"));

    if (predictor == 0) predictor = 1;
    if (columns == 0) columns = 1;
    if (colors == 0) colors = 1;
    if (bpc == 0) bpc = 8;

    if (!strcmp(s, "ASCIIHexDecode") || !strcmp(s, "AHx"))
        return fz_open_ahxd(chain);

    else if (!strcmp(s, "ASCII85Decode") || !strcmp(s, "A85"))
        return fz_open_a85d(chain);

    else if (!strcmp(s, "CCITTFaxDecode") || !strcmp(s, "CCF"))
    {
        pdf_obj *k = pdf_dict_gets(p, "K");
        pdf_obj *eol = pdf_dict_gets(p, "EndOfLine");
        pdf_obj *eba = pdf_dict_gets(p, "EncodedByteAlign");
        pdf_obj *columns = pdf_dict_gets(p, "Columns");
        pdf_obj *rows = pdf_dict_gets(p, "Rows");
        pdf_obj *eob = pdf_dict_gets(p, "EndOfBlock");
        pdf_obj *bi1 = pdf_dict_gets(p, "BlackIs1");
        if (params)
        {
            /* We will shortstop here */
            params->type = PDF_IMAGE_FAX;
            params->u.fax.k = (k ? pdf_to_int(k) : 0);
            params->u.fax.eol = (eol ? pdf_to_bool(eol) : 0);
            params->u.fax.eba = (eba ? pdf_to_bool(eba) : 0);
            params->u.fax.columns = (columns ? pdf_to_int(columns) : 1728);
            params->u.fax.rows = (rows ? pdf_to_int(rows) : 0);
            params->u.fax.eob = (eob ? pdf_to_bool(eob) : 1);
            params->u.fax.bi1 = (bi1 ? pdf_to_bool(bi1) : 0);
            return chain;
        }
        return fz_open_faxd(chain,
                            k ? pdf_to_int(k) : 0,
                            eol ? pdf_to_bool(eol) : 0,
                            eba ? pdf_to_bool(eba) : 0,
                            columns ? pdf_to_int(columns) : 1728,
                            rows ? pdf_to_int(rows) : 0,
                            eob ? pdf_to_bool(eob) : 1,
                            bi1 ? pdf_to_bool(bi1) : 0);
    }

    else if (!strcmp(s, "DCTDecode") || !strcmp(s, "DCT"))
    {
        pdf_obj *ct = pdf_dict_gets(p, "ColorTransform");
        if (params)
        {
            /* We will shortstop here */
            params->type = PDF_IMAGE_JPEG;
            params->u.jpeg.ct = (ct ? pdf_to_int(ct) : -1);
            return chain;
        }
        return fz_open_dctd(chain, ct ? pdf_to_int(ct) : -1);
    }

    else if (!strcmp(s, "RunLengthDecode") || !strcmp(s, "RL"))
    {
        if (params)
        {
            /* We will shortstop here */
            params->type = PDF_IMAGE_RLD;
            return chain;
        }
        return fz_open_rld(chain);
    }
    else if (!strcmp(s, "FlateDecode") || !strcmp(s, "Fl"))
    {
        if (params)
        {
            /* We will shortstop here */
            params->type = PDF_IMAGE_FLATE;
            params->u.flate.predictor = predictor;
            params->u.flate.columns = columns;
            params->u.flate.colors = colors;
            params->u.flate.bpc = bpc;
            return chain;
        }
        chain = fz_open_flated(chain);
        if (predictor > 1)
            chain = fz_open_predict(chain, predictor, columns, colors, bpc);
        return chain;
    }

    else if (!strcmp(s, "LZWDecode") || !strcmp(s, "LZW"))
    {
        pdf_obj *ec = pdf_dict_gets(p, "EarlyChange");
        if (params)
        {
            /* We will shortstop here */
            params->type = PDF_IMAGE_LZW;
            params->u.lzw.predictor = predictor;
            params->u.lzw.columns = columns;
            params->u.lzw.colors = colors;
            params->u.lzw.bpc = bpc;
            params->u.lzw.ec = (ec ? pdf_to_int(ec) : 1);
            return chain;
        }
        chain = fz_open_lzwd(chain, ec ? pdf_to_int(ec) : 1);
        if (predictor > 1)
            chain = fz_open_predict(chain, predictor, columns, colors, bpc);
        return chain;
    }

    else if (!strcmp(s, "JBIG2Decode"))
    {
        fz_buffer *globals = NULL;
        pdf_obj *obj = pdf_dict_gets(p, "JBIG2Globals");
        if (obj)
            globals = pdf_load_stream(xref, pdf_to_num(obj), pdf_to_gen(obj));
        /* fz_open_jbig2d takes possession of globals */
        return fz_open_jbig2d(chain, globals);
    }

    else if (!strcmp(s, "JPXDecode"))
        return chain; /* JPX decoding is special cased in the image loading code */

    else if (!strcmp(s, "Crypt"))
    {
        pdf_obj *name;

        if (!xref->crypt)
        {
            fz_warn(ctx, "crypt filter in unencrypted document");
            return chain;
        }

        name = pdf_dict_gets(p, "Name");
        if (pdf_is_name(name))
            return pdf_open_crypt_with_filter(chain, xref->crypt, pdf_to_name(name), num, gen);

        return chain;
    }

    fz_warn(ctx, "unknown filter name (%s)", s);
    return chain;
}
コード例 #3
0
/*
 * Create a filter given a name and param dictionary.
 */
static fz_stream *
build_filter(fz_stream *chain, pdf_xref * xref, fz_obj * f, fz_obj * p, int num, int gen)
{
	fz_error error;
	char *s;

	s = fz_to_name(f);

	if (!strcmp(s, "ASCIIHexDecode") || !strcmp(s, "AHx"))
		return fz_open_ahxd(chain);

	else if (!strcmp(s, "ASCII85Decode") || !strcmp(s, "A85"))
		return fz_open_a85d(chain);

	else if (!strcmp(s, "CCITTFaxDecode") || !strcmp(s, "CCF"))
		return fz_open_faxd(chain, p);

	else if (!strcmp(s, "DCTDecode") || !strcmp(s, "DCT"))
		return fz_open_dctd(chain, p);

	else if (!strcmp(s, "RunLengthDecode") || !strcmp(s, "RL"))
		return fz_open_rld(chain);

	else if (!strcmp(s, "FlateDecode") || !strcmp(s, "Fl"))
	{
		fz_obj *obj = fz_dict_gets(p, "Predictor");
		if (fz_to_int(obj) > 1)
			return fz_open_predict(fz_open_flated(chain), p);
		return fz_open_flated(chain);
	}

	else if (!strcmp(s, "LZWDecode") || !strcmp(s, "LZW"))
	{
		fz_obj *obj = fz_dict_gets(p, "Predictor");
		if (fz_to_int(obj) > 1)
			return fz_open_predict(fz_open_lzwd(chain, p), p);
		return fz_open_lzwd(chain, p);
	}

	else if (!strcmp(s, "JBIG2Decode"))
	{
		fz_obj *obj = fz_dict_gets(p, "JBIG2Globals");
		if (obj)
		{
			fz_buffer *globals;
			error = pdf_load_stream(&globals, xref, fz_to_num(obj), fz_to_gen(obj));
			if (error)
				fz_catch(error, "cannot load jbig2 global segments");
			chain = fz_open_jbig2d(chain, globals);
			fz_drop_buffer(globals);
			return chain;
		}
		return fz_open_jbig2d(chain, NULL);
	}

	else if (!strcmp(s, "JPXDecode"))
		return chain; /* JPX decoding is special cased in the image loading code */

	else if (!strcmp(s, "Crypt"))
	{
		fz_obj *name;

		if (!xref->crypt)
		{
			fz_warn("crypt filter in unencrypted document");
			return chain;
		}

		name = fz_dict_gets(p, "Name");
		if (fz_is_name(name))
			return pdf_open_crypt_with_filter(chain, xref->crypt, fz_to_name(name), num, gen);

		return chain;
	}

	fz_warn("unknown filter name (%s)", s);
	return chain;
}