本文整理汇总了C#中BitMiracle.LibTiff.Classic.Tiff.FileName方法的典型用法代码示例。如果您正苦于以下问题:C# Tiff.FileName方法的具体用法?C# Tiff.FileName怎么用?C# Tiff.FileName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitMiracle.LibTiff.Classic.Tiff
的用法示例。
在下文中一共展示了Tiff.FileName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: writeBufferToSeparateTiles
bool writeBufferToSeparateTiles(Tiff outImage, byte[] buf, int imagelength, int imagewidth, short spp)
{
byte[] obuf = new byte[outImage.TileSize()];
FieldValue[] result = outImage.GetField(TiffTag.TILELENGTH);
int tl = result[0].ToInt();
result = outImage.GetField(TiffTag.TILEWIDTH);
int tw = result[0].ToInt();
result = outImage.GetField(TiffTag.BITSPERSAMPLE);
short bps = result[0].ToShort();
Debug.Assert(bps % 8 == 0);
short bytes_per_sample = (short)(bps / 8);
int imagew = outImage.ScanlineSize();
int tilew = outImage.TileRowSize();
int iimagew = outImage.RasterScanlineSize();
int iskew = iimagew - tilew * spp;
int bufp = 0;
for (int row = 0; row < imagelength; row += tl)
{
int nrow = (row + tl > imagelength) ? imagelength - row : tl;
int colb = 0;
for (int col = 0; col < imagewidth; col += tw)
{
for (short s = 0; s < spp; s++)
{
/*
* Tile is clipped horizontally. Calculate
* visible portion and skewing factors.
*/
if (colb + tilew > imagew)
{
int width = imagew - colb;
int oskew = tilew - width;
cpContigBufToSeparateBuf(obuf, buf, bufp + (colb * spp) + s, nrow, width / bytes_per_sample, oskew, (oskew * spp) + iskew, spp, bytes_per_sample);
}
else
cpContigBufToSeparateBuf(obuf, buf, bufp + (colb * spp) + s, nrow, m_tilewidth, 0, iskew, spp, bytes_per_sample);
if (outImage.WriteTile(obuf, col, row, 0, s) < 0)
{
Tiff.Error(outImage.FileName(), "Error, can't write tile at {0} {1} sample {2}", col, row, s);
return false;
}
}
colb += tilew;
}
bufp += nrow * iimagew;
}
return true;
}
示例2: writeBufferToSeparateStrips
static bool writeBufferToSeparateStrips(Tiff outImage, byte[] buf, int imagelength, int imagewidth, short spp)
{
byte[] obuf = new byte[outImage.StripSize()];
FieldValue[] result = outImage.GetFieldDefaulted(TiffTag.ROWSPERSTRIP);
int rowsperstrip = result[0].ToInt();
int rowsize = imagewidth * spp;
int strip = 0;
for (short s = 0; s < spp; s++)
{
for (int row = 0; row < imagelength; row += rowsperstrip)
{
int nrows = (row + rowsperstrip > imagelength) ? imagelength - row : rowsperstrip;
int stripsize = outImage.VStripSize(nrows);
cpContigBufToSeparateBuf(obuf, buf, row * rowsize + s, nrows, imagewidth, 0, 0, spp, 1);
if (outImage.WriteEncodedStrip(strip++, obuf, stripsize) < 0)
{
Tiff.Error(outImage.FileName(), "Error, can't write strip {0}", strip - 1);
return false;
}
}
}
return true;
}
示例3: writeBufferToContigTiles
bool writeBufferToContigTiles(Tiff outImage, byte[] buf, int imagelength, int imagewidth, short spp)
{
byte[] obuf = new byte[outImage.TileSize()];
FieldValue[] result = outImage.GetField(TiffTag.TILELENGTH);
int tl = result[0].ToInt();
result = outImage.GetField(TiffTag.TILEWIDTH);
int tw = result[0].ToInt();
int imagew = outImage.ScanlineSize();
int tilew = outImage.TileRowSize();
int iskew = imagew - tilew;
int bufp = 0;
for (int row = 0; row < imagelength; row += m_tilelength)
{
int nrow = (row + tl > imagelength) ? imagelength - row : tl;
int colb = 0;
for (int col = 0; col < imagewidth; col += tw)
{
/*
* Tile is clipped horizontally. Calculate
* visible portion and skewing factors.
*/
if (colb + tilew > imagew)
{
int width = imagew - colb;
int oskew = tilew - width;
cpStripToTile(obuf, 0, buf, bufp + colb, nrow, width, oskew, oskew + iskew);
}
else
cpStripToTile(obuf, 0, buf, bufp + colb, nrow, tilew, 0, iskew);
if (outImage.WriteTile(obuf, col, row, 0, 0) < 0)
{
Tiff.Error(outImage.FileName(), "Error, can't write tile at {0} {1}", col, row);
return false;
}
colb += tilew;
}
bufp += nrow * imagew;
}
return true;
}
示例4: cpSeparate2ContigByRow
/*
* Separate -> contig by row.
*/
bool cpSeparate2ContigByRow(Tiff inImage, Tiff outImage, int imagelength, int imagewidth, short spp)
{
byte[] inbuf = new byte[inImage.ScanlineSize()];
byte[] outbuf = new byte[outImage.ScanlineSize()];
for (int row = 0; row < imagelength; row++)
{
/* merge channels */
for (short s = 0; s < spp; s++)
{
if (!inImage.ReadScanline(inbuf, row, s) && !m_ignore)
{
Tiff.Error(inImage.FileName(), "Error, can't read scanline {0}", row);
return false;
}
int inp = 0;
int outp = s;
for (int n = imagewidth; n-- > 0; )
{
outbuf[outp] = inbuf[inp];
inp++;
outp += spp;
}
}
if (!outImage.WriteScanline(outbuf, row, 0))
{
Tiff.Error(outImage.FileName(), "Error, can't write scanline {0}", row);
return false;
}
}
return true;
}
示例5: cvt_whole_image
/// <summary>
/// Read the whole image into one big RGBA buffer and then write out
/// strips from that. This is using the traditional TIFFReadRGBAImage()
/// API that we trust.
/// </summary>
private bool cvt_whole_image(Tiff inImage, Tiff outImage, int width, int height)
{
int pixel_count = width * height;
/* XXX: Check the integer overflow. */
if (width == 0 || height == 0 || (pixel_count / width) != height)
{
Tiff.Error(inImage.FileName(),
"Malformed input file; can't allocate buffer for raster of {0}x{1} size",
width, height);
return false;
}
m_rowsPerStrip = outImage.DefaultStripSize(m_rowsPerStrip);
outImage.SetField(TiffTag.ROWSPERSTRIP, m_rowsPerStrip);
int[] raster = new int[pixel_count];
/* Read the image in one chunk into an RGBA array */
if (!inImage.ReadRGBAImageOriented(width, height, raster, Orientation.TOPLEFT, false))
return false;
/*
* Do we want to strip away alpha components?
*/
byte[] rasterBytes;
int rasterByteSize;
if (m_noAlpha)
{
rasterByteSize = pixel_count * 3;
rasterBytes = new byte[rasterByteSize];
for (int i = 0, rasterBytesPos = 0; i < pixel_count; i++)
{
byte[] bytes = BitConverter.GetBytes(raster[i]);
rasterBytes[rasterBytesPos++] = bytes[0];
rasterBytes[rasterBytesPos++] = bytes[1];
rasterBytes[rasterBytesPos++] = bytes[2];
}
}
else
{
rasterByteSize = pixel_count * 4;
rasterBytes = new byte[rasterByteSize];
Buffer.BlockCopy(raster, 0, rasterBytes, 0, rasterByteSize);
}
/*
* Write out the result in strips
*/
for (int row = 0; row < height; row += m_rowsPerStrip)
{
int bytes_per_pixel;
if (m_noAlpha)
bytes_per_pixel = 3;
else
bytes_per_pixel = 4;
int rows_to_write;
if (row + m_rowsPerStrip > height)
rows_to_write = height - row;
else
rows_to_write = m_rowsPerStrip;
int offset = bytes_per_pixel * row * width;
int count = bytes_per_pixel * rows_to_write * width;
if (outImage.WriteEncodedStrip(row / m_rowsPerStrip, rasterBytes, offset, count) == -1)
return false;
}
return true;
}
示例6: pickFuncAndCopy
/*
* Select the appropriate copy function to use.
*/
bool pickFuncAndCopy(Tiff inImage, Tiff outImage, short bitspersample, short samplesperpixel, int length, int width)
{
using (TextWriter stderr = Console.Error)
{
FieldValue[] result = inImage.GetField(TiffTag.PLANARCONFIG);
PlanarConfig shortv = (PlanarConfig)result[0].ToShort();
if (shortv != m_config && bitspersample != 8 && samplesperpixel > 1)
{
stderr.Write("{0}: Cannot handle different planar configuration w/ bits/sample != 8\n", inImage.FileName());
return false;
}
result = inImage.GetField(TiffTag.IMAGEWIDTH);
int w = result[0].ToInt();
result = inImage.GetField(TiffTag.IMAGELENGTH);
int l = result[0].ToInt();
bool bychunk;
if (!(outImage.IsTiled() || inImage.IsTiled()))
{
result = inImage.GetField(TiffTag.ROWSPERSTRIP);
if (result != null)
{
int irps = result[0].ToInt();
/* if biased, force decoded copying to allow image subtraction */
bychunk = (m_bias == null) && (m_rowsperstrip == irps);
}
else
bychunk = false;
}
else
{
/* either inImage or outImage is tiled */
if (m_bias != null)
{
stderr.Write("{0}: Cannot handle tiled configuration w/bias image\n", inImage.FileName());
return false;
}
if (outImage.IsTiled())
{
int tw;
result = inImage.GetField(TiffTag.TILEWIDTH);
if (result == null)
tw = w;
else
tw = result[0].ToInt();
int tl;
result = inImage.GetField(TiffTag.TILELENGTH);
if (result == null)
tl = l;
else
tl = result[0].ToInt();
bychunk = (tw == m_tilewidth && tl == m_tilelength);
}
else
{
/* outImage's not, so inImage must be tiled */
result = inImage.GetField(TiffTag.TILEWIDTH);
int tw = result[0].ToInt();
result = inImage.GetField(TiffTag.TILELENGTH);
int tl = result[0].ToInt();
bychunk = (tw == w && tl == m_rowsperstrip);
}
}
if (inImage.IsTiled())
{
if (outImage.IsTiled())
{
/* Tiles -> Tiles */
if (shortv == PlanarConfig.CONTIG && m_config == PlanarConfig.CONTIG)
return cpContigTiles2ContigTiles(inImage, outImage, length, width, samplesperpixel);
else if (shortv == PlanarConfig.CONTIG && m_config == PlanarConfig.SEPARATE)
return cpContigTiles2SeparateTiles(inImage, outImage, length, width, samplesperpixel);
else if (shortv == PlanarConfig.SEPARATE && m_config == PlanarConfig.CONTIG)
return cpSeparateTiles2ContigTiles(inImage, outImage, length, width, samplesperpixel);
else if (shortv == PlanarConfig.SEPARATE && m_config == PlanarConfig.SEPARATE)
return cpSeparateTiles2SeparateTiles(inImage, outImage, length, width, samplesperpixel);
}
else
{
/* Tiles -> Strips */
if (shortv == PlanarConfig.CONTIG && m_config == PlanarConfig.CONTIG)
return cpContigTiles2ContigStrips(inImage, outImage, length, width, samplesperpixel);
else if (shortv == PlanarConfig.CONTIG && m_config == PlanarConfig.SEPARATE)
return cpContigTiles2SeparateStrips(inImage, outImage, length, width, samplesperpixel);
else if (shortv == PlanarConfig.SEPARATE && m_config == PlanarConfig.CONTIG)
return cpSeparateTiles2ContigStrips(inImage, outImage, length, width, samplesperpixel);
else if (shortv == PlanarConfig.SEPARATE && m_config == PlanarConfig.SEPARATE)
//.........这里部分代码省略.........
示例7: cpDecodedStrips
/*
* Strip -> strip for change in encoding.
*/
bool cpDecodedStrips(Tiff inImage, Tiff outImage, int imagelength, int imagewidth, short spp)
{
int stripsize = inImage.StripSize();
byte[] buf = new byte[stripsize];
int ns = inImage.NumberOfStrips();
int row = 0;
for (int s = 0; s < ns; s++)
{
int cc = (row + m_rowsperstrip > imagelength) ? inImage.VStripSize(imagelength - row) : stripsize;
if (inImage.ReadEncodedStrip(s, buf, 0, cc) < 0 && !m_ignore)
{
Tiff.Error(inImage.FileName(), "Error, can't read strip {0}", s);
return false;
}
if (outImage.WriteEncodedStrip(s, buf, cc) < 0)
{
Tiff.Error(outImage.FileName(), "Error, can't write strip {0}", s);
return false;
}
row += m_rowsperstrip;
}
return true;
}
示例8: read_tiff_data
/*
This function sets the input directory to the directory of a given
page and determines information about the image. It checks
the image characteristics to determine if it is possible to convert
the image data into a page of PDF output, setting values of the T2P
struct for this page. It determines what color space is used in
the output PDF to represent the image.
It determines if the image can be converted as raw data without
requiring transcoding of the image data.
*/
private void read_tiff_data(Tiff input)
{
m_pdf_transcode = t2p_transcode_t.T2P_TRANSCODE_ENCODE;
m_pdf_sample = t2p_sample_t.T2P_SAMPLE_NOTHING;
m_pdf_switchdecode = m_pdf_colorspace_invert;
input.SetDirectory(m_tiff_pages[m_pdf_page].page_directory);
FieldValue[] result = input.GetField(TiffTag.IMAGEWIDTH);
m_tiff_width = result[0].ToInt();
if (m_tiff_width == 0)
{
Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE, "No support for {0} with zero width", input.FileName());
m_error = true;
return;
}
result = input.GetField(TiffTag.IMAGELENGTH);
m_tiff_length = result[0].ToInt();
if (m_tiff_length == 0)
{
Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE,
"No support for {0} with zero length", input.FileName());
m_error = true;
return;
}
result = input.GetField(TiffTag.COMPRESSION);
if (result == null)
{
Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE,
"No support for {0} with no compression tag", input.FileName());
m_error = true;
return;
}
else
m_tiff_compression = (Compression)result[0].ToInt();
if (!input.IsCodecConfigured(m_tiff_compression))
{
Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE,
"No support for {0} with compression type {1}: not configured",
input.FileName(), m_tiff_compression);
m_error = true;
return;
}
result = input.GetFieldDefaulted(TiffTag.BITSPERSAMPLE);
m_tiff_bitspersample = result[0].ToShort();
switch (m_tiff_bitspersample)
{
case 1:
case 2:
case 4:
case 8:
break;
case 0:
Tiff.Warning(Tiff2PdfConstants.TIFF2PDF_MODULE,
"Image {0} has 0 bits per sample, assuming 1", input.FileName());
m_tiff_bitspersample = 1;
break;
default:
Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE,
"No support for {0} with {1} bits per sample",
input.FileName(), m_tiff_bitspersample);
m_error = true;
return;
}
result = input.GetFieldDefaulted(TiffTag.SAMPLESPERPIXEL);
m_tiff_samplesperpixel = result[0].ToShort();
if (m_tiff_samplesperpixel > 4)
{
Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE,
"No support for {0} with {1} samples per pixel", input.FileName(), m_tiff_samplesperpixel);
m_error = true;
return;
}
if (m_tiff_samplesperpixel == 0)
{
Tiff.Warning(Tiff2PdfConstants.TIFF2PDF_MODULE,
"Image {0} has 0 samples per pixel, assuming 1", input.FileName());
m_tiff_samplesperpixel = 1;
}
result = input.GetField(TiffTag.SAMPLEFORMAT);
//.........这里部分代码省略.........
示例9: readContigStripsIntoBuffer
bool readContigStripsIntoBuffer(Tiff inImage, byte[] buffer, int imagelength, int imagewidth, short spp)
{
int scanlinesize = inImage.ScanlineSize();
int offset = 0;
for (int row = 0; row < imagelength; row++)
{
if (!inImage.ReadScanline(buffer, offset, row, 0) && !m_ignore)
{
Tiff.Error(inImage.FileName(), "Error, can't read scanline {0}", row);
return false;
}
offset += scanlinesize;
}
return true;
}
示例10: readwrite_pdf_image_tile
/*
* This function reads the raster image data from the input TIFF for an image
* tile and writes the data to the output PDF XObject image dictionary stream
* for the tile. It returns the amount written or zero on error.
*/
private int readwrite_pdf_image_tile(Tiff input, int tile)
{
bool edge = false;
edge |= tile_is_right_edge(m_tiff_pages[m_pdf_page], tile);
edge |= tile_is_bottom_edge(m_tiff_pages[m_pdf_page], tile);
byte[] buffer = null;
int bufferoffset = 0;
FieldValue[] result = null;
if ((m_pdf_transcode == t2p_transcode_t.T2P_TRANSCODE_RAW) && (!edge || (m_pdf_compression == t2p_compress_t.T2P_COMPRESS_JPEG)))
{
if (m_pdf_compression == t2p_compress_t.T2P_COMPRESS_G4)
{
buffer = new byte [m_tiff_datasize];
input.ReadRawTile(tile, buffer, 0, m_tiff_datasize);
if (m_tiff_fillorder == FillOrder.LSB2MSB)
Tiff.ReverseBits(buffer, m_tiff_datasize);
writeToFile(buffer, m_tiff_datasize);
return m_tiff_datasize;
}
if (m_pdf_compression == t2p_compress_t.T2P_COMPRESS_ZIP)
{
buffer = new byte [m_tiff_datasize];
input.ReadRawTile(tile, buffer, 0, m_tiff_datasize);
if (m_tiff_fillorder == FillOrder.LSB2MSB)
Tiff.ReverseBits(buffer, m_tiff_datasize);
writeToFile(buffer, m_tiff_datasize);
return m_tiff_datasize;
}
if (m_tiff_compression == Compression.JPEG)
{
byte[] table_end = new byte[2];
buffer = new byte [m_tiff_datasize];
result = input.GetField(TiffTag.JPEGTABLES);
if (result != null)
{
int count = result[0].ToInt();
byte[] jpt = result[1].ToByteArray();
if (count > 0)
{
Buffer.BlockCopy(jpt, 0, buffer, 0, count);
bufferoffset += count - 2;
table_end[0] = buffer[bufferoffset - 2];
table_end[1] = buffer[bufferoffset - 1];
}
if (count > 0)
{
int xuint32 = bufferoffset;
bufferoffset += input.ReadRawTile(tile, buffer, bufferoffset - 2, -1);
buffer[xuint32 - 2] = table_end[0];
buffer[xuint32 - 1] = table_end[1];
}
else
{
bufferoffset += input.ReadRawTile(tile, buffer, bufferoffset, -1);
}
}
writeToFile(buffer, bufferoffset);
return bufferoffset;
}
}
if (m_pdf_sample == t2p_sample_t.T2P_SAMPLE_NOTHING)
{
buffer = new byte [m_tiff_datasize];
int read = input.ReadEncodedTile(tile, buffer, bufferoffset, m_tiff_datasize);
if (read == -1)
{
Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE,
"Error on decoding tile {0} of {1}", tile, input.FileName());
m_error = true;
return 0;
}
}
else
{
if (m_pdf_sample == t2p_sample_t.T2P_SAMPLE_PLANAR_SEPARATE_TO_CONTIG)
{
int septilesize = input.TileSize();
int septilecount = input.NumberOfTiles();
int tilecount = septilecount / m_tiff_samplesperpixel;
buffer = new byte [m_tiff_datasize];
byte[] samplebuffer = new byte [m_tiff_datasize];
int samplebufferoffset = 0;
for (short i = 0; i < m_tiff_samplesperpixel; i++)
{
int read = input.ReadEncodedTile(tile + i * tilecount, samplebuffer, samplebufferoffset, septilesize);
if (read == -1)
//.........这里部分代码省略.........
示例11: read_tiff_init
/*
This function scans the input TIFF file for pages. It attempts
to determine which IFD's of the TIFF file contain image document
pages. For each, it gathers some information that has to do
with the output of the PDF document as a whole.
*/
private void read_tiff_init(Tiff input)
{
short directorycount = input.NumberOfDirectories();
m_tiff_pages = new T2P_PAGE [directorycount];
for (int p = 0; p < directorycount; p++)
m_tiff_pages[p] = new T2P_PAGE();
FieldValue[] result = null;
for (short i = 0; i < directorycount; i++)
{
int subfiletype = 0;
if (!input.SetDirectory(i))
{
Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE,
"Can't set directory {0} of input file {1}", i, input.FileName());
return;
}
result = input.GetField(TiffTag.PAGENUMBER);
if (result != null)
{
short pagen = result[0].ToShort();
short paged = result[1].ToShort();
if ((pagen > paged) && (paged != 0))
m_tiff_pages[m_tiff_pagecount].page_number = paged;
else
m_tiff_pages[m_tiff_pagecount].page_number = pagen;
}
else
{
result = input.GetField(TiffTag.SUBFILETYPE);
if (result != null)
{
subfiletype = result[0].ToInt();
if ((((FileType)subfiletype & FileType.PAGE) == 0) && (subfiletype != 0))
continue;
}
else
{
result = input.GetField(TiffTag.OSUBFILETYPE);
if (result != null)
{
subfiletype = result[0].ToInt();
if (((OFileType)subfiletype != OFileType.IMAGE) && ((OFileType)subfiletype != OFileType.PAGE) && (subfiletype != 0))
continue;
}
}
m_tiff_pages[m_tiff_pagecount].page_number = m_tiff_pagecount;
}
m_tiff_pages[m_tiff_pagecount].page_directory = i;
if (input.IsTiled())
m_tiff_pages[m_tiff_pagecount].page_tilecount = input.NumberOfTiles();
m_tiff_pagecount++;
}
IComparer myComparer = new cmp_t2p_page();
Array.Sort(m_tiff_pages, myComparer);
for (short i = 0; i < m_tiff_pagecount; i++)
{
m_pdf_xrefcount += 5;
input.SetDirectory(m_tiff_pages[i].page_directory);
result = input.GetField(TiffTag.PHOTOMETRIC);
if ((result != null && ((Photometric)result[0].ToInt() == Photometric.PALETTE)) || input.GetField(TiffTag.INDEXED) != null)
{
m_tiff_pages[i].page_extra++;
m_pdf_xrefcount++;
}
result = input.GetField(TiffTag.COMPRESSION);
if (result != null)
{
Compression xuint16 = (Compression)result[0].ToInt();
if ((xuint16 == Compression.DEFLATE || xuint16 == Compression.ADOBE_DEFLATE)
&& ((m_tiff_pages[i].page_tilecount != 0) || input.NumberOfStrips() == 1)
&& !m_pdf_nopassthrough)
{
if (m_pdf_minorversion < 2)
m_pdf_minorversion = 2;
}
}
result = input.GetField(TiffTag.TRANSFERFUNCTION);
if (result != null)
{
m_tiff_transferfunction[0] = result[0].GetBytes();
//.........这里部分代码省略.........
示例12: readwrite_pdf_image
/*
This function reads the raster image data from the input TIFF for an image and writes
the data to the output PDF XObject image dictionary stream. It returns the amount written
or zero on error.
*/
private int readwrite_pdf_image(Tiff input)
{
byte[] buffer = null;
int bufferoffset = 0;
int stripcount = 0;
int max_striplength = 0;
FieldValue[] result = null;
if (m_pdf_transcode == t2p_transcode_t.T2P_TRANSCODE_RAW)
{
if (m_pdf_compression == t2p_compress_t.T2P_COMPRESS_G4)
{
buffer = new byte [m_tiff_datasize];
input.ReadRawStrip(0, buffer, 0, m_tiff_datasize);
if (m_tiff_fillorder == FillOrder.LSB2MSB)
{
/*
* make sure is lsb-to-msb
* bit-endianness fill order
*/
Tiff.ReverseBits(buffer, m_tiff_datasize);
}
writeToFile(buffer, m_tiff_datasize);
return m_tiff_datasize;
}
if (m_pdf_compression == t2p_compress_t.T2P_COMPRESS_ZIP)
{
buffer = new byte [m_tiff_datasize];
input.ReadRawStrip(0, buffer, 0, m_tiff_datasize);
if (m_tiff_fillorder == FillOrder.LSB2MSB)
Tiff.ReverseBits(buffer, m_tiff_datasize);
writeToFile(buffer, m_tiff_datasize);
return m_tiff_datasize;
}
if (m_tiff_compression == Compression.JPEG)
{
buffer = new byte [m_tiff_datasize];
result = input.GetField(TiffTag.JPEGTABLES);
if (result != null)
{
int count = result[0].ToInt();
byte[] jpt = result[1].ToByteArray();
if (count > 4)
{
Buffer.BlockCopy(jpt, 0, buffer, 0, count);
bufferoffset += count - 2;
}
}
stripcount = input.NumberOfStrips();
result = input.GetField(TiffTag.STRIPBYTECOUNTS);
int[] sbc = result[0].ToIntArray();
for (int i = 0; i < stripcount; i++)
{
if (sbc[i] > max_striplength)
max_striplength = sbc[i];
}
byte[] stripbuffer = new byte [max_striplength];
for (int i = 0; i < stripcount; i++)
{
int striplength = input.ReadRawStrip(i, stripbuffer, 0, -1);
if (!process_jpeg_strip(stripbuffer, striplength, buffer, ref bufferoffset, stripcount, i, m_tiff_length))
{
Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE,
"Can't process JPEG data in input file {0}", input.FileName());
m_error = true;
return 0;
}
}
buffer[bufferoffset++] = 0xff;
buffer[bufferoffset++] = 0xd9;
writeToFile(buffer, bufferoffset);
return bufferoffset;
}
}
int stripsize = 0;
if (m_pdf_sample == t2p_sample_t.T2P_SAMPLE_NOTHING)
{
buffer = new byte [m_tiff_datasize];
stripsize = input.StripSize();
stripcount = input.NumberOfStrips();
for (int i = 0; i < stripcount; i++)
{
int read = input.ReadEncodedStrip(i, buffer, bufferoffset, stripsize);
if (read == -1)
{
Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE,
"Error on decoding strip {0} of {1}", i, input.FileName());
//.........这里部分代码省略.........
示例13: read_tiff_size
/*
This function returns the necessary size of a data buffer to contain the raw or
uncompressed image data from the input TIFF for a page.
*/
private void read_tiff_size(Tiff input)
{
if (m_pdf_transcode == t2p_transcode_t.T2P_TRANSCODE_RAW)
{
FieldValue[] result = null;
if (m_pdf_compression == t2p_compress_t.T2P_COMPRESS_G4)
{
result = input.GetField(TiffTag.STRIPBYTECOUNTS);
int[] sbc = result[0].ToIntArray();
m_tiff_datasize = sbc[0];
return;
}
if (m_pdf_compression == t2p_compress_t.T2P_COMPRESS_ZIP)
{
result = input.GetField(TiffTag.STRIPBYTECOUNTS);
int[] sbc = result[0].ToIntArray();
m_tiff_datasize = sbc[0];
return;
}
if (m_tiff_compression == Compression.JPEG)
{
result = input.GetField(TiffTag.JPEGTABLES);
if (result != null)
{
int count = result[0].ToInt();
if (count > 4)
{
m_tiff_datasize += count;
m_tiff_datasize -= 2; /* don't use EOI of header */
}
}
else
{
m_tiff_datasize = 2; /* SOI for first strip */
}
int stripcount = input.NumberOfStrips();
int[] sbc = null;
result = input.GetField(TiffTag.STRIPBYTECOUNTS);
if (result == null)
{
Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE,
"Input file {0} missing field: STRIPBYTECOUNTS",
input.FileName());
m_error = true;
return;
}
else
sbc = result[0].ToIntArray();
for (int i = 0; i < stripcount; i++)
{
m_tiff_datasize += sbc[i];
m_tiff_datasize -= 4; /* don't use SOI or EOI of strip */
}
m_tiff_datasize += 2; /* use EOI of last strip */
return;
}
}
m_tiff_datasize = input.ScanlineSize() * m_tiff_length;
if (m_tiff_planar == PlanarConfig.SEPARATE)
m_tiff_datasize *= m_tiff_samplesperpixel;
}
示例14: cvt_by_tile
static bool cvt_by_tile(Tiff inImage, Tiff outImage, int width, int height)
{
int tile_width = 0;
int tile_height = 0;
FieldValue[] result = inImage.GetField(TiffTag.TILEWIDTH);
if (result != null)
{
tile_width = result[0].ToInt();
result = inImage.GetField(TiffTag.TILELENGTH);
if (result != null)
tile_height = result[0].ToInt();
}
if (result == null)
{
Tiff.Error(inImage.FileName(), "Source image not tiled");
return false;
}
outImage.SetField(TiffTag.TILEWIDTH, tile_width);
outImage.SetField(TiffTag.TILELENGTH, tile_height);
// Allocate tile buffer
int raster_size = multiply(tile_width, tile_height);
int rasterByteSize = multiply(raster_size, sizeof(int));
if (raster_size == 0 || rasterByteSize == 0)
{
Tiff.Error(inImage.FileName(),
"Can't allocate buffer for raster of size {0}x{1}", tile_width, tile_height);
return false;
}
int[] raster = new int[raster_size];
byte[] rasterBytes = new byte[rasterByteSize];
// Allocate a scanline buffer for swapping during the vertical mirroring pass.
// (Request can't overflow given prior checks.)
int[] wrk_line = new int[tile_width];
// Loop over the tiles.
for (int row = 0; row < height; row += tile_height)
{
for (int col = 0; col < width; col += tile_width)
{
// Read the tile into an RGBA array
if (!inImage.ReadRGBATile(col, row, raster))
return false;
// For some reason the ReadRGBATile() function chooses the lower left corner
// as the origin. Vertically mirror scanlines.
for (int i_row = 0; i_row < tile_height / 2; i_row++)
{
int topIndex = tile_width * i_row * sizeof(int);
int bottomIndex = tile_width * (tile_height - i_row - 1) * sizeof(int);
Buffer.BlockCopy(raster, topIndex, wrk_line, 0, tile_width * sizeof(int));
Buffer.BlockCopy(raster, bottomIndex, raster, topIndex, tile_width * sizeof(int));
Buffer.BlockCopy(wrk_line, 0, raster, bottomIndex, tile_width * sizeof(int));
}
// Write out the result in a tile.
int tile = outImage.ComputeTile(col, row, 0, 0);
Buffer.BlockCopy(raster, 0, rasterBytes, 0, rasterByteSize);
if (outImage.WriteEncodedTile(tile, rasterBytes, rasterByteSize) == -1)
return false;
}
}
return true;
}
示例15: copyTag
private static void copyTag(Tiff inImage, Tiff outImage, TiffTag tag, short count, TiffType type)
{
FieldValue[] result = null;
switch (type)
{
case TiffType.SHORT:
result = inImage.GetField(tag);
if (result != null)
{
if (count == 1)
outImage.SetField(tag, result[0]);
else if (count == 2)
outImage.SetField(tag, result[0], result[1]);
else if (count == 4)
outImage.SetField(tag, result[0], result[1], result[2]);
else if (count == -1)
outImage.SetField(tag, result[0], result[1]);
}
break;
case TiffType.LONG:
result = inImage.GetField(tag);
if (result != null)
outImage.SetField(tag, result[0]);
break;
case TiffType.RATIONAL:
result = inImage.GetField(tag);
if (result != null)
outImage.SetField(tag, result[0]);
break;
case TiffType.ASCII:
result = inImage.GetField(tag);
if (result != null)
outImage.SetField(tag, result[0]);
break;
case TiffType.DOUBLE:
result = inImage.GetField(tag);
if (result != null)
outImage.SetField(tag, result[0]);
break;
default:
Tiff.Error(inImage.FileName(),
"Data type {0} is not supported, tag {1} skipped.", tag, type);
break;
}
}