internal DirectoryEntry(byte[] bytes) { Inode = BitConverter.ToUInt32(bytes, 0x00); RecordLength = BitConverter.ToUInt16(bytes, 0x04); NameLength = bytes[0x06]; FileType = (FILE_TYPE)bytes[0x07]; Name = Encoding.ASCII.GetString(bytes, 0x08, NameLength); }
private void LoadAttachFile(GridView gridview) { this.splashScreenManager1.ShowWaitForm(); string file_name = gridview == this.gridViewSlip ? this.selected_slip : this.selected_tax; string file_folder = gridview == this.gridViewSlip ? "Slip/" : "Tax/"; string file_url = this.main_form.config.ApiUrl.Replace("/Api/", "") + "/Images/" + file_folder + file_name; this.current_file_type = Path.GetExtension(file_name) == ".pdf" ? FILE_TYPE.PDF : FILE_TYPE.IMAGE; this.pictureEdit1.Image = null; if (APIClient.CheckUrlFileExist(file_url)) { if (Path.GetExtension(file_name) == ".pdf") { using (WebClient client = new WebClient()) { using (MemoryStream ms = new MemoryStream(client.DownloadData(file_url))) { pdfViewer1.LoadDocument(ms); this.pdfViewer1.BringToFront(); this.pictureEdit1.SendToBack(); } } } else { this.pdfViewer1.CloseDocument(); this.pictureEdit1.BringToFront(); this.pdfViewer1.SendToBack(); this.pictureEdit1.LoadAsync(file_url); this.pictureEdit1.Tag = file_name; } } else { this.pdfViewer1.SendToBack(); this.pictureEdit1.BringToFront(); //this.pictureEdit1.Image = SoImporter.Properties.Resources.NO_PICTURE; //this.pictureEdit1.Image = null; this.pictureEdit1.Tag = ""; } this.splashScreenManager1.CloseWaitForm(); }
public void Read(BinaryReader R) { m_fileName = new FileInfo(R.ReadString()); m_timeStamp = DateTime.FromBinary(R.ReadInt64()); m_fileType = (FILE_TYPE)R.ReadInt32(); if (m_fileType > FILE_TYPE.BIMAGE) { throw new Exception("Corrupted image file!"); } m_width = R.ReadInt32(); m_height = R.ReadInt32(); m_couldBeRead = R.ReadBoolean(); string errorText = R.ReadString(); m_error = errorText != string.Empty ? new Exception(errorText) : null; m_usage = FindUsage(m_fileName); // Attempt to find usage again }
/// <summary> /// Reads image size and other informations, doesn't read content /// </summary> public void ReadImageInfos() { m_usage = FindUsage(m_fileName); if (m_fileName.Extension.ToLower().StartsWith(".bimage")) { // Can't read! m_fileType = FILE_TYPE.BIMAGE; m_couldBeRead = false; return; } try { using (ImageUtility.Bitmap B = new ImageUtility.Bitmap(m_fileName)) { m_error = null; m_couldBeRead = true; m_width = B.Width; m_height = B.Height; switch (B.Type) { case ImageUtility.Bitmap.FILE_TYPE.PNG: m_fileType = FILE_TYPE.PNG; break; case ImageUtility.Bitmap.FILE_TYPE.TGA: m_fileType = FILE_TYPE.TGA; break; // case ImageUtility.Bitmap.FILE_TYPE.DDS: m_fileType = FILE_TYPE.DDS; break; // DDS not supported? case ImageUtility.Bitmap.FILE_TYPE.JPEG: m_fileType = FILE_TYPE.JPG; break; case ImageUtility.Bitmap.FILE_TYPE.TIFF: m_fileType = FILE_TYPE.TIFF; break; } } } catch (Exception _e) { m_couldBeRead = false; m_error = _e; throw _e; } }
/// <summary> /// Actual load from a byte[] in memory /// </summary> /// <param name="_ImageFileContent">The source image content as a byte[]</param> /// <param name="_FileType">The type of file to load</param> /// <exception cref="NotSupportedException">Occurs if the image type is not supported by the Bitmap class</exception> /// <exception cref="Exception">Occurs if the source image format cannot be converted to RGBA32F which is the generic format we read from</exception> public void Load( byte[] _ImageFileContent, FILE_TYPE _FileType ) { Load( _ImageFileContent, _FileType ); }
/// <summary> /// Reads image size and other informations, doesn't read content /// </summary> public void ReadImageInfos() { m_usage = FindUsage( m_fileName ); if ( m_fileName.Extension.ToLower().StartsWith( ".bimage" ) ) { // Can't read! m_fileType = FILE_TYPE.BIMAGE; m_couldBeRead = false; return; } try { using ( ImageUtility.Bitmap B = new ImageUtility.Bitmap( m_fileName ) ) { m_error = null; m_couldBeRead = true; m_width = B.Width; m_height = B.Height; switch ( B.Type ) { case ImageUtility.Bitmap.FILE_TYPE.PNG: m_fileType = FILE_TYPE.PNG; break; case ImageUtility.Bitmap.FILE_TYPE.TGA: m_fileType = FILE_TYPE.TGA; break; // case ImageUtility.Bitmap.FILE_TYPE.DDS: m_fileType = FILE_TYPE.DDS; break; // DDS not supported? case ImageUtility.Bitmap.FILE_TYPE.JPEG: m_fileType = FILE_TYPE.JPG; break; case ImageUtility.Bitmap.FILE_TYPE.TIFF: m_fileType = FILE_TYPE.TIFF; break; } } } catch ( Exception _e ) { m_couldBeRead = false; m_error = _e; throw _e; } }
public void Read( BinaryReader R ) { m_fileName = new FileInfo( R.ReadString() ); m_timeStamp = DateTime.FromBinary( R.ReadInt64() ); m_fileType = (FILE_TYPE) R.ReadInt32(); if ( m_fileType > FILE_TYPE.BIMAGE ) throw new Exception( "Corrupted image file!" ); m_width = R.ReadInt32(); m_height = R.ReadInt32(); m_couldBeRead = R.ReadBoolean(); string errorText = R.ReadString(); m_error = errorText != string.Empty ? new Exception( errorText ) : null; m_usage = FindUsage( m_fileName ); // Attempt to find usage again }
public LFile(FILE_TYPE ftype, System.Text.Encoding encode) { CurEncoding = encode; }
public LFile(FILE_TYPE ftype) { CurEncoding = Encoding.Default; }
/// <summary> /// Creates a bitmap from a stream /// </summary> /// <param name="_Device"></param> /// <param name="_Name"></param> /// <param name="_ImageStream">The image stream to load the bitmap from</param> /// <param name="_FileType">The image type</param> public Bitmap( System.IO.Stream _ImageStream, FILE_TYPE _FileType, ColorProfile _ProfileOverride ) { Load( _ImageStream, _FileType, _ProfileOverride ); }
/// <summary> /// Creates a bitmap from memory /// </summary> /// <param name="_Device"></param> /// <param name="_Name"></param> /// <param name="_ImageFileContent">The memory buffer to load the bitmap from</param> /// <param name="_FileType">The image type</param> public Bitmap( byte[] _ImageFileContent, FILE_TYPE _FileType ) { Load( _ImageFileContent, _FileType ); }
/// <summary> /// Creates a bitmap from a stream /// </summary> /// <param name="_Device"></param> /// <param name="_Name"></param> /// <param name="_ImageStream">The image stream to load the bitmap from</param> /// <param name="_FileType">The image type</param> public Bitmap( System.IO.Stream _ImageStream, FILE_TYPE _FileType ) { Load( _ImageStream, _FileType ); }
public void Load( System.IO.Stream _ImageStream, FILE_TYPE _FileType, ColorProfile _ProfileOverride ) { // Read the file's content byte[] ImageContent = new byte[_ImageStream.Length]; _ImageStream.Read( ImageContent, 0, (int) _ImageStream.Length ); Load( ImageContent, _FileType, _ProfileOverride ); }
/// <summary> /// Loads from stream /// </summary> /// <param name="_ImageStream"></param> /// <param name="_FileType"></param> public void Load( System.IO.Stream _ImageStream, FILE_TYPE _FileType ) { Load( _ImageStream, _FileType, null ); }
public void Load( System.IO.FileInfo _ImageFileName, FILE_TYPE _FileType, ColorProfile _ProfileOverride ) { using ( System.IO.FileStream ImageStream = _ImageFileName.Open( System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read ) ) Load( ImageStream, _FileType, _ProfileOverride ); }
/// <summary> /// Loads from disk /// </summary> /// <param name="_ImageFileName"></param> /// <param name="_FileType"></param> public void Load( System.IO.FileInfo _ImageFileName, FILE_TYPE _FileType ) { Load( _ImageFileName, _FileType, null ); }
/// <summary> /// Creates a bitmap from memory /// </summary> /// <param name="_Device"></param> /// <param name="_Name"></param> /// <param name="_ImageFileContent">The memory buffer to load the bitmap from</param> /// <param name="_FileType">The image type</param> public Bitmap( byte[] _ImageFileContent, FILE_TYPE _FileType, ColorProfile _ProfileOverride ) { Load( _ImageFileContent, _FileType, _ProfileOverride ); }
public void Load( byte[] _ImageFileContent, FILE_TYPE _FileType, ColorProfile _ProfileOverride ) { m_Type = _FileType; try { switch ( _FileType ) { case FILE_TYPE.JPEG: case FILE_TYPE.PNG: case FILE_TYPE.TIFF: case FILE_TYPE.GIF: case FILE_TYPE.BMP: using ( System.IO.MemoryStream Stream = new System.IO.MemoryStream( _ImageFileContent ) ) { // ===== 1] Load the bitmap source ===== BitmapDecoder Decoder = BitmapDecoder.Create( Stream, BitmapCreateOptions.IgnoreColorProfile | BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnDemand ); if ( Decoder.Frames.Count == 0 ) throw new Exception( "BitmapDecoder failed to read at least one bitmap frame!" ); BitmapFrame Frame = Decoder.Frames[0]; if ( Frame == null ) throw new Exception( "Invalid decoded bitmap!" ); // DEBUG // int StrideX = (Frame.Format.BitsPerPixel>>3)*Frame.PixelWidth; // byte[] DebugImageSource = new byte[StrideX*Frame.PixelHeight]; // Frame.CopyPixels( DebugImageSource, StrideX, 0 ); // DEBUG // pas de gamma sur les JPEG si non spécifié ! // Il y a bien une magouille faite lors de la conversion par le FormatConvertedBitmap! // ===== 2] Build the color profile ===== m_ColorProfile = _ProfileOverride != null ? _ProfileOverride : new ColorProfile( Frame.Metadata as BitmapMetadata, _FileType ); // ===== 3] Convert the frame to generic RGBA32F ===== ConvertFrame( Frame ); // ===== 4] Convert to CIE XYZ (our device-independent profile connection space) ===== if ( ms_ReadContent && ms_ConvertContent2XYZ ) m_ColorProfile.RGB2XYZ( m_Bitmap, m_Bitmap ); } break; case FILE_TYPE.TGA: { // Load as a System.Drawing.Bitmap and convert to float4 using ( System.IO.MemoryStream Stream = new System.IO.MemoryStream( _ImageFileContent ) ) using ( TargaImage TGA = new TargaImage( Stream, !ms_ReadContent ) ) { // Create a default sRGB linear color profile m_ColorProfile = _ProfileOverride != null ? _ProfileOverride : new ColorProfile( ColorProfile.Chromaticities.sRGB, // Use default sRGB color profile ColorProfile.GAMMA_CURVE.STANDARD, // But with a standard gamma curve... TGA.ExtensionArea.GammaRatio // ...whose gamma is retrieved from extension data ); if ( ms_ReadContent ) { // Convert byte[] ImageContent = LoadBitmap( TGA.Image, out m_Width, out m_Height ); m_Bitmap = new float4[m_Width,m_Height]; byte A; int i = 0; for ( int Y=0; Y < m_Height; Y++ ) for ( int X=0; X < m_Width; X++ ) { m_Bitmap[X,Y].x = BYTE_TO_FLOAT * ImageContent[i++]; m_Bitmap[X,Y].y = BYTE_TO_FLOAT * ImageContent[i++]; m_Bitmap[X,Y].z = BYTE_TO_FLOAT * ImageContent[i++]; A = ImageContent[i++]; m_bHasAlpha |= A != 0xFF; m_Bitmap[X,Y].w = BYTE_TO_FLOAT * A; } if ( ms_ConvertContent2XYZ ) { // Convert to CIEXYZ m_ColorProfile.RGB2XYZ( m_Bitmap, m_Bitmap ); } } else { // Only read dimensions m_Width = TGA.Header.Width; m_Height = TGA.Header.Height; } } return; } case FILE_TYPE.HDR: { // Load as XYZ m_Bitmap = LoadAndDecodeHDRFormat( _ImageFileContent, true, _ProfileOverride, out m_ColorProfile ); m_Width = m_Bitmap.GetLength( 0 ); m_Height = m_Bitmap.GetLength( 1 ); return; } #if USE_LIB_RAW case FILE_TYPE.CRW: case FILE_TYPE.CR2: case FILE_TYPE.DNG: { using ( System.IO.MemoryStream Stream = new System.IO.MemoryStream( _ImageFileContent ) ) using ( LibRawManaged.RawFile Raw = new LibRawManaged.RawFile() ) { Raw.UnpackRAW( Stream ); ColorProfile.Chromaticities Chroma = Raw.ColorProfile == LibRawManaged.RawFile.COLOR_PROFILE.ADOBE_RGB ? ColorProfile.Chromaticities.AdobeRGB_D65 // Use Adobe RGB : ColorProfile.Chromaticities.sRGB; // Use default sRGB color profile // Create a default sRGB linear color profile m_ColorProfile = _ProfileOverride != null ? _ProfileOverride : new ColorProfile( Chroma, ColorProfile.GAMMA_CURVE.STANDARD, // But with a standard gamma curve... 1.0f // Linear ); // Also get back valid camera shot info m_bHasValidShotInfo = true; m_ISOSpeed = Raw.ISOSpeed; m_ShutterSpeed = Raw.ShutterSpeed; m_Aperture = Raw.Aperture; m_FocalLength = Raw.FocalLength; // Convert m_Width = Raw.Width; m_Height = Raw.Height; // float ColorNormalizer = 1.0f / Raw.Maximum; float ColorNormalizer = 1.0f / 65535.0f; if ( ms_ReadContent ) { m_Bitmap = new float4[m_Width,m_Height]; UInt16[,][] ImageContent = Raw.Image; for ( int Y=0; Y < m_Height; Y++ ) for ( int X=0; X < m_Width; X++ ) { m_Bitmap[X,Y].x = ImageContent[X,Y][0] * ColorNormalizer; m_Bitmap[X,Y].y = ImageContent[X,Y][1] * ColorNormalizer; m_Bitmap[X,Y].z = ImageContent[X,Y][2] * ColorNormalizer; m_Bitmap[X,Y].w = ImageContent[X,Y][3] * ColorNormalizer; } if ( ms_ConvertContent2XYZ ) { // Convert to CIEXYZ m_ColorProfile.RGB2XYZ( m_Bitmap, m_Bitmap ); } } } #region My poor attempt at reading CRW files // using ( System.IO.MemoryStream Stream = new System.IO.MemoryStream( _ImageFileContent ) ) // using ( CanonRawLoader CRWLoader = new CanonRawLoader( Stream ) ) // { // ColorProfile.Chromaticities Chroma = CRWLoader.m_ColorProfile == CanonRawLoader.DataColorProfile.COLOR_PROFILE.ADOBE_RGB // ? ColorProfile.Chromaticities.AdobeRGB_D65 // Use Adobe RGB // : ColorProfile.Chromaticities.sRGB; // Use default sRGB color profile // // // Create a default sRGB linear color profile // m_ColorProfile = new ColorProfile( // Chroma, // ColorProfile.GAMMA_CURVE.STANDARD, // But with a standard gamma curve... // 1.0f // Linear // ); // // // Convert // m_Width = CRWLoader.m_RAWImage.m_Width; // m_Height = CRWLoader.m_RAWImage.m_Height; // // m_Bitmap = new float4[m_Width,m_Height]; // UInt16[] ImageContent = CRWLoader.m_RAWImage.m_DecodedImage; // int i = 0; // // for ( int Y=0; Y < m_Height; Y++ ) // // for ( int X=0; X < m_Width; X++ ) // // { // // m_Bitmap[X,Y].x = ImageContent[i++] / 4096.0f; // // m_Bitmap[X,Y].y = ImageContent[i++] / 4096.0f; // // m_Bitmap[X,Y].z = ImageContent[i++] / 4096.0f; // // i++; // // } // // i=0; // for ( int Y=0; Y < m_Height; Y++ ) // for ( int X=0; X < m_Width; X++ ) // m_Bitmap[X,Y].x = ImageContent[i++] / 4096.0f; // i=0; // for ( int Y=0; Y < m_Height; Y++ ) // for ( int X=0; X < m_Width; X++ ) // m_Bitmap[X,Y].y = ImageContent[i++] / 4096.0f; // i=0; // for ( int Y=0; Y < m_Height; Y++ ) // for ( int X=0; X < m_Width; X++ ) // m_Bitmap[X,Y].z = ImageContent[i++] / 4096.0f; // // // Convert to CIEXYZ // m_ColorProfile.RGB2XYZ( m_Bitmap ); // } #endregion return; } #endif default: throw new NotSupportedException( "The image file type \"" + _FileType + "\" is not supported by the Bitmap class!" ); } } catch ( Exception ) { throw; // Go on ! } }
/// <summary> /// Save to a stream /// </summary> /// <param name="_Stream">The stream to write the image to</param> /// <param name="_FileType">The file type to save as</param> /// <param name="_Parms">Additional formatting flags</param> /// <param name="_Options">An optional block of options for encoding</param> /// <exception cref="NotSupportedException">Occurs if the image type is not supported by the Bitmap class</exception> /// <exception cref="Exception">Occurs if the source image format cannot be converted to RGBA32F which is the generic format we read from</exception> public void Save( System.IO.Stream _Stream, FILE_TYPE _FileType, FORMAT_FLAGS _Parms, FormatEncoderOptions _Options ) { if ( m_ColorProfile == null ) throw new Exception( "You can't save the bitmap if you don't provide a valid color profile!" ); try { switch ( _FileType ) { case FILE_TYPE.JPEG: case FILE_TYPE.PNG: case FILE_TYPE.TIFF: case FILE_TYPE.GIF: case FILE_TYPE.BMP: { BitmapEncoder Encoder = null; switch ( _FileType ) { case FILE_TYPE.JPEG: Encoder = new JpegBitmapEncoder(); break; case FILE_TYPE.PNG: Encoder = new PngBitmapEncoder(); break; case FILE_TYPE.TIFF: Encoder = new TiffBitmapEncoder(); break; case FILE_TYPE.GIF: Encoder = new GifBitmapEncoder(); break; case FILE_TYPE.BMP: Encoder = new BmpBitmapEncoder(); break; } if ( _Options != null ) { switch ( _FileType ) { case FILE_TYPE.JPEG: (Encoder as JpegBitmapEncoder).QualityLevel = _Options.JPEGQualityLevel; break; case FILE_TYPE.PNG: (Encoder as PngBitmapEncoder).Interlace = _Options.PNGInterlace; break; case FILE_TYPE.TIFF: (Encoder as TiffBitmapEncoder).Compression = _Options.TIFFCompression; break; case FILE_TYPE.GIF: break; case FILE_TYPE.BMP: break; } } // Find the appropriate pixel format int BitsPerComponent = 8; bool IsFloat = false; if ( (_Parms & FORMAT_FLAGS.SAVE_16BITS_UNORM) != 0 ) BitsPerComponent = 16; if ( (_Parms & FORMAT_FLAGS.SAVE_32BITS_FLOAT) != 0 ) { // Floating-point format BitsPerComponent = 32; IsFloat = true; } int ComponentsCount = (_Parms & FORMAT_FLAGS.GRAY) == 0 ? 3 : 1; if ( m_bHasAlpha && (_Parms & FORMAT_FLAGS.SKIP_ALPHA) == 0 ) ComponentsCount++; bool PreMultiplyAlpha = (_Parms & FORMAT_FLAGS.PREMULTIPLY_ALPHA) != 0; System.Windows.Media.PixelFormat Format; if ( ComponentsCount == 1 ) { // Gray switch ( BitsPerComponent ) { case 8: Format = System.Windows.Media.PixelFormats.Gray8; break; case 16: Format = System.Windows.Media.PixelFormats.Gray16; break; case 32: Format = System.Windows.Media.PixelFormats.Gray32Float; break; default: throw new Exception( "Unsupported format!" ); } } else if ( ComponentsCount == 3 ) { // RGB switch ( BitsPerComponent ) { case 8: Format = System.Windows.Media.PixelFormats.Bgr24; break; case 16: Format = System.Windows.Media.PixelFormats.Rgb48; break; case 32: throw new Exception( "32BITS formats aren't supported without ALPHA!" ); default: throw new Exception( "Unsupported format!" ); } } else { // RGBA switch ( BitsPerComponent ) { case 8: Format = PreMultiplyAlpha ? System.Windows.Media.PixelFormats.Pbgra32 : System.Windows.Media.PixelFormats.Bgra32; break; case 16: Format = PreMultiplyAlpha ? System.Windows.Media.PixelFormats.Prgba64 : System.Windows.Media.PixelFormats.Rgba64; break; case 32: Format = PreMultiplyAlpha ? System.Windows.Media.PixelFormats.Prgba128Float : System.Windows.Media.PixelFormats.Rgba128Float; if ( !IsFloat ) throw new Exception( "32BITS_UNORM format isn't supported if not floating-point!" ); break; default: throw new Exception( "Unsupported format!" ); } } // Convert into appropriate frame BitmapFrame Frame = ConvertFrame( Format ); Encoder.Frames.Add( Frame ); // Save Encoder.Save( _Stream ); } break; // case FILE_TYPE.TGA: //TODO! // { // // Load as a System.Drawing.Bitmap and convert to float4 // using ( System.IO.MemoryStream Stream = new System.IO.MemoryStream( _ImageFileContent ) ) // using ( TargaImage TGA = new TargaImage( Stream ) ) // { // // Create a default sRGB linear color profile // m_ColorProfile = new ColorProfile( // ColorProfile.Chromaticities.sRGB, // Use default sRGB color profile // ColorProfile.GAMMA_CURVE.STANDARD, // But with a standard gamma curve... // TGA.ExtensionArea.GammaRatio // ...whose gamma is retrieved from extension data // ); // // // Convert // byte[] ImageContent = LoadBitmap( TGA.Image, out m_Width, out m_Height ); // m_Bitmap = new float4[m_Width,m_Height]; // byte A; // int i = 0; // for ( int Y=0; Y < m_Height; Y++ ) // for ( int X=0; X < m_Width; X++ ) // { // m_Bitmap[X,Y].x = BYTE_TO_FLOAT * ImageContent[i++]; // m_Bitmap[X,Y].y = BYTE_TO_FLOAT * ImageContent[i++]; // m_Bitmap[X,Y].z = BYTE_TO_FLOAT * ImageContent[i++]; // // A = ImageContent[i++]; // m_bHasAlpha |= A != 0xFF; // // m_Bitmap[X,Y].w = BYTE_TO_FLOAT * A; // } // // // Convert to CIEXYZ // m_ColorProfile.RGB2XYZ( m_Bitmap ); // } // return; // } // case FILE_TYPE.HDR: //TODO! // { // // Load as XYZ // m_Bitmap = LoadAndDecodeHDRFormat( _ImageFileContent, true, out m_ColorProfile ); // m_Width = m_Bitmap.GetLength( 0 ); // m_Height = m_Bitmap.GetLength( 1 ); // return; // } case FILE_TYPE.CRW: case FILE_TYPE.CR2: case FILE_TYPE.DNG: default: throw new NotSupportedException( "The image file type \"" + _FileType + "\" is not supported by the Bitmap class!" ); } } catch ( Exception ) { throw; // Go on ! } finally { } }