protected int replaceNaN(ShortBuffer shortBuffer, short value) { int length = shortBuffer.remaining(); int numValues = 0; if (this.tmpBuffer == null || this.tmpBuffer.length < shortBuffer.remaining()) { this.tmpBuffer = new short[length]; } shortBuffer.get(this.tmpBuffer, 0, length); shortBuffer.flip(); for (int i = 0; i < length; i++) { if (isNoValueShort(this.tmpBuffer[i])) { this.tmpBuffer[i] = value; } else { numValues++; } } shortBuffer.put(this.tmpBuffer, 0, length); shortBuffer.flip(); return(numValues); }
private int getInt32(Buffer buffer) { if (buffer is IntBuffer) { return(((IntBuffer)buffer).get()); } else if (buffer is ShortBuffer) { ShortBuffer shortBuffer = (ShortBuffer)buffer; int n0 = shortBuffer.get() & 0xFFFF; int n1 = shortBuffer.get() & 0xFFFF; return((n1 << 16) | n0); } else if (buffer is ByteBuffer) { return(((ByteBuffer)buffer).Int); } return(0); }
/// <summary> /// Since the given buffer may not have an array, this will automatically perform necessary edits to get a <see cref="ushort"/> array (this uses ushort because of how java handles datatypes) /// </summary> /// <param name="buffer"></param> /// <returns></returns> private static ushort[] GetFromShortBuffer(ShortBuffer buffer) { List <ushort> data = new List <ushort>(); while (buffer.hasRemaining()) { short v = buffer.get(); // This is kinda expensive ngl data.Add(BitConverter.ToUInt16(BitConverter.GetBytes(v), 0)); } return(data.ToArray()); }
public override int read16(int address) { address &= addressMask; return(((int)shortBuffer.get(address >> 1)) & 0xFFFF); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void write() throws java.io.IOException public virtual void write() { if (bufferStorage >= TPSM_PIXEL_STORAGE_MODE_4BIT_INDEXED && bufferStorage <= TPSM_PIXEL_STORAGE_MODE_32BIT_INDEXED && bufferStorage != depthBufferPixelFormat) { // Writing of indexed images not supported return; } if (compressedImage) { decompressImage(); } bool imageInvert = invert; int readWidth = System.Math.Min(width, bufferWidth); sbyte[] pixelBytes = new sbyte[4]; sbyte[] blackPixelBytes = new sbyte[pixelBytes.Length]; // ImageIO doesn't support the bmp file format and // doesn't properly write PNG files with pixel alpha values AbstractCaptureImage captureImage; if (bmpFileFormat.Equals(fileFormat)) { captureImage = new CaptureImageBMP(); } else if (pngFileFormat.Equals(fileFormat)) { captureImage = new CaptureImagePNG(); } else { captureImage = new CaptureImageImageIO(); } captureImage.writeHeader(FileName, fileFormat, width, height, readWidth); if (captureImage.Inverted) { imageInvert = !imageInvert; } bool imageType32Bit = bufferStorage == TPSM_PIXEL_STORAGE_MODE_32BIT_ABGR8888 || bufferStorage == RE_DEPTH_STENCIL; if (imageReader != null) { for (int y = 0; y < height; y++) { captureImage.startLine(imageInvert ? (height - y - 1) : y); for (int x = 0; x < readWidth; x++) { int pixel = imageReader.readNext(); captureImage.writePixel(pixel); } captureImage.endLine(); } captureImage.writeEnd(); } else if (buffer is IntBuffer && imageType32Bit) { IntBuffer intBuffer = (IntBuffer)buffer; for (int y = 0; y < height; y++) { intBuffer.position((imageInvert ? (height - y - 1) : y) * bufferWidth); captureImage.startLine(imageInvert ? (height - y - 1) : y); for (int x = 0; x < readWidth; x++) { try { int pixel = intBuffer.get(); captureImage.writePixel(pixel); } catch (BufferUnderflowException) { captureImage.writePixel(blackPixelBytes); } } captureImage.endLine(); } } else if (buffer is IntBuffer && !imageType32Bit) { IntBuffer intBuffer = (IntBuffer)buffer; for (int y = 0; y < height; y++) { intBuffer.position((imageInvert ? (height - y - 1) : y) * bufferWidth / 2); captureImage.startLine(imageInvert ? (height - y - 1) : y); for (int x = 0; x < readWidth; x += 2) { try { int twoPixels = intBuffer.get(); getPixelBytes((short)twoPixels, bufferStorage, pixelBytes); captureImage.writePixel(pixelBytes); if (x + 1 < readWidth) { getPixelBytes((short)((int)((uint)twoPixels >> 16)), bufferStorage, pixelBytes); captureImage.writePixel(pixelBytes); } } catch (BufferUnderflowException) { captureImage.writePixel(blackPixelBytes); captureImage.writePixel(blackPixelBytes); } } captureImage.endLine(); } } else if (buffer is ShortBuffer && !imageType32Bit) { ShortBuffer shortBuffer = (ShortBuffer)buffer; for (int y = 0; y < height; y++) { shortBuffer.position((imageInvert ? (height - y - 1) : y) * bufferWidth); captureImage.startLine(imageInvert ? (height - y - 1) : y); for (int x = 0; x < readWidth; x++) { short pixel = shortBuffer.get(); getPixelBytes(pixel, bufferStorage, pixelBytes); captureImage.writePixel(pixelBytes); } captureImage.endLine(); } } else if (imageType32Bit) { for (int y = 0; y < height; y++) { IMemoryReader memoryReader = MemoryReader.getMemoryReader(imageaddr + (imageInvert ? (height - y - 1) : y) * bufferWidth * 4, bufferWidth * 4, 4); captureImage.startLine(imageInvert ? (height - y - 1) : y); for (int x = 0; x < readWidth; x++) { int pixel = memoryReader.readNext(); captureImage.writePixel(pixel); } captureImage.endLine(); } } else { for (int y = 0; y < height; y++) { IMemoryReader memoryReader = MemoryReader.getMemoryReader(imageaddr + (imageInvert ? (height - y - 1) : y) * bufferWidth * 2, bufferWidth * 2, 2); captureImage.startLine(imageInvert ? (height - y - 1) : y); for (int x = 0; x < readWidth; x++) { short pixel = (short)memoryReader.readNext(); getPixelBytes(pixel, bufferStorage, pixelBytes); captureImage.writePixel(pixelBytes); } captureImage.endLine(); } } if (buffer != null) { buffer.rewind(); } captureImage.writeEnd(); //if (log.DebugEnabled) { Console.WriteLine(string.Format("Saved image to {0}", FileName)); } }