Exemplo n.º 1
0
            public TGAImage(GenericImage image)
            {
                IDLength     = 0;
                ColorMapType = 0;
                // currently only uncomrepssed export is supported
                ImageType            = 2;
                ColorMapOffset       = 0;
                ColorMapEntryCount   = 0;
                ColorMapBitsPerPixel = 0;
                XOrigin = 0;
                YOrigin = 0;
                Width   = (ushort)image.width;
                Height  = (ushort)image.height;
                int channelCount = (int)Math.Max(3, Math.Min(4, image.channels));

                BitsPerPixel    = (byte)(channelCount * 8);
                DiscriptioField = 0;
                ImageID         = new byte[0];
                ColorMap        = new byte[0];
                ImageData       = new byte[Width * Height * channelCount];
                for (int y = 0; y < Height; ++y)
                {
                    for (int x = 0; x < Width; ++x)
                    {
                        for (int c = 0; c < channelCount; ++c)
                        {
                            ImageData[c + channelCount * (x + y * Width)] = (byte)(image.GetPixelChannel(0, 0, 0, (uint)y, (uint)x, (uint)c) * 255);
                        }
                    }
                }
            }
Exemplo n.º 2
0
            protected override double ApplyFilter(uint x_, uint y_, uint z_, uint mipmap, uint layer, uint channel, ref GenericImage image)
            {
                uint x = (uint)Math.Max(1, ((int)image.width >> (int)mipmap));
                uint y = (uint)Math.Max(1, ((int)image.height >> (int)mipmap));
                uint z = (uint)Math.Max(1, ((int)image.depth >> (int)mipmap));

                uint x2 = (uint)Math.Max(1, ((int)image.width >> (int)(mipmap - 1)));
                uint y2 = (uint)Math.Max(1, ((int)image.height >> (int)(mipmap - 1)));
                uint z2 = (uint)Math.Max(1, ((int)image.depth >> (int)(mipmap - 1)));

                uint dX = x2 / x;
                uint dY = y2 / y;
                uint dZ = z2 / z;

                double value = 0;
                uint   count = 0;

                for (uint d = 0; d < dZ; ++d)
                {
                    for (uint h = 0; h < dY; ++h)
                    {
                        for (uint w = 0; w < dX; ++w)
                        {
                            ++count;
                            value += image.GetPixelChannel(mipmap - 1, layer, z_ * dZ + d, y_ * dY + h, x_ * dX + w, channel);
                        }
                    }
                }
                if (count > 0)
                {
                    return(value / count);
                }
                else
                {
                    return(0);
                }
            }