// 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);
        }
Example #2
0
        //-----------------------------------------------------------------------
        public void ILUtil.FromAxiom(PixelBox src)
        {
            // ilTexImage http://openil.sourceforge.net/docs/il/f00059.htm
            ILFormat ifmt = OgreFormat2ilFormat(src.format);

            if (src.isConsecutive() && ifmt.isValid())
            {
                // The easy case, the buffer is laid out in memory just like
                // we want it to be and is in a format DevIL can understand directly
                // We could even save the copy if DevIL would let us
                Il.ilTexImage(src.Width, src.Height, src.Depth, ifmt.numberOfChannels,
                              ifmt.format, ifmt.type, src.data);
            }
            else if (ifmt.isValid())
            {
                // The format can be understood directly by DevIL. The only
                // problem is that ilTexImage expects our image data consecutively
                // so we cannot use that directly.

                // Let DevIL allocate the memory for us, and copy the data consecutively
                // to its memory
                ilTexImage(static_cast <ILuint>(src.getWidth()),
                           static_cast <ILuint>(src.getHeight()),
                           static_cast <ILuint>(src.getDepth()), ifmt.numberOfChannels,
                           ifmt.format, ifmt.type, 0);
                PixelBox dst(src.getWidth(), src.getHeight(), src.getDepth(), src.format, ilGetData());

                PixelUtil::bulkPixelConversion(src, dst);
            }
            else
            {
                // Here it gets ugly. We're stuck with a pixel format that DevIL
                // can't do anything with. We will do a bulk pixel conversion and
                // then feed it to DevIL anyway. The problem is finding the best
                // format to convert to.

                // most general format supported by OGRE and DevIL
                PixelFormat fmt = PixelUtil::hasAlpha(src.format)?PF_FLOAT32_RGBA:PF_FLOAT32_RGB;

                // Make up a pixel format
                // We don't have to consider luminance formats as they have
                // straight conversions to DevIL, just weird permutations of RGBA an LA
                int depths[4];
Example #3
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
        }