tiff_from_name(gx_device_xps *dev, const char *name, int big_endian, bool usebigtiff)
{
    char mode[5] = "w";
    int modelen = 1;
    TIFF *t;
    tifs_io_xps *tiffio;
    gs_memory_t *mem = dev->memory->non_gc_memory;
    char *filename;

    if (big_endian)
        mode[modelen++] = 'b';
    else
        mode[modelen++] = 'l';

    if (usebigtiff)
        /* this should never happen for libtiff < 4.0 - see tiff_put_some_params() */
        mode[modelen++] = '8';

    mode[modelen] = (char)0;

    tiffio = (tifs_io_xps *)gs_malloc(dev->memory->non_gc_memory,
        sizeof(tifs_io_xps), 1, "tiff_from_name");
    if (!tiffio) {
        return NULL;
    }
    tiffio->pdev = dev;

    filename = (char *)gs_alloc_bytes(mem, gp_file_name_sizeof,
        "tiff_from_name(filename)");
    if (!filename)
        return NULL;

    tiffio->fid = gp_open_scratch_file_rm(mem, "tif-", filename, "wb+");
    dev->xps_pie->fid = tiffio->fid;  /* We will be closing it from here */

    gs_free_object(mem, filename, "tiff_from_name(filename)");

    t = TIFFClientOpen(name, mode,
        (thandle_t)tiffio, (TIFFReadWriteProc)xps_tifsReadProc,
        (TIFFReadWriteProc)xps_tifsWriteProc, (TIFFSeekProc)xps_tifsSeekProc,
        xps_tifsCloseProc, (TIFFSizeProc)xps_tifsSizeProc, xps_tifsDummyMapProc,
        xps_tifsDummyUnmapProc);
    return t;
}
tiff_from_name(gx_device_xps *dev, const char *name, int big_endian, bool usebigtiff)
{
    char mode[5] = "w";
    int modelen = 1;
    TIFF *t;
    tifs_io_xps *tiffio;
    gs_memory_t *mem = dev->memory->non_gc_memory;
    char *filename;

    if (big_endian)
        mode[modelen++] = 'b';
    else
        mode[modelen++] = 'l';

    if (usebigtiff)
         
        mode[modelen++] = '8';

    mode[modelen] = (char)0;

    tiffio = (tifs_io_xps *)gs_malloc(dev->memory->non_gc_memory,
        sizeof(tifs_io_xps), 1, "tiff_from_name");
    if (!tiffio) {
        return NULL;
    }
    tiffio->pdev = dev;

    filename = (char *)gs_alloc_bytes(mem, gp_file_name_sizeof,
        "tiff_from_name(filename)");
    if (!filename)
        return NULL;

    tiffio->fid = gp_open_scratch_file_rm(mem, "tif-", filename, "wb+");
    dev->xps_pie->fid = tiffio->fid;   

    gs_free_object(mem, filename, "tiff_from_name(filename)");

    t = TIFFClientOpen(name, mode,
        (thandle_t)tiffio, (TIFFReadWriteProc)xps_tifsReadProc,
        (TIFFReadWriteProc)xps_tifsWriteProc, (TIFFSeekProc)xps_tifsSeekProc,
        xps_tifsCloseProc, (TIFFSizeProc)xps_tifsSizeProc, xps_tifsDummyMapProc,
        xps_tifsDummyUnmapProc);
    return t;
}