arsd.color

  • Declaration

    struct Color;

    Represents an RGBA color

    • Declaration

      ubyte[4] components;

      [r, g, b, a]

      Discussion

      The color components are available as a static array, individual bytes, and a uint inside this union. Since it is anonymous, you can use the inner members' names directly.

    • r

      Declaration

      ubyte r;

      red

      Discussion

      Holder for rgba individual components. The color components are available as a static array, individual bytes, and a uint inside this union. Since it is anonymous, you can use the inner members' names directly.

    • g

      Declaration

      ubyte g;

      green

      Discussion

      Holder for rgba individual components. The color components are available as a static array, individual bytes, and a uint inside this union. Since it is anonymous, you can use the inner members' names directly.

    • b

      Declaration

      ubyte b;

      blue

      Discussion

      Holder for rgba individual components. The color components are available as a static array, individual bytes, and a uint inside this union. Since it is anonymous, you can use the inner members' names directly.

    • a

      Declaration

      ubyte a;

      alpha. 255 == opaque

      Discussion

      Holder for rgba individual components. The color components are available as a static array, individual bytes, and a uint inside this union. Since it is anonymous, you can use the inner members' names directly.

    • Declaration

      uint asUint;

      The components as a single 32 bit value (beware of endian issues!)

      Discussion

      The color components are available as a static array, individual bytes, and a uint inside this union. Since it is anonymous, you can use the inner members' names directly.

    • Declaration

      static pure nothrow @safe Color fromIntegers(int red, int green, int blue, int alpha = 255);

      Like the constructor, but this makes sure they are in range before casting. If they are out of range, it saturates: anything less than zero becomes zero and anything greater than 255 becomes 255.

    • Declaration

      pure nothrow @nogc @safe this(int red, int green, int blue, int alpha = 255);

      Construct a color with the given values. They should be in range 0 <= x <= 255, where 255 is maximum intensity and 0 is minimum intensity.

    • Declaration

      static pure nothrow @nogc @safe Color transparent();
      static pure nothrow @nogc @safe Color white();
      static pure nothrow @nogc @safe Color black();
      static pure nothrow @nogc @safe Color red();
      static pure nothrow @nogc @safe Color green();
      static pure nothrow @nogc @safe Color blue();
      static pure nothrow @nogc @safe Color yellow();
      static pure nothrow @nogc @safe Color teal();
      static pure nothrow @nogc @safe Color purple();

      Static convenience functions for common color names

    • Declaration

      Color toBW()();

      Return black-and-white color

    • Declaration

      const @safe string toCssString();

      Makes a string that matches CSS syntax for websites

    • Declaration

      const @safe string toString();

      Makes a hex string RRGGBBAA (aa only present if it is not 255)

    • Declaration

      const @safe string toRgbaHexString();

      returns RRGGBBAA, even if a== 255

    • Declaration

      static @safe Color fromNameString(string s);

      Gets a color by name, iff the name is one of the static members listed above

    • Declaration

      static @safe Color fromString(string s);

      Reads a CSS style string to get the color. Understands #rrggbb, rgba(), hsl(), and rrggbbaa

    • Declaration

      static @safe Color fromHsl(real h, real s, real l);

      from hsl

  • Declaration

    @safe Color fromHsl(real[3] hsl);

    Converts hsl to rgb

  • Declaration

    @safe Color fromHsl(real h, real s, real l, real a = 255);

    Converts hsl to rgb

  • Declaration

    @safe real[3] toHsl(Color c, bool useWeightedLightness = false);

    Converts an RGB color into an HSL triplet. useWeightedLightness will try to get a better value for luminosity for the human eye, which is more sensitive to green than red and more to red than blue. If it is false, it just does average of the rgb.

  • Declaration

    @safe Color lighten(Color c, real percentage);

    .

  • Declaration

    @safe Color darken(Color c, real percentage);

    .

  • Declaration

    @safe Color moderate(Color c, real percentage);

    for light colors, call darken. for dark colors, call lighten.

    Discussion

    The goal: get toward center grey.

  • Declaration

    @safe Color extremify(Color c, real percentage);

    the opposite of moderate. Make darks darker and lights lighter

  • Declaration

    @safe Color oppositeLightness(Color c);

    Move around the lightness wheel, trying not to break on moderate things

  • Declaration

    @safe Color makeTextColor(Color c);

    Try to determine a text color - either white or black - based on the input

  • Declaration

    @safe Color rotateHue(Color c, real degrees);

  • Declaration

    @safe Color setHue(Color c, real hue);

  • Declaration

    @safe Color desaturate(Color c, real percentage);

  • Declaration

    @safe Color saturate(Color c, real percentage);

  • Declaration

    @safe Color setSaturation(Color c, real saturation);

  • Declaration

    @safe ubyte unalpha(ubyte colorYouHave, float alpha, ubyte backgroundColor);

  • Declaration

    @safe ubyte makeAlpha(ubyte colorYouHave, ubyte backgroundColor);

  • Declaration

    @safe Color colorFromString(string s);

  • Declaration

    interface MemoryImage;

    This provides two image classes and a bunch of functions that work on them.

    Discussion

    Why are they separate classes? I think the operations on the two of them are necessarily different. There's a whole bunch of operations that only really work on truecolor (blurs, gradients), and a few that only work on indexed images (palette swaps). Even putpixel is pretty different. On indexed, it is a palette entry's index number. On truecolor, it is the actual color. A greyscale image is the weird thing in the middle. It is truecolor, but fits in the same size as indexed. Still, I'd say it is a specialization of truecolor. There is a subset that works on both An image in memory

    • Declaration

      abstract @safe TrueColorImage getAsTrueColorImage();

      gets it as a TrueColorImage. May return this or may do a conversion and return a new image

    • Declaration

      abstract const @safe int width();

      Image width, in pixels

    • Declaration

      abstract const @safe int height();

      Image height, in pixels

    • Declaration

      abstract const @safe Color getPixel(int x, int y);

      Get image pixel. Slow, but returns valid RGBA color (completely transparent for off-image pixels).

    • Declaration

      abstract @safe void setPixel(int x, int y, in Color clr);

      Set image pixel.

    • Declaration

      @trusted MemoryImage fromImage(T : const(char)[])(T filename);

      Load image from file. This will import arsd.png and arsd.jpeg to do the actual work, and cost nothing if you don't use it.

  • Declaration

    class IndexedImage: arsd.color.MemoryImage;

    An image that consists of indexes into a color palette. Use [getAsTrueColorImage]() if you don't care about palettes

    • Declaration

      Color[] palette;

      .

    • Declaration

      ubyte[] data;

      the data as indexes into the palette. Stored left to right, top to bottom, no padding.

    • Declaration

      const @safe int width();

      .

    • Declaration

      const @safe int height();

      .

    • Declaration

      @safe this(int w, int h);

      .

    • Declaration

      @safe TrueColorImage getAsTrueColorImage();

      returns a new image

    • Declaration

      const @safe TrueColorImage convertToTrueColor();

      Creates a new TrueColorImage based on this data

    • Declaration

      @safe ubyte getOrAddColor(Color c);

      Gets an exact match, if possible, adds if not. See also: the findNearestColor free function.

    • Declaration

      const @safe int numColors();

      Number of colors currently in the palette (note: palette entries are not necessarily used in the image data)

    • Declaration

      @safe ubyte addColor(Color c);

      Adds an entry to the palette, returning its inded

  • Declaration

    class TrueColorImage: arsd.color.MemoryImage;

    An RGBA array of image data. Use the free function quantize() to convert to an IndexedImage

    • Declaration

      struct Data;

      .

      • Declaration

        ubyte[] bytes;

        the data as rgba bytes. Stored left to right, top to bottom, no padding.

      • Declaration

        inout @property @trusted inout(Color)[] colors();

        the same data as Color structs

    • Declaration

      Data imageData;

      .

    • Declaration

      const @safe int width();

      .

    • Declaration

      const @safe int height();

      .

    • Declaration

      @safe this(int w, int h);

      .

    • Declaration

      @safe this(int w, int h, ubyte[] data);

      Creates with existing data. The data pointer is stored here.

    • Declaration

      @safe TrueColorImage getAsTrueColorImage();

      Returns this

  • Declaration

    @safe IndexedImage quantize(in TrueColorImage img, Color[] palette = null, in int maxColors = 256);

    Converts true color to an indexed image. It uses palette as the starting point, adding entries

    Discussion

    until maxColors as needed. If palette is null, it creates a whole new palette. After quantizing the image, it applies a dithering algorithm. This is not written for speed.

  • Declaration

    @safe ubyte findNearestColor(in Color[] palette, in Color pixel);

    Finds the best match for pixel in palette (currently by checking for minimum euclidean distance in rgb colorspace)

  • Declaration

    @safe void floydSteinbergDither(IndexedImage img, in TrueColorImage original);

    Dithers img in place to look more like original.

  • Declaration

    struct Point;

    • x

      Declaration

      int x;

    • y

      Declaration

      int y;

  • Declaration

    struct Size;

    • Declaration

      int width;

    • Declaration

      int height;

  • Declaration

    struct Rectangle;

    • Declaration

      int left;

    • top

      Declaration

      int top;

    • Declaration

      int right;

    • Declaration

      int bottom;