- CssSpriteGenerator.zip
- Code
- CssSpriteGenerator.sln
- CssSpriteGenerator.suo
- CssSpriteGenerator.vssscc
- CssSpriteGenerator
- DemoSite_AutoResized
- DemoSite_CombineAndMinify
- ___generated
- Bin
- CombineAndMinify.dll
- CombineAndMinify.pdb
- CssSpriteGenerator.dll
- CssSpriteGenerator.pdb
- EcmaScript.NET.modified.dll
- Yahoo.Yui.Compressor.dll
- DemoSite_CompressedJpeg
- DemoSite_CompressedPng
- DemoSite_CssBackgroundImages
- App_Browsers
- PageAdapter.browser
- Bin
- CssSpriteGenerator.dll
- CssSpriteGenerator.pdb
- css
- images
- button-green-left.png
- button-green-right.png
- button-green-w100.png
- button-orange-left.png
- button-orange-right.png
- button-orange-w100.png
- gradient-hor-blue-w20h1.png
- gradient-hor-green-w20h1.png
- gradient-vert-blue-w1h20.png
- gradient-vert-green-w1h20.png
- gradient-vert-lightblue-w1h10.png
- gradient-vert-orange-w1h10.png
- site.css
- Default.aspx
- Default.aspx.cs
- web.config
- DemoSite_Database
- DemoSite_DefaultConfig
- App_Browsers
- PageAdapter.browser
- Bin
- CssSpriteGenerator.dll
- CssSpriteGenerator.pdb
- Default.aspx
- Default.aspx.cs
- images
- band-4bits.png
- cart.png
- circles-8bits.gif
- contactus.png
- dragonboats-thumbnail1.jpg
- dragonboats-thumbnail2.jpg
- dragonboats-thumbnail3.jpg
- print.png
- rectangles-4bits.png
- smallrectangles-4bits.png
- web.config
- DemoSite_FolderImages
- DemoSite_Gallery
- DemoSite_QuickStart
- App_Browsers
- PageAdapter.browser
- Bin
- CssSpriteGenerator.dll
- CssSpriteGenerator.pdb
- Default.aspx
- Default.aspx.cs
- images
- 200x200.png
- 90x90.gif
- 90x90.jpg
- 90x90.png
- photos
- vanuatu2.JPG
- web.config
- CssSpriteGenerator.zip
|
using System;
using System.Drawing.Imaging;
namespace SimplePaletteQuantizer.Extensions
{
/// <summary>
/// The utility extender class.
/// </summary>
public static partial class Extend
{
/// <summary>
/// Gets the bit count for a given pixel format.
/// </summary>
/// <param name="pixelFormat">The pixel format.</param>
/// <returns>The bit count.</returns>
public static Byte GetBitDepth(this PixelFormat pixelFormat)
{
switch (pixelFormat)
{
case PixelFormat.Format1bppIndexed:
return 1;
case PixelFormat.Format4bppIndexed:
return 4;
case PixelFormat.Format8bppIndexed:
return 8;
case PixelFormat.Format16bppArgb1555:
case PixelFormat.Format16bppGrayScale:
case PixelFormat.Format16bppRgb555:
case PixelFormat.Format16bppRgb565:
return 16;
case PixelFormat.Format24bppRgb:
return 24;
case PixelFormat.Format32bppArgb:
case PixelFormat.Format32bppPArgb:
case PixelFormat.Format32bppRgb:
return 32;
case PixelFormat.Format48bppRgb:
return 48;
case PixelFormat.Format64bppArgb:
case PixelFormat.Format64bppPArgb:
return 64;
default:
String message = string.Format("A pixel format '{0}' not supported!", pixelFormat);
throw new NotSupportedException(message);
}
}
/// <summary>
/// Gets the available color count for a given pixel format.
/// </summary>
/// <param name="pixelFormat">The pixel format.</param>
/// <returns>The available color count.</returns>
public static UInt16 GetColorCount(this PixelFormat pixelFormat)
{
// checks whether a pixel format is indexed, otherwise throw an exception
if (!pixelFormat.IsIndexed())
{
String message = string.Format("Cannot retrieve color count for a non-indexed format '{0}'.", pixelFormat);
throw new NotSupportedException(message);
}
switch (pixelFormat)
{
case PixelFormat.Format1bppIndexed:
return 2;
case PixelFormat.Format4bppIndexed:
return 16;
case PixelFormat.Format8bppIndexed:
return 256;
default:
String message = string.Format("A pixel format '{0}' not supported!", pixelFormat);
throw new NotSupportedException(message);
}
}
/// <summary>
/// Gets the friendly name of the pixel format.
/// </summary>
/// <param name="pixelFormat">The pixel format.</param>
/// <returns></returns>
public static String GetFriendlyName(this PixelFormat pixelFormat)
{
switch (pixelFormat)
{
case PixelFormat.Format1bppIndexed:
return "Indexed (2 colors)";
case PixelFormat.Format4bppIndexed:
return "Indexed (16 colors)";
case PixelFormat.Format8bppIndexed:
return "Indexed (256 colors)";
case PixelFormat.Format16bppGrayScale:
return "Grayscale (65536 shades)";
case PixelFormat.Format16bppArgb1555:
return "Highcolor + Alpha mask (32768 colors)";
case PixelFormat.Format16bppRgb555:
case PixelFormat.Format16bppRgb565:
return "Highcolor (65536 colors)";
case PixelFormat.Format24bppRgb:
return "Truecolor (24-bit)";
case PixelFormat.Format32bppArgb:
case PixelFormat.Format32bppPArgb:
return "Truecolor + Alpha (32-bit)";
case PixelFormat.Format32bppRgb:
return "Truecolor (32-bit)";
case PixelFormat.Format48bppRgb:
return "Truecolor (48-bit)";
case PixelFormat.Format64bppArgb:
case PixelFormat.Format64bppPArgb:
return "Truecolor + Alpha (64-bit)";
default:
String message = string.Format("A pixel format '{0}' not supported!", pixelFormat);
throw new NotSupportedException(message);
}
}
/// <summary>
/// Determines whether the specified pixel format is indexed.
/// </summary>
/// <param name="pixelFormat">The pixel format.</param>
/// <returns>
/// <c>true</c> if the specified pixel format is indexed; otherwise, <c>false</c>.
/// </returns>
public static Boolean IsIndexed(this PixelFormat pixelFormat)
{
return (pixelFormat & PixelFormat.Indexed) == PixelFormat.Indexed;
}
/// <summary>
/// Determines whether the specified pixel format is supported.
/// </summary>
/// <param name="pixelFormat">The pixel format.</param>
/// <returns>
/// <c>true</c> if the specified pixel format is supported; otherwise, <c>false</c>.
/// </returns>
public static Boolean IsSupported(this PixelFormat pixelFormat)
{
switch (pixelFormat)
{
case PixelFormat.Format1bppIndexed:
case PixelFormat.Format4bppIndexed:
case PixelFormat.Format8bppIndexed:
case PixelFormat.Format16bppArgb1555:
case PixelFormat.Format16bppRgb555:
case PixelFormat.Format16bppRgb565:
case PixelFormat.Format24bppRgb:
case PixelFormat.Format32bppArgb:
case PixelFormat.Format32bppPArgb:
case PixelFormat.Format32bppRgb:
case PixelFormat.Format48bppRgb:
case PixelFormat.Format64bppArgb:
case PixelFormat.Format64bppPArgb:
return true;
default:
return false;
}
}
/// <summary>
/// Determines whether the specified pixel format has an alpha channel.
/// </summary>
/// <param name="pixelFormat">The pixel format.</param>
/// <returns>
/// <c>true</c> if the specified pixel format has an alpha channel; otherwise, <c>false</c>.
/// </returns>
public static Boolean HasAlpha(this PixelFormat pixelFormat)
{
return (pixelFormat & PixelFormat.Alpha) == PixelFormat.Alpha ||
(pixelFormat & PixelFormat.PAlpha) == PixelFormat.PAlpha;
}
/// <summary>
/// Determines whether [is deep color] [the specified pixel format].
/// </summary>
/// <param name="pixelFormat">The pixel format.</param>
/// <returns>
/// <c>true</c> if [is deep color] [the specified pixel format]; otherwise, <c>false</c>.
/// </returns>
public static Boolean IsDeepColor(this PixelFormat pixelFormat)
{
switch (pixelFormat)
{
case PixelFormat.Format16bppGrayScale:
case PixelFormat.Format48bppRgb:
case PixelFormat.Format64bppArgb:
case PixelFormat.Format64bppPArgb:
return true;
default:
return false;
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Twitter: @MattPerdeck
LinkedIn: au.linkedin.com/in/mattperdeck
Current project:
JSNLog JavaScript Logging Package
Matt has over 9 years .NET and SQL Server development experience. Before getting into .Net, he worked on a number of systems, ranging from the largest ATM network in The Netherlands to embedded software in advanced Wide Area Networks and the largest ticketing web site in Australia. He has lived and worked in Australia, The Netherlands, Slovakia and Thailand.
He is the author of the book ASP.NET Performance Secrets (www.amazon.com/ASP-NET-Site-Performance-Secrets-Perdeck/dp/1849690685) in which he shows in clear and practical terms how to quickly find the biggest bottlenecks holding back the performance of your web site, and how to then remove those bottlenecks. The book deals with all environments affecting a web site - the web server, the database server and the browser.
Matt currently lives in Sydney, Australia. He recently worked at Readify and the global professional services company PwC. He now works at SP Health, a global provider of weight loss web sites such at CSIRO's TotalWellBeingDiet.com and BiggestLoserClub.com.