public unsafe static RawDescriptionLoader FromFile(string filename) { IntPtr eximg_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SSRLWrapper.ExtractedDescription))); int err = SSRLWrapper.ExtractDescriptionFromFile(filename, eximg_ptr); #if DEBUG Console.WriteLine("ExtractDescriptionFromFile returned " + err); #endif if (err != 0) { throw new Exception(); // TODO: Design a correct exception type } SSRLWrapper.ExtractedDescription eximg = (SSRLWrapper.ExtractedDescription)Marshal.PtrToStructure(eximg_ptr, typeof(SSRLWrapper.ExtractedDescription)); RawDescriptionLoader ppml = new RawDescriptionLoader(); // Handling ppml.mThumbnailData = new byte[eximg.data_size]; ppml.mIsJpeg = eximg.is_jpeg; ppml.mAperture = eximg.aperture; ppml.mShutter = eximg.shutter; ppml.mISOSpeed = eximg.iso_speed; ppml.mFocalLength = eximg.focal_len; ppml.mArtist = Marshal.PtrToStringAnsi(eximg.artist); ppml.mDescription = Marshal.PtrToStringAnsi(eximg.desc); ppml.mTimeStamp = timeOrigin.AddSeconds(eximg.timestamp); ppml.mCameraMaker = Marshal.PtrToStringAnsi(eximg.camera_maker); ppml.mCameraModel = Marshal.PtrToStringAnsi(eximg.camera_model); int flip = eximg.flip; Marshal.Copy(eximg.data, ppml.mThumbnailData, 0, ppml.mThumbnailData.Length); SSRLWrapper.FreeExtractedDescription(eximg); // Rotating the image // flip: 0 - no rotation; 3 - 180-deg rotation; 5 - 90-deg counterclockwise, 6 - 90-deg clockwise if (flip == 0) { ppml.mFlip = FlipValues.None; } else if (flip == 3) { ppml.mFlip = FlipValues.UpsideDown; } else if (flip == 5) { ppml.mFlip = FlipValues.Counterclockwise; } else if (flip == 6) { ppml.mFlip = FlipValues.Clockwise; } return(ppml); }
public unsafe static RawLoader FromFile(string filename, bool divide_by_2, ProgressReporter callback) { IntPtr eximg_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SSRLWrapper.ExtractedRawImage))); int err = SSRLWrapper.ExtractRawImageFromFile(filename, divide_by_2, eximg_ptr, delegate(float progress) { return(callback(progress)); }); #if DEBUG Console.WriteLine("ExtractRawImageFromFile returned " + err); #endif if (err != 0) { return(null); } SSRLWrapper.ExtractedRawImage eximg = (SSRLWrapper.ExtractedRawImage)Marshal.PtrToStructure(eximg_ptr, typeof(SSRLWrapper.ExtractedRawImage)); RawLoader ppml = new RawLoader(eximg.width, eximg.height); if (eximg.bitsPerChannel == 16) { // Handling short[] rgb_data = new short[eximg.width * eximg.height * 3]; Marshal.Copy(eximg.data, rgb_data, 0, rgb_data.Length); for (int i = 0; i < eximg.width; i++) { for (int j = 0; j < eximg.height; j++) { ppml.r_channel[i, j] = (ushort)rgb_data[3 * (i + eximg.width * j)]; ppml.g_channel[i, j] = (ushort)rgb_data[3 * (i + eximg.width * j) + 1]; ppml.b_channel[i, j] = (ushort)rgb_data[3 * (i + eximg.width * j) + 2]; } } } else if (eximg.bitsPerChannel == 8) { throw new Exception("Can't handle 8 bit"); } else { throw new Exception("incorrect or unsupported bitsPerChannel value: " + eximg.bitsPerChannel); } SSRLWrapper.FreeExtractedRawImage(eximg); return(ppml); }