public override Stream Encode(Stream input, Codec.CodecData pData) { var fiBitmap = _encode(input, pData); // open memory chunk allocated by FreeImage var mem = FI.FreeImage.OpenMemory(IntPtr.Zero, 0); // write data into memory FI.FreeImage.SaveToMemory((FI.FREE_IMAGE_FORMAT) this._freeImageType, fiBitmap, mem, FI.FREE_IMAGE_SAVE_FLAGS.DEFAULT); // Grab data information var data = IntPtr.Zero; uint size = 0; FI.FreeImage.AcquireMemory(mem, ref data, ref size); // Copy data into our own buffer // Because we're asking MemoryDataStream to free this, must create in a compatible way var ourData = new byte[size]; using (var src = BufferBase.Wrap(data, (int)size)) { using (var dest = BufferBase.Wrap(ourData)) { Memory.Copy(src, dest, (int)size); } } // Wrap data in stream, tell it to free on close var outstream = new MemoryStream(ourData); // Now free FreeImage memory buffers FI.FreeImage.CloseMemory(mem); // Unload bitmap FI.FreeImage.Unload(fiBitmap); return(outstream); }
public override void EncodeToFile(Stream input, string outFileName, Codec.CodecData codecData) { var data = (ImageData)codecData; // save the image to file SDI.PixelFormat pf; int bpp; switch (data.format) { case Axiom.Media.PixelFormat.B8G8R8: pf = SDI.PixelFormat.Format24bppRgb; bpp = 3; break; case Axiom.Media.PixelFormat.A8B8G8R8: pf = SDI.PixelFormat.Format32bppRgb; bpp = 4; break; default: throw new ArgumentException("Unsupported Pixel Format " + data.format); } var image = new Bitmap(data.width, data.height, pf); //Create a BitmapData and Lock all pixels to be written SDI.BitmapData imagedta = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), SDI.ImageLockMode.WriteOnly, image.PixelFormat); var buffer = new byte[input.Length]; input.Read(buffer, 0, buffer.Length); for (var c = 0; c < buffer.Length - bpp; c += bpp) { var tmp = buffer[c]; buffer[c] = buffer[c + 2]; buffer[c + 2] = tmp; } //Copy the data from the byte array into BitmapData.Scan0 Marshal.Copy(buffer, 0, imagedta.Scan0, buffer.Length); //Unlock the pixels image.UnlockBits(imagedta); image.Save(outFileName, _convertImageFormat(outFileName)); }
public override void EncodeToFile(Stream input, string outFileName, Codec.CodecData codecData) { int imageID; // create and bind a new image Il.ilGenImages(1, out imageID); Il.ilBindImage(imageID); var buffer = new byte[input.Length]; input.Read(buffer, 0, buffer.Length); var imgData = (ImageData)codecData; PixelBox src; using (var bufHandle = BufferBase.Wrap(buffer)) { src = new PixelBox(imgData.width, imgData.height, imgData.depth, imgData.format, bufHandle); } try { // Convert image from Axiom to current IL image ILUtil.ConvertToIL(src); } catch (Exception ex) { LogManager.Instance.Write("IL Failed image conversion :", ex.Message); } // flip the image Ilu.iluFlipImage(); // save the image to file Il.ilSaveImage(outFileName); var error = Il.ilGetError(); if (error != Il.IL_NO_ERROR) { LogManager.Instance.Write("IL Error, could not save file: {0} : {1}", outFileName, Ilu.iluErrorString(error)); } Il.ilDeleteImages(1, ref imageID); }
public override Stream Encode(Stream input, Codec.CodecData data) { throw new NotImplementedException("Encode to memory not implemented"); }
public override Stream Encode(Stream input, Codec.CodecData data) { throw new NotImplementedException(); }
/// <see cref="Axiom.Media.Codec.EncodeToFile"/> public override void EncodeToFile(Stream input, string outFileName, Codec.CodecData data) { throw new NotImplementedException(); }