Beispiel #1
0
        public byte[] Read(Stream stream, out int x, out int y, out int comp, int req_comp)
        {
            _stream = stream;

            try
            {
                int xx, yy, ccomp;
                var result = Stb.stbi_load_from_callbacks(_callbacks, null, &xx, &yy, &ccomp, req_comp);

                x    = xx;
                y    = yy;
                comp = ccomp;

                if (result == null)
                {
                    throw new Exception(Stb.LastError);
                }

                // Convert to array
                var c    = req_comp != 0 ? req_comp : comp;
                var data = new byte[x * y * c];
                Marshal.Copy(new IntPtr(result), data, 0, data.Length);
                Operations.Free(result);

                return(data);
            }
            finally
            {
                _stream = null;
            }
        }