// Write to memory /// <summary> /// (1) On windows, this will only write tiff and PostScript to memory. /// For other formats, it requires open_memstream(3). /// (2) PostScript output is uncompressed, in hex ascii. /// Most printers support level 2 compression (tiff_g4 for 1 bpp, /// jpeg for 8 and 32 bpp). /// </summary> /// <param name="pdata">data of tiff compressed image</param> /// <param name="psize">size of returned data</param> /// <param name="pix"></param> /// <param name="format">defined in imageio.h</param> /// <returns>false if OK, true on error</returns> public static bool pixWriteMem(out IntPtr pdata, out IntPtr psize, Pix pix, ImageFileFormatTypes format) { if (null == pix) { throw new ArgumentNullException("pix cannot be null."); } return(Native.DllImports.pixWriteMem(out pdata, out psize, (HandleRef)pix, format)); }
public static bool pixDisplayWriteFormat(this Pix pixs, int reduction, ImageFileFormatTypes format) { if (null == pixs) { throw new ArgumentNullException("pixs cannot be null."); } return(Native.DllImports.pixDisplayWriteFormat((HandleRef)pixs, reduction, format)); }
/// <summary> /// (1) The output formats are restricted to tiff, jpeg and png /// because these are the most commonly used image formats and /// the ones that are typically installed with leptonica. /// (2) This decides what compression to use based on the pix. /// It chooses tiff-g4 if 1 bpp without a colormap, jpeg with /// quality 75 if grayscale, rgb or rgba (where it loses /// the alpha layer), and lossless png for all other situations. /// </summary> /// <param name="pix"></param> /// <param name="pformat"></param> /// <returns>false if OK, true on error</returns> public static bool pixGetAutoFormat(this Pix pix, out ImageFileFormatTypes pformat) { if (null == pix) { throw new ArgumentNullException("pix cannot be null."); } return(Native.DllImports.pixGetAutoFormat((HandleRef)pix, out pformat)); }
/// <summary> /// /// </summary> /// <param name="pix"></param> /// <param name="informat"></param> /// <returns>false if OK, true on error</returns> public static bool pixSetInputFormat(this Pix pix, ImageFileFormatTypes informat) { if (null == pix) { throw new ArgumentNullException("pix cannot be null"); } return(Native.DllImports.pixSetInputFormat((HandleRef)pix, informat)); }
/// <summary> /// (1) This determines the file format from the first 12 bytes in /// the compressed data stream, which are stored in memory. /// (2) For tiff files, this returns IFF_TIFF.The specific tiff /// compression is then determined using findTiffCompression(). /// </summary> /// <param name="buf">byte buffer at least 12 bytes in size; we can't check</param> /// <param name="pformat">found format</param> /// <returns>false if OK, true on error or if format is not recognized</returns> public static bool findFileFormatBuffer(IntPtr buf, out ImageFileFormatTypes pformat) { if (IntPtr.Zero == buf) { throw new ArgumentNullException("buf cannot be null."); } return(Native.DllImports.findFileFormatBuffer(buf, out pformat)); }
/// <summary> /// Important: Side effect -- this resets fp to BOF. /// </summary> /// <param name="fp"></param> /// <param name="pformat"></param> /// <returns>false if OK, true on error or if format is not recognized</returns> public static bool findFileFormatStream(IntPtr fp, out ImageFileFormatTypes pformat) { if (IntPtr.Zero == fp) { throw new ArgumentNullException("fp cannot be null."); } return(Native.DllImports.findFileFormatStream(fp, out pformat)); }
/// <summary> /// /// </summary> /// <param name="fp"></param> /// <param name="pix"></param> /// <param name="format"></param> /// <returns>false if OK; true on error</returns> public static bool pixWriteStream(IntPtr fp, Pix pix, ImageFileFormatTypes format) { if (null == pix || IntPtr.Zero == fp) { throw new ArgumentNullException("pix, fp cannot be null."); } return(Native.DllImports.pixWriteStream(fp, (HandleRef)pix, format)); }
/// <summary> /// (1) Open for write using binary mode (with the "b" flag) /// to avoid having Windows automatically translate the NL /// into CRLF, which corrupts image files. On non-windows /// systems this flag should be ignored, per ISO C90. /// Thanks to Dave Bryan for pointing this out. /// (2) If the default image format IFF_DEFAULT is requested: /// use the input format if known; otherwise, use a lossless format. /// (3) There are two modes with respect to file naming. /// (a) The default code writes to %fname. /// (b) If WRITE_AS_NAMED is defined to 0, it's a bit fancier. /// Then, if %fname does not have a file extension, one is /// automatically appended, depending on the requested format. /// The original intent for providing option (b) was to insure /// that filenames on Windows have an extension that matches /// the image compression. However, this is not the default. /// </summary> /// <param name="fname"></param> /// <param name="pix"></param> /// <param name="format">defined in imageio.h</param> /// <returns>false if OK; true on error</returns> public static bool pixWrite(string fname, Pix pix, ImageFileFormatTypes format) { if (null == pix || string.IsNullOrWhiteSpace(fname)) { throw new ArgumentNullException("pix, fname cannot be null."); } return(Native.DllImports.pixWrite(fname, (HandleRef)pix, format)); }
/// <summary> /// (1) This reads the actual headers for jpeg, png, tiff, jp2k and pnm. /// For bmp and gif, we cheat and read all the data into a pix, /// from which we extract the "header" information. /// (2) The amount of data required depends on the format.For /// png, it requires less than 30 bytes, but for jpeg it can /// require most of the compressed file.In practice, the data /// is typically the entire compressed file in memory. /// (3) findFileFormatBuffer() requires up to 8 bytes to decide on /// the format, which we require. /// </summary> /// <param name="data">const; encoded</param> /// <param name="size">size of data</param> /// <param name="pformat">image format</param> /// <param name="pw"></param> /// <param name="ph"></param> /// <param name="pbps"></param> /// <param name="pspp"></param> /// <param name="piscmap"></param> /// <returns>false if OK, true on error</returns> public static bool pixReadHeaderMem(IntPtr data, IntPtr size, out ImageFileFormatTypes pformat, out int pw, out int ph, out int pbps, out int pspp, out bool piscmap) { if (IntPtr.Zero == data || IntPtr.Zero == size) { throw new ArgumentNullException("data, size cannot be null."); } return(Native.DllImports.pixReadHeaderMem(data, size, out pformat, out pw, out ph, out pbps, out pspp, out piscmap)); }
// Format finders /// <summary> /// /// </summary> /// <param name="filename"></param> /// <param name="pformat">found format</param> /// <returns>false if OK, true on error or if format is not recognized</returns> public static bool findFileFormat(string filename, out ImageFileFormatTypes pformat) { if (string.IsNullOrEmpty(filename)) { throw new ArgumentNullException("filename cannot be null."); } if (!System.IO.File.Exists(filename)) { throw new System.IO.FileNotFoundException("filename does not exist"); } return(Native.DllImports.findFileFormat(filename, out pformat)); }
// Read header information from file /// <summary> /// This reads the actual headers for jpeg, png, tiff and pnm. /// For bmp and gif, we cheat and read the entire file into a pix, from which we extract the "header" information. /// </summary> /// <param name="filename">filename with full pathname or in local directory</param> /// <param name="pformat">file format</param> /// <param name="pw"></param> /// <param name="ph"></param> /// <param name="pbps">bits/sample</param> /// <param name="pspp">samples/pixel 1, 3 or 4</param> /// <param name="piscmap">1 if cmap exists; 0 otherwise</param> /// <returns>false if OK, true on error</returns> public static bool pixReadHeader(string filename, out ImageFileFormatTypes pformat, out int pw, out int ph, out int pbps, out int pspp, out bool piscmap) { if (string.IsNullOrEmpty(filename)) { throw new ArgumentNullException("filename cannot be null."); } if (!System.IO.File.Exists(filename)) { throw new System.IO.FileNotFoundException("filename does not exist"); } return(Native.DllImports.pixReadHeader(filename, out pformat, out pw, out ph, out pbps, out pspp, out piscmap)); }
// High-level procedures for writing images to file: /// <summary> /// Use %format = IFF_DEFAULT to decide the output format individually for each pix. /// </summary> /// <param name="rootname"></param> /// <param name="pixa"></param> /// <param name="format">defined in imageio.h; see notes for default</param> /// <returns>false if OK; true on error</returns> public static bool pixaWriteFiles(string rootname, Pixa pixa, ImageFileFormatTypes format) { if (null == pixa || string.IsNullOrWhiteSpace(rootname)) { throw new ArgumentNullException("pixa, rootname cannot be null."); } if (!System.IO.Directory.Exists(rootname)) { throw new System.IO.DirectoryNotFoundException("rootname does not exist"); } return(Native.DllImports.pixaWriteFiles(rootname, (HandleRef)pixa, format)); }
public bool Write(string filename, ImageFileFormatTypes format) { return(WriteFile.pixWrite(filename, this, format)); }
/// <summary> /// This string is NOT owned by the caller; it is just a pointer to a global string. Do not free it. /// </summary> /// <param name="format"></param> /// <returns>extension string, or NULL if format is out of range</returns> public static string getFormatExtension(ImageFileFormatTypes format) { var pointer = Native.DllImports.getFormatExtension(format); return(Marshal.PtrToStringAnsi(pointer)); }
public static IntPtr regTestGenLocalFilename(this L_RegParams rp, int index, ImageFileFormatTypes format) { throw new NotImplementedException(); }
public static int regTestWritePixAndCheck(this L_RegParams rp, Pix pix, ImageFileFormatTypes format) { return(Native.DllImports.regTestWritePixAndCheck((HandleRef)rp, (HandleRef)pix, (int)format)); }