private ColourTable SetActiveColourTable() { ColourTable act; // active colour table if (_strategy == ColourTableStrategy.UseLocal) { if (_quantizerType == QuantizerType.UseSuppliedPalette) { if (_frames[_encodingFrame].Palette == null) { // TESTME: SetActiveColourTable - SetActiveColourTable, UseSuppliedPalette, no palette supplied string message = "You have opted to use a local colour table built " + "from a supplied palette, but frame " + _encodingFrame + "does not have a palette."; throw new InvalidOperationException(message); } else { // Build local colour table from colours in the frame's // supplied palette. act = new ColourTable(); foreach (Color c in _frames[_encodingFrame].Palette) { act.Add(c); } act.Pad(); } } else { // Build local colour table based on colours in the image. Image thisImage = _frames[_encodingFrame].TheImage; _pixelAnalysis = new PixelAnalysis(thisImage, _quantizerType); _pixelAnalysis.ColourQuality = _quality; _pixelAnalysis.Analyse(); // make local colour table active act = _pixelAnalysis.ColourTable; } } else { // make global colour table active act = _globalColourTable; } return(act); }
/// <summary> /// Creates a colour table directly from the distinct colours in the /// supplied image(s). /// </summary> private void CreateDirectColourTable() { //AddCounter( buildColourTableCounterText, // _distinctColours.Values.Count ); _colourTable = new ColourTable(); int distinctColourIndex = 0; foreach (Color c in _distinctColours.Values) { //MyProgressCounters[buildColourTableCounterText].Value //= distinctColourIndex; _colourTable.Add(c); distinctColourIndex++; } _colourTable.Pad(); //RemoveCounter( buildColourTableCounterText ); }
/// <summary> /// Creates a colour table directly from the distinct colours in the /// supplied image(s). /// </summary> private void CreateDirectColourTable() { string buildColourTableCounterText = "Creating colour table from images"; AddCounter(buildColourTableCounterText, _distinctColours.Values.Count); _colourTable = new ColourTable(); int distinctColourIndex = 0; foreach (Color c in _distinctColours.Values) { MyProgressCounters[buildColourTableCounterText].Value = distinctColourIndex; _colourTable.Add(c); distinctColourIndex++; } _colourTable.Pad(); RemoveCounter(buildColourTableCounterText); }
/// <summary> /// Writes a Logical Screen Descriptor to the supplied stream. /// Also writes a global colour table if required. /// </summary> /// <param name="outputStream"> /// The stream to write to. /// </param> private void WriteLogicalScreenDescriptor(Stream outputStream) { bool hasGlobalColourTable = _strategy == ColourTableStrategy.UseGlobal; int colourResolution = 7; // TODO: parameterise colourResolution? bool globalColourTableIsSorted = false; // Sorting of colour tables is not currently supported int backgroundColorIndex = 0; // TODO: parameterise backgroundColourIndex? int pixelAspectRatio = 0; // TODO: parameterise pixelAspectRatio? if (_strategy == ColourTableStrategy.UseGlobal) { if (_quantizerType == QuantizerType.UseSuppliedPalette) { // use supplied palette _globalColourTable = new ColourTable(); //AddCounter( buildColourTableCounterText, // _palette.Count ); int paletteIndex = 0; foreach (Color c in _palette) { _globalColourTable.Add(c); //MyProgressCounters[buildColourTableCounterText].Value //= paletteIndex; paletteIndex++; } _globalColourTable.Pad(); //RemoveCounter( buildColourTableCounterText ); } else { // Analyse the pixels in all the images to build the // global colour table. Collection <Image> images = new Collection <Image>(); foreach (GifFrame thisFrame in _frames) { Image thisImage = thisFrame.TheImage; images.Add(thisImage); } _pixelAnalysis = new PixelAnalysis(images); _pixelAnalysis.ColourQuality = _quality; _pixelAnalysis.Analyse(); _globalColourTable = _pixelAnalysis.ColourTable; } LogicalScreenDescriptor lsd = new LogicalScreenDescriptor(_logicalScreenSize, hasGlobalColourTable, colourResolution, globalColourTableIsSorted, _globalColourTable.SizeBits, backgroundColorIndex, pixelAspectRatio); lsd.WriteToStream(outputStream); _globalColourTable.WriteToStream(outputStream); } else { LogicalScreenDescriptor lsd = new LogicalScreenDescriptor(_logicalScreenSize, hasGlobalColourTable, colourResolution, globalColourTableIsSorted, 7, backgroundColorIndex, pixelAspectRatio); lsd.WriteToStream(outputStream); } }