/** * Returns a copy of the specified buffer, with the specified new size. The new size must be greater than or equal * to the specified buffer's size. If the new size is greater than the specified buffer's size, this returns a new * buffer which is partially filled with the contents of the specified buffer. The returned buffer is a backed by a * direct ByteBuffer if and only if the specified buffer is direct. * * @param buffer the buffer to copy. * @param newSize the new buffer's size, in shorts. * * @return the new buffer, with the specified size. * * @throws ArgumentException if the buffer is null, if the new size is negative, or if the new size is less * than the buffer's remaing elements. */ public static ShortBuffer copyOf(ShortBuffer buffer, int newSize) { if (newSize < 0 || newSize < buffer.remaining()) { String message = Logging.getMessage("generic.SizeOutOfRange", newSize); Logging.logger().severe(message); throw new ArgumentException(message); } ShortBuffer newBuffer = newShortBuffer(newSize, buffer.isDirect()); int pos = buffer.position(); // Save the input buffer's current position. try { newBuffer.put(buffer); newBuffer.rewind(); } finally { buffer.position(pos); // Restore the input buffer's original position. } return(newBuffer); }
public MyRenderer(BasicCustomVideoRenderer parent) { this.mCustomVideoRenderer = parent; ByteBuffer bb = ByteBuffer.allocateDirect(mXYZCoords.Length * 4); bb.order(ByteOrder.nativeOrder()); mVertexBuffer = bb.asFloatBuffer(); mVertexBuffer.put(mXYZCoords); mVertexBuffer.position(0); ByteBuffer tb = ByteBuffer.allocateDirect(mUVCoords.Length * 4); tb.order(ByteOrder.nativeOrder()); mTextureBuffer = tb.asFloatBuffer(); mTextureBuffer.put(mUVCoords); mTextureBuffer.position(0); ByteBuffer dlb = ByteBuffer.allocateDirect(mVertexIndex.Length * 2); dlb.order(ByteOrder.nativeOrder()); mDrawListBuffer = dlb.asShortBuffer(); mDrawListBuffer.put(mVertexIndex); mDrawListBuffer.position(0); }
private void initTriangle() { // float has 4 bytes ByteBuffer vbb = ByteBuffer.allocateDirect(_nrOfVertices * 3 * 4); vbb.order(ByteOrder.nativeOrder()); _vertexBuffer = vbb.asFloatBuffer(); // short has 2 bytes ByteBuffer ibb = ByteBuffer.allocateDirect(_nrOfVertices * 2); ibb.order(ByteOrder.nativeOrder()); _indexBuffer = ibb.asShortBuffer(); float[] coords = { -0.5f, -0.5f, 0f, // (x1, y1, z1) 0.5f, -0.5f, 0f, // (x2, y2, z2) 0f, 0.5f, 0f // (x3, y3, z3) }; _vertexBuffer.put(coords); _indexBuffer.put(_indicesArray); _vertexBuffer.position(0); _indexBuffer.position(0); }
private void initTriangle() { float[] coords = { -0.5f, -0.5f, 0.5f, // 0 0.5f, -0.5f, 0.5f, // 1 0f, -0.5f, -0.5f, // 2 0f, 0.5f, 0f, // 3 }; _nrOfVertices = coords.Length; float[] colors = { 1f, 0f, 0f, 1f, // point 0 red 0f, 1f, 0f, 1f, // point 1 green 0f, 0f, 1f, 1f, // point 2 blue 1f, 1f, 1f, 1f, // point 3 white }; short[] indices = new short[] { 0, 1, 3, // rwg 0, 2, 1, // rbg 0, 3, 2, // rbw 1, 2, 3, // bwg }; // float has 4 bytes, coordinate * 4 bytes ByteBuffer vbb = ByteBuffer.allocateDirect(coords.Length * 4); vbb.order(ByteOrder.nativeOrder()); _vertexBuffer = vbb.asFloatBuffer(); // short has 2 bytes, indices * 2 bytes ByteBuffer ibb = ByteBuffer.allocateDirect(indices.Length * 2); ibb.order(ByteOrder.nativeOrder()); _indexBuffer = ibb.asShortBuffer(); // float has 4 bytes, colors (RGBA) * 4 bytes ByteBuffer cbb = ByteBuffer.allocateDirect(colors.Length * 4); cbb.order(ByteOrder.nativeOrder()); _colorBuffer = cbb.asFloatBuffer(); _vertexBuffer.put(coords); _indexBuffer.put(indices); _colorBuffer.put(colors); _vertexBuffer.position(0); _indexBuffer.position(0); _colorBuffer.position(0); }
private void initTriangle() { // float has 4 bytes ByteBuffer vbb = ByteBuffer.allocateDirect(_nrOfVertices * 3 * 4); vbb.order(ByteOrder.nativeOrder()); _vertexBuffer = vbb.asFloatBuffer(); // short has 4 bytes ByteBuffer ibb = ByteBuffer.allocateDirect(_nrOfVertices * 2); ibb.order(ByteOrder.nativeOrder()); _indexBuffer = ibb.asShortBuffer(); // float has 4 bytes, 4 colors (RGBA) * number of vertices * 4 bytes ByteBuffer cbb = ByteBuffer.allocateDirect(4 * _nrOfVertices * 4); cbb.order(ByteOrder.nativeOrder()); _colorBuffer = cbb.asFloatBuffer(); float[] coords = { -0.5f, -0.5f, 0f, // (x1, y1, z1) 0.5f, -0.5f, 0f, // (x2, y2, z2) 0.5f, 0.5f, 0f // (x3, y3, z3) }; float[] colors = { 1f, 0f, 0f, 1f, // point 1 0f, 1f, 0f, 1f, // point 2 0f, 0f, 1f, 1f, // point 3 }; _vertexBuffer.put(coords); _indexBuffer.put(_indicesArray); _colorBuffer.put(colors); _vertexBuffer.position(0); _indexBuffer.position(0); _colorBuffer.position(0); }
public MyRenderer() { ByteBuffer bb = ByteBuffer.allocateDirect(mXYZCoords.Length * 4); bb.order(ByteOrder.nativeOrder()); mVertexBuffer = bb.asFloatBuffer(); mVertexBuffer.put(mXYZCoords); mVertexBuffer.position(0); ByteBuffer tb = ByteBuffer.allocateDirect(mUVCoords.Length * 4); tb.order(ByteOrder.nativeOrder()); mTextureBuffer = tb.asFloatBuffer(); mTextureBuffer.put(mUVCoords); mTextureBuffer.position(0); ByteBuffer dlb = ByteBuffer.allocateDirect(mVertexIndex.Length * 2); dlb.order(ByteOrder.nativeOrder()); mDrawListBuffer = dlb.asShortBuffer(); mDrawListBuffer.put(mVertexIndex); mDrawListBuffer.position(0); }
public static ShortBuffer getDirectBuffer(int size, ShortBuffer buffer) { if (buffer == null) { return(buffer); } size = Round2(size); if (buffer.Direct) { buffer.limit((size >> 1) + buffer.position()); return(buffer); } ShortBuffer directBuffer = allocateDirectBuffer(size).asShortBuffer(); directBuffer.put((ShortBuffer)((ShortBuffer)buffer).slice().limit(size >> 1)); directBuffer.rewind(); return(directBuffer); }
//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)); } }