public byte[] Decode(PdfObject decodedObject, byte[] inputData, DecodeParameters decodeParameters) { FIBITMAP myImage = new FIBITMAP(); using (MemoryStream stream = new MemoryStream(inputData)) { myImage = FreeImage.LoadFromStream(stream); } Bitmap bitmap = FreeImage.GetBitmap(myImage); decodedObject.ColorSpace = ColorSpace.RGB; byte[] result = new byte[decodedObject.Width * decodedObject.Height * 3]; for (int i = 0; i < decodedObject.Width; i++) { for (int j = 0; j < decodedObject.Height; j++) { Color pixel = bitmap.GetPixel(i, j); int index = j * decodedObject.Width + i; result[index * 3] = pixel.R; result[index * 3 + 1] = pixel.G; result[index * 3 + 2] = pixel.B; } } return result; }
public byte[] Decode(PdfObject decodedObject, byte[] inputData, DecodeParameters decodeParameters) { FIBITMAP myImage = new FIBITMAP(); using (MemoryStream stream = new MemoryStream(inputData)) { myImage = FreeImage.LoadFromStream(stream); } Bitmap bitmap = FreeImage.GetBitmap(myImage); decodedObject.ColorSpace = ColorSpace.RGB; byte[] result = new byte[decodedObject.Width * decodedObject.Height * 3]; for (int i = 0; i < decodedObject.Width; i++) { for (int j = 0; j < decodedObject.Height; j++) { Color pixel = bitmap.GetPixel(i, j); int index = j * decodedObject.Width + i; result[index * 3] = pixel.R; result[index * 3 + 1] = pixel.G; result[index * 3 + 2] = pixel.B; } } return(result); }
public byte[] Decode(PdfObject decodedObject, byte[] inputData, DecodeParameters decodeParameters) { FIBITMAP myImage = new FIBITMAP(); using (MemoryStream stream = new MemoryStream(inputData)) { myImage = FreeImage.LoadFromStream(stream); } Bitmap bitmap = FreeImage.GetBitmap(myImage); byte[] result; if (decodedObject.ColorSpace == ColorSpace.Gray) { result = new byte[decodedObject.Width * decodedObject.Height]; for (int i = 0; i < decodedObject.Width; i++) { for (int j = 0; j < decodedObject.Height; j++) { Color pixel = bitmap.GetPixel(i, j); int index = j * decodedObject.Width + i; byte grayColor = (byte)(0.2126 * pixel.R + 0.7152 * pixel.G + 0.0722 * pixel.B); result[index] = grayColor; } } } else { result = new byte[decodedObject.Width * decodedObject.Height * 3]; for (int i = 0; i < decodedObject.Width; i++) { for (int j = 0; j < decodedObject.Height; j++) { Color pixel = bitmap.GetPixel(i, j); int index = j * decodedObject.Width + i; result[index * 3] = pixel.R; result[index * 3 + 1] = pixel.G; result[index * 3 + 2] = pixel.B; } } } return(result); }
public byte[] Decode(PdfObject decodedObject, byte[] inputData, DecodeParameters decodeParameters) { string filename = Guid.NewGuid().ToString(); File.WriteAllBytes(filename + ".j2k", inputData); ProcessStartInfo processInfo = new ProcessStartInfo(OpenJpegPath, " -i " + filename + ".j2k -o " + filename + ".bmp"); processInfo.WorkingDirectory = Directory.GetCurrentDirectory(); processInfo.WindowStyle = ProcessWindowStyle.Hidden; processInfo.CreateNoWindow = true; var process = Process.Start(processInfo); process.WaitForExit(); System.Drawing.Bitmap bitmap = System.Drawing.Image.FromFile(filename + ".bmp") as Bitmap; if (bitmap == null) { return(new byte[0]); } BitmapData bitmapData = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), ImageLockMode.ReadOnly, bitmap.PixelFormat); int length = bitmapData.Stride * bitmapData.Height; int stride = bitmapData.Stride; byte[] bytes = new byte[length]; System.Runtime.InteropServices.Marshal.Copy(bitmapData.Scan0, bytes, 0, length); bitmap.UnlockBits(bitmapData); byte[] bytePixels = new byte[bitmapData.Width * bitmapData.Height * 3]; int resLength = bytePixels.Length; for (int i = 0; i < resLength; i++) { int row = i / (bitmapData.Width * 3); int col = i % (bitmapData.Width * 3); bytePixels[i] = bytes[row * stride + col]; } bitmap.Dispose(); File.Delete(filename + ".j2k"); File.Delete(filename + ".bmp"); return(bytePixels); }
public byte[] Decode(PdfObject decodedObject, byte[] inputData, DecodeParameters parms) { throw new NotImplementedException(); }
/****************/ /* Decode frame */ /****************/ internal int silk_decode_frame( EntropyCoder psRangeDec, /* I/O Compressor data structure */ short[] pOut, /* O Pointer to output speech frame */ int pOut_ptr, BoxedValueInt pN, /* O Pointer to size of output frame */ int lostFlag, /* I 0: no loss, 1 loss, 2 decode fec */ int condCoding /* I The type of conditional coding to use */ ) { SilkDecoderControl thisCtrl = new SilkDecoderControl(); int L, mv_len, ret = 0; L = this.frame_length; thisCtrl.LTP_scale_Q14 = 0; /* Safety checks */ Inlines.OpusAssert(L > 0 && L <= SilkConstants.MAX_FRAME_LENGTH); if (lostFlag == DecoderAPIFlag.FLAG_DECODE_NORMAL || (lostFlag == DecoderAPIFlag.FLAG_DECODE_LBRR && this.LBRR_flags[this.nFramesDecoded] == 1)) { short[] pulses = new short[(L + SilkConstants.SHELL_CODEC_FRAME_LENGTH - 1) & ~(SilkConstants.SHELL_CODEC_FRAME_LENGTH - 1)]; /*********************************************/ /* Decode quantization indices of side info */ /*********************************************/ DecodeIndices.silk_decode_indices(this, psRangeDec, this.nFramesDecoded, lostFlag, condCoding); /*********************************************/ /* Decode quantization indices of excitation */ /*********************************************/ DecodePulses.silk_decode_pulses(psRangeDec, pulses, this.indices.signalType, this.indices.quantOffsetType, this.frame_length); /********************************************/ /* Decode parameters and pulse signal */ /********************************************/ DecodeParameters.silk_decode_parameters(this, thisCtrl, condCoding); /********************************************************/ /* Run inverse NSQ */ /********************************************************/ DecodeCore.silk_decode_core(this, thisCtrl, pOut, pOut_ptr, pulses); /********************************************************/ /* Update PLC state */ /********************************************************/ PLC.silk_PLC(this, thisCtrl, pOut, pOut_ptr, 0); this.lossCnt = 0; this.prevSignalType = this.indices.signalType; Inlines.OpusAssert(this.prevSignalType >= 0 && this.prevSignalType <= 2); /* A frame has been decoded without errors */ this.first_frame_after_reset = 0; } else { /* Handle packet loss by extrapolation */ PLC.silk_PLC(this, thisCtrl, pOut, pOut_ptr, 1); } /*************************/ /* Update output buffer. */ /*************************/ Inlines.OpusAssert(this.ltp_mem_length >= this.frame_length); mv_len = this.ltp_mem_length - this.frame_length; Arrays.MemMoveShort(this.outBuf, this.frame_length, 0, mv_len); Array.Copy(pOut, pOut_ptr, this.outBuf, mv_len, this.frame_length); /************************************************/ /* Comfort noise generation / estimation */ /************************************************/ CNG.silk_CNG(this, thisCtrl, pOut, pOut_ptr, L); /****************************************************************/ /* Ensure smooth connection of extrapolated and good frames */ /****************************************************************/ PLC.silk_PLC_glue_frames(this, pOut, pOut_ptr, L); /* Update some decoder state variables */ this.lagPrev = thisCtrl.pitchL[this.nb_subfr - 1]; /* Set output frame length */ pN.Val = L; return(ret); }