// TODO: Fix this to be like Ogre
        public override void EncodeToFile(Stream input, string fileName, object codecData)
        {
            int imageID;

            // create and bind a new image
            Il.ilGenImages(1, out imageID);
            Il.ilBindImage(imageID);

            byte[] buffer = new byte[input.Length];
            input.Read(buffer, 0, buffer.Length);

            ImageData data  = (ImageData)codecData;
            ILFormat  ilfmt = ILUtil.ConvertToILFormat(data.format);

            // stuff the data into the image
            Il.ilTexImage(data.width, data.height, 1, (byte)ilfmt.channels, ilfmt.format, ilfmt.type, buffer);

            if (data.flip)
            {
                // flip the image
                Ilu.iluFlipImage();
            }

            // save the image to file
            Il.ilSaveImage(fileName);

            // delete the image
            Il.ilDeleteImages(1, ref imageID);
        }
Exemple #2
0
        //-----------------------------------------------------------------------
        public static void ToAxiom(PixelBox dst)
        {
            if (!dst.Consecutive)
            {
                throw new NotImplementedException("Destination must currently be consecutive");
            }
            if (dst.Width != Il.ilGetInteger(Il.IL_IMAGE_WIDTH) ||
                dst.Height != Il.ilGetInteger(Il.IL_IMAGE_HEIGHT) ||
                dst.Depth != Il.ilGetInteger(Il.IL_IMAGE_DEPTH))
            {
                throw new AxiomException("Destination dimensions must equal IL dimension");
            }

            int ilfmt = Il.ilGetInteger(Il.IL_IMAGE_FORMAT);
            int iltp  = Il.ilGetInteger(Il.IL_IMAGE_TYPE);

            // Check if in-memory format just matches
            // If yes, we can just copy it and save conversion
            ILFormat ifmt = ILUtil.ConvertToILFormat(dst.Format);

            if (ifmt.format == ilfmt && ILabs(ifmt.type) == ILabs(iltp))
            {
                int size = Il.ilGetInteger(Il.IL_IMAGE_SIZE_OF_DATA);
                // Copy from the IL structure to our buffer
                PixelUtil.CopyBytes(dst.Data, dst.Offset, Il.ilGetData(), 0, size);
                return;
            }
            // Try if buffer is in a known OGRE format so we can use OGRE its
            // conversion routines
            PixelFormat bufFmt = ILUtil.ConvertFromILFormat(ilfmt, iltp);

            ifmt = ILUtil.ConvertToILFormat(bufFmt);

            if (ifmt.format == ilfmt && ILabs(ifmt.type) == ILabs(iltp))
            {
                // IL format matches another OGRE format
                PixelBox src = new PixelBox(dst.Width, dst.Height, dst.Depth, bufFmt, Il.ilGetData());
                PixelUtil.BulkPixelConversion(src, dst);
                return;
            }

#if NOT
            // The extremely slow method
            if (iltp == Il.IL_UNSIGNED_BYTE || iltp == Il.IL_BYTE)
            {
                ilToOgreInternal(static_cast <uint8 *>(dst.data), dst.format, (uint8)0x00, (uint8)0x00, (uint8)0x00, (uint8)0xFF);
            }
            else if (iltp == IL_FLOAT)
            {
                ilToOgreInternal(static_cast <uint8 *>(dst.data), dst.format, 0.0f, 0.0f, 0.0f, 1.0f);
            }
            else if (iltp == IL_SHORT || iltp == IL_UNSIGNED_SHORT)
            {
                ilToOgreInternal(static_cast <uint8 *>(dst.data), dst.format,
                                 (uint16)0x0000, (uint16)0x0000, (uint16)0x0000, (uint16)0xFFFF);
            }
            else
            {
                OGRE_EXCEPT(Exception::UNIMPLEMENTED_FEATURE,
                            "Cannot convert this DevIL type",
                            "ILUtil::ilToOgre");
            }
#else
            throw new NotImplementedException("Cannot convert this DevIL type");
#endif
        }