using System;
using System.Diagnostics;
using System.Drawing;
namespace FreeImageAPI.Metadata
{
///
/// Provides additional information specific for GIF files. This class cannot be inherited.
///
public class GifInformation : MDM_ANIMATION
{
///
/// Initializes a new instance of the class
/// with the specified .
///
/// A reference to a instance.
public GifInformation(FreeImageBitmap bitmap)
: base(bitmap.Dib)
{
}
///
/// Gets or sets a value indicating whether this frame uses the
/// GIF image's global palette. If set to false, this
/// frame uses its local palette.
///
///
/// Handling of null values
/// A null value indicates, that the corresponding metadata tag is not
/// present in the metadata model.
/// Setting this property's value to a non-null reference creates the
/// metadata tag if necessary.
/// Setting this property's value to a null reference deletes the
/// metadata tag from the metadata model.
///
public bool? UseGlobalPalette
{
get
{
byte? useGlobalPalette = GetTagValue("NoLocalPalette");
return useGlobalPalette.HasValue ? (useGlobalPalette.Value != 0) : default(bool?);
}
set
{
byte? val = null;
if (value.HasValue)
{
val = (byte)(value.Value ? 1 : 0);
}
SetTagValue("NoLocalPalette", val);
}
}
///
/// Creates a global palette for the GIF image, intialized with all entries of the
/// current local palette.
/// The property will be set to true when
/// invoking this method. This effectively enables the newly created global palette.
///
///
/// The image does not have a palette.
///
public void CreateGlobalPalette()
{
CreateGlobalPalette(new Palette(dib));
}
///
/// Creates a global palette for the GIF image with the specified size, intialized
/// with the first entries of the current local palette.
/// The property will be set to true when
/// invoking this method. This effectively enables the newly created global palette.
///
/// The size of the newly created global palette.
///
/// is a null reference.
public void CreateGlobalPalette(int size)
{
CreateGlobalPalette(new Palette(dib), size);
}
///
/// Creates a global palette for the GIF image, intialized with the entries
/// of the specified palette.
/// The property will be set to true when
/// invoking this method. This effectively enables the newly created global palette.
///
/// The palette that contains the initial values for
/// the newly created global palette.
///
/// is a null reference.
public void CreateGlobalPalette(Palette palette)
{
if (palette == null)
{
throw new ArgumentNullException("palette");
}
GlobalPalette = palette;
UseGlobalPalette = true;
}
///
/// Creates a global palette for the GIF image with the specified size, intialized
/// with the first entries of the specified palette.
/// The property will be set to true when
/// invoking this method. This effectively enables the newly created global palette.
///
/// The palette that contains the initial values for
/// the newly created global palette.
/// The size of the newly created global palette.
///
/// is a null reference.
public void CreateGlobalPalette(Palette palette, int size)
{
if (palette == null)
{
throw new ArgumentNullException("palette");
}
if (size <= 0)
{
throw new ArgumentOutOfRangeException("size");
}
Palette pal = new Palette(size);
pal.CopyFrom(palette);
GlobalPalette = palette;
UseGlobalPalette = true;
}
}
}