Beispiel #1
0
      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);
      }
Beispiel #2
0
        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();
            }
        }