/// <summary> /// Decode the given source using the character set. /// </summary> protected override CharBuffer Decode(ByteBuffer source) { if (throwOnInvalidBytes) return charSet.NewDecoder() .OnMalformedInput(CodingErrorAction.REPORT) .OnUnmappableCharacter(CodingErrorAction.REPORT) .Decode(source); return base.Decode(source); }
public Cube() { ByteBuffer byteBuf = ByteBuffer.AllocateDirect(vertices.Length * 4); byteBuf.Order(ByteOrder.NativeOrder()); mVertexBuffer = byteBuf.AsFloatBuffer(); mVertexBuffer.Put(vertices); mVertexBuffer.Position(0); byteBuf = ByteBuffer.AllocateDirect(colors.Length * 4); byteBuf.Order(ByteOrder.NativeOrder()); mColorBuffer = byteBuf.AsFloatBuffer(); mColorBuffer.Put(colors); mColorBuffer.Position(0); mIndexBuffer = ByteBuffer.AllocateDirect(indices.Length); mIndexBuffer.Put(indices); mIndexBuffer.Position(0); }
private void copyPALtoBGRA(ByteBuffer buffer, byte[] curLine) { if (paletteA != null) { for (int i = 1, n = curLine.Length; i < n; i += 1) { int idx = curLine[i] & 255; byte r = palette[idx * 3 + 0]; byte g = palette[idx * 3 + 1]; byte b = palette[idx * 3 + 2]; byte a = paletteA[idx]; buffer.Put(b).Put(g).Put(r).Put(a); } } else { for (int i = 1, n = curLine.Length; i < n; i += 1) { int idx = curLine[i] & 255; byte r = palette[idx * 3 + 0]; byte g = palette[idx * 3 + 1]; byte b = palette[idx * 3 + 2]; byte a = 0xFF; buffer.Put(b).Put(g).Put(r).Put(a); } } }
private void copyRGBAtoRGB(ByteBuffer buffer, byte[] curLine) { for (int i = 1, n = curLine.Length; i < n; i += 4) { buffer.Put(curLine[i]).Put(curLine[i + 1]).Put(curLine[i + 2]); } }
private void copyRGBtoBGRA(ByteBuffer buffer, byte[] curLine) { if (transPixel != null) { byte tr = transPixel[1]; byte tg = transPixel[3]; byte tb = transPixel[5]; for (int i = 1, n = curLine.Length; i < n; i += 3) { byte r = curLine[i]; byte g = curLine[i + 1]; byte b = curLine[i + 2]; byte a = (byte)0xFF; if (r == tr && g == tg && b == tb) { a = 0; } buffer.Put(b).Put(g).Put(r).Put(a); } } else { for (int i = 1, n = curLine.Length; i < n; i += 3) { buffer.Put(curLine[i + 2]).Put(curLine[i + 1]).Put(curLine[i]).Put((byte)0xFF); } } }
private void copy(ByteBuffer buffer, byte[] curLine) { buffer.Put(curLine, 1, curLine.Length - 1); }
public void decode(ByteBuffer buffer, int stride, Format fmt) { int offset = buffer.Position(); int lineSize = ((width * bitdepth + 7) / 8) * bytesPerPixel; byte[] curLine = new byte[lineSize + 1]; byte[] prevLine = new byte[lineSize + 1]; byte[] palLine = (bitdepth < 8) ? new byte[width + 1] : null; Inflater inflater = new Inflater(); try { for (int y = 0; y < height; y++) { readChunkUnzip(inflater, curLine, 0, curLine.Length); unfilter(curLine, prevLine); buffer.Position(offset + y * stride); switch (colorType) { case COLOR_TRUECOLOR: switch (fmt) { case Format.ABGR: copyRGBtoABGR(buffer, curLine); break; case Format.RGBA: copyRGBtoRGBA(buffer, curLine); break; case Format.BGRA: copyRGBtoBGRA(buffer, curLine); break; case Format.RGB: copy(buffer, curLine); break; default: throw new UnsupportedOperationException("Unsupported format for this image"); } break; case COLOR_TRUEALPHA: switch (fmt) { case Format.ABGR: copyRGBAtoABGR(buffer, curLine); break; case Format.RGBA: copy(buffer, curLine); break; case Format.BGRA: copyRGBAtoBGRA(buffer, curLine); break; case Format.RGB: copyRGBAtoRGB(buffer, curLine); break; default: throw new UnsupportedOperationException("Unsupported format for this image"); } break; case COLOR_GREYSCALE: switch (fmt) { case Format.LUMINANCE: case Format.ALPHA: copy(buffer, curLine); break; default: throw new UnsupportedOperationException("Unsupported format for this image"); } break; case COLOR_GREYALPHA: switch (fmt) { case Format.LUMINANCE_ALPHA: copy(buffer, curLine); break; default: throw new UnsupportedOperationException("Unsupported format for this image"); } break; case COLOR_INDEXED: switch (bitdepth) { case 8: palLine = curLine; break; case 4: expand4(curLine, palLine); break; case 2: expand2(curLine, palLine); break; case 1: expand1(curLine, palLine); break; default: throw new UnsupportedOperationException("Unsupported bitdepth for this image"); } switch (fmt) { case Format.ABGR: copyPALtoABGR(buffer, palLine); break; case Format.RGBA: copyPALtoRGBA(buffer, palLine); break; case Format.BGRA: copyPALtoBGRA(buffer, palLine); break; default: throw new UnsupportedOperationException("Unsupported format for this image"); } break; default: throw new UnsupportedOperationException("Not yet implemented"); } byte[] tmp = curLine; curLine = prevLine; prevLine = tmp; } } finally { inflater.End(); } }
/// <summary> /// Decode the given source using the character set. /// </summary> protected virtual CharBuffer Decode(ByteBuffer source) { const string replaceWith = "?"; var encoder = charSet.NewDecoder() .OnMalformedInput(CodingErrorAction.REPLACE) .OnUnmappableCharacter(CodingErrorAction.REPLACE) .ReplaceWith(replaceWith); return encoder.Decode(source); }
public static void BufferData(/* final */ GL11 pGL11, /* final */ ByteBuffer pByteBuffer, /* final */ int pUsage) { pGL11.GlBufferData(GL11Consts.GlArrayBuffer, pByteBuffer.Capacity(), pByteBuffer, pUsage); }