itl_256

ITL is a C++ image library developed at Enseed Inc. that relies heavily on templates to define efficient image representation in system memory. Thanks to the power of C++ templates, a maximum of information can be used at compile time to facilitate the use of various image representations, minimize errors, maximize compatibility and yet leave little to no footprint at compile time.

Some of the abstractions in ITL include:

  • Abstraction from image orientations through smart row and column iterators.
  • Abstraction from color spaces (e.g. sRGB vs YCbCr-601).
  • Abstraction from component model (RGB vs CMY).
  • Abstraction from planar representation.
  • Abstraction from multiple pixel in a single packet (e.g. YCbCr422 or 1 bit black & white).
  • Abstraction from component range (e.g. with video YCbCr where 16/255 is black and 235/255 is white).
  • Abstraction from component ordering (an algorithm that works on RGB will also work on BGR).
  • Abstraction from component size (working with 1, 2, 4, 8, 16, 32, 64 bit components is all the same)

Structure

ITL can be used from four different levels:

  • itllayersImage: A template-less wrapper over the PixMap to simplify image manipulation.
  • PixelPacket:  A group of pixels sharing the same storage.
  • PixMap: A collection of PixelPacket representing an image.
  • Pixels: The smallest element of a picture.

Examples

Working with Pixels

Since the component ordering and the component size is abstracted, one can write a pixel loop that returns luminance from any RGB source, RGB pixel, whether it is 1, 8, 32 or 64 bit per components, and no matter if it is RGB, or BGR, no matter if it is packed or planar, and whether it also contains alpha or not:

template<class PIXELTYPE>
float LuminanceFromRGB(const PIXELTYPE &pixel)
{
    const float redMin = PIXELTYPE::RedStorageType::min();
    const float redMax = PIXELTYPE::RedStorageType::max();
    float red = (float(pixel->red()) -  redMin) / (redMax - redMin);

    const float greenMin = PIXELTYPE::GreenStorageType::min();
    const float green Max = PIXELTYPE::GreenStorageType::max();
    float green = (float(pixel->green()) -  greenMin) / (greenMax - greenMin);

    const float blueMin = PIXELTYPE::BlueStorageType::min();
    const float blue Max = PIXELTYPE::BlueStorageType::max();
    float blue = (float(pixel->blue()) -  blueMin) / (blueMax - blueMin);

    // Following CCIR-601 for luminance from RGB
    return red * 0.299 + green * 0.587 + blue * 0.114;
}

Since all ITL pixels have built-in conversion, the previous code can be shortened if you convert to a float RGB pixel:

template<class PIXELTYPE>
float LuminanceFromRGB(const PIXELTYPE &pixel)
{
    RGB32fPixel fPixel;
    fPixel.convert(pixel);

    // Following CCIR-601 for luminance from RGB
    return fPixel.red() * 0.299 + fPixel.green() * 0.587 + fPixel.blue() * 0.114;
}

And while we’re at it, there is a pixel type defined for luminance:

template<class PIXELTYPE>
float LuminanceFromRGB(const PIXELTYPE &pixel)
{
    Lum32fPixel lum;
    lum.convert(pixel);
    return lum.luminance();
}

Using template specialization, one can write several algorithm depending on the various details of the pixel. For instance, one could process pixels from one color space differently than pixels from another colorspace:

template<class PIXELTYPE, class COLORSPACE=PIXELTYPE::COLOR_SPACE>
void ProcessPixel(const PIXELTYPE &pixel);

template<class PIXELTYPE>
void ProcessPixel<PIXELTYPE, ColorSpace_sRGB>(const PIXELTYPE &pixel)
{ /* Process a pixel that is defined in the sRGB color space */ }

template<class PIXELTYPE>
void ProcessPixel<PIXELTYPE, ColorSpace_YCbCr601>(const PIXELTYPE &pixel)
{ /* Process a pixel that is defined in the YCbCr BT.601 color space */ }

// Calling ProcessPixel<PIXELTYPE>(pixel) will automatically choose the correct function.

Or process a pixel differently if it has an alpha component or not:

template<class PIXELTYPE, class HASALPHA=std::tr1::is_base_of<ComponentModel_Alpha, typename PIXELTYPE::ComponentModel>::value>
void ProcessPixel(const PIXELTYPE &pixel);

template<class PIXELTYPE, true>
void ProcessPixel(const PIXELTYPE &pixel)
{ /* process a pixel that has an alpha component - i.e. pixel.alpha() is valid */ }

template<class PIXELTYPE, false>
void ProcessPixel(const PIXELTYPE &pixel)
{
    // process a pixel that has does not have an alpha component
    // i.e. pixel.alpha() is invalid and would generate an error
}

// Calling ProcessPixel<PIXELTYPE>(pixel) will automatically choose the correct function.

Working with PixelPackets

Pixel packets are used when a single storage element holds multiple pixels. This
is the case, for instance, with YCbCr422 pixels or 1, 2 and 4 bit per component
pixels. In the case of a 1 bit b&w pixel, a single byte holds 8 pixels:

Lum1Pixel bw;
cout << "This packet holds " << Lum1Pixel::PIXEL_PER_PACKET << " pixels" << endl;
// This packet holds 8 pixels

Special care must be given to these types of pixels. They can be set in one call
(bw.setLuminance(1, 0, 0, 1, 1, 1, 1, 0);), but they must be read
individually:

int bw0 = bw.pixel0().luminance();
int bw1 = bw.pixel1().luminance();
int bw2 = bw.pixel2().luminance();
...

In the case of YCbCr422, you can thus access the two pixels like this:

YCbYCr8Pixel yuv422; // This is a Y-Cb-Y-Cr 422 pixel.  It actually holds 2 pixels
yuv422.setYCbYCr(255, 128, 192, 64);

RGB8Pixel rgb1;
rgb1.convert(yuv422.pixel0());

RGB8Pixel rgb2;
rgb2.convert(yuv422.pixel1());

In case you are wondering, pixel0 and pixel1 refer to the same address (same storage) but provide a different interpretation of the storage using a type cast.

Working with PixMap

PixMap can be iterated such that you do not have to worry whether they are top down or bottom up:

// an 8 bit RGB pixmap, the first pixel is at the bottom of the image
PixMap<RGB8Pixel, PixMapDrawsFromBottom> rgbPixMap(256, 256);

// an 8 bit RGB pixmap, the first pixel is at the top of the image
PixMap<RGB8Pixel, PixMapDrawsFromTop> rgbPixMap(256, 256);

// by default, an image is drawn from top (the most common case)
PixMap<RGB8Pixel> rgbPixMap(256, 256);

// Iterate in the native direction
PixMap<RGB8Pixel>::Iterator iter = rgbPixMap.begin();

// Iterate from top to bottom
PixMap<RGB8Pixel>::TopToBottomIterator iter = rgbPixMap.beginFromTop();

// Iterate from bottom to top
PixMap<RGB8Pixel>::BottomToTopIterator iter = rgbPixMap.beginFromBottom();

This is useful when you are dealing with two images and want to make sure you are iterating over them in the same direction. Iteration has been pixmaps simplified using functors. For instance, the following code would save any pixmap (RGB, YUV, CMYK, 1bbp, 8bbp, 64bbp, planar, packed, upside down, etc..) to a ppm file:

class SaveToPPM
{
public:
    SaveToPPM(FILE *file) : _file(file) {}
   
    template<class PIXELTYPE>
    void operator()(const PIXELTYPE &pixel) const
    {
        RGB8Pixel rgbPixel;
        rgbPixel.convert(pixel);
        fwrite(&rgbPixel, 3, 1, _file);
    }

private:
    FILE *_file;
};

PixMap<YCbYCr8Pixel> yuv422PixMap(512, 512);

FILE *f = fopen("img.ppm", "w");
fprintf(f, "P6\n%d %d 255\n", yuv422PixMap.width(), yuv422PixMap.height());
yuv422PixMap.forEachPixel(SaveToPPM(f));
f.close();
  • converter121
  • dancing211

    council216

  • download215
  • fiesta28

  • clothing122
  • flavor145

  • digital122
  • firmware93
  • drivers31
  • example16
  • download9
  • download206
  • ghetto206

    depot206

  • edmonton126
  • cover169
  • feline186
  • color33
  • elizabeth204
    death73
  • download129
  • found101

    death67

  • error118
  • florida188
  • corvette179

  • fotos99
  • dance204
  • college19

  • costume197
  • durham78

  • death68
  • florence172

    ghost210

    equipment102

  • download97
  • gallery62

  • dimensions129
  • hairstyles138

  • falcon122
  • edition119

    girlfriend2

    controller93

    dance197
    edition116
  • driver170
  • drivers5

  • credit56
  • download2
  • district4
  • department201
  • download138
  • guide66

    dictionary88

    gibson216

  • francis137
  • gratis125
  • guest42
  • cycles156
  • crack197

  • define91
  • final64
    groups12
  • clothing114
  • contact64
    guest31

    curve132

  • diving9
  • cornwall152

  • group219
  • display216
  • database5

  • greek143
  • construction55
  • gambar85
  • frozen191

  • coupons122
  • course132
  • furnace3
    fashion169
    county77

    download31

  • dwarf80
  • estate206
  • electrical178
  • eugene217
  • download94
  • grill173
  • fight30
  • england57
  • firmware96
    constellation46
    cleaner51
    corporation156
    eddie108
  • disney201
  • florida174
  • guild74
  • corporation170
  • county83

  • download56
  • exhaust54
  • download137
    flower209
    furniture38
  • drivers42
  • crest77

    force42

    dodge25
  • guitar105
  • gourmet74

    education137

    elementary193
    flying3

    designs25

    computer211

  • field21
  • estate141

  • frankie155
  • crown99
    green155
  • crack211
  • harmony179
  • death75

    elementary189
  • hands164
  • green158

    estate183

  • download92
  • crate15
  • exhaust47
  • download105

    download187

  • driver168
  • frank154

    dolls38

  • group0
  • construction48
  • guest39

    electric165

    corporate154

    groups10

  • dance200
  • gallery53
  • guide59

    clone103

    conversion101

  • groups15
  • demon172

    formula65

  • fence196
  • download216

    harley178

  • gallery76
  • guitar104
  • gallery57
  • golden54

  • elite200
  • georgia186
    flowers215

    generator163

  • david21
  • guest41
  • elementary188
  • gallery72

    deluxe166

    examples28

  • gazette148
  • custom136
  • football23
  • dealer61
    class32

    email215

    health215

    detroit37

  • distribution218
  • furniture21
  • estate143
  • convertible124
  • crack207
  • classifieds43
    colorado43
    colorado44
  • danielle0
  • grill175

    florida180

    college214
    custom143
    department198

    crack205

    department202

    collar178

  • comforter86
  • guest38
  • edition120

    franchise133
    cloth106
    crack210
    daniel216
  • disease187
  • download86

    ferry204

  • costume192
  • convert114
  • davis52
  • coupons124
  • corner149
  • georgia185
  • financial72

    directory155

    credit42

    fonts9

    college23

    dynasty83

    editor123

    download69

    english60

    death66
    elizabeth201
    express66
    college7
  • dodge34
  • email208
  • circus9
  • dream92
    download51
    company156

    download95

  • david25
  • cover167

    green159
    court153

    download145

    filter51
  • diagram63
  • group211

    garden132

    frank149

    consulting58

    frank150

  • drivers29
  • fiction20

    dosage55

    harbor168

  • future44
  • computers219

    forums92

  • french172
  • condominium21
  • drivers17
  • headphones209
    definition143

    formula64

    clown131

    edward138

    garden129
    doctor20
    control81

    corporation171

  • drivers11
  • drill117
  • county93
  • conference29

    device43
  • council219
  • german196

    facts108
  • download22
  • class25
  • closet105
  • drivers23

    coupon112

    florida189

    clock97
  • hairy140
  • header207
  • harvey197
  • digital124

  • cylinder160
  • definition108
    driver193
    happy165
  • comcast74
  • greek141
    download29

    elite197

  • forever49
  • email209

    folder6

  • epson92
  • collins25
  • doors52
  • extension76
  • furniture8

    funeral204

  • guidelines69
  • example17

  • download4
  • counter5
  • father173
    crack181
  • grass121
  • denver190
  • florida193
  • furniture6

  • factory105
  • download192
  • directory150

    costume199

    foundation111

  • driver181
  • grill183

    dublin68

    concept2

    daughter20

  • company151
  • grand103

  • guitar82
  • girls13
    garden126
    diego101
  • design6
  • engineer44
  • english64
  • diagram64
  • fishing117

    fiction17

    definition132

    download180

    disorder211
  • clips92
  • coral147

    community132
    falls128
  • danny2
  • garage114
  • egyptian164
  • crack193

  • corporation155
  • generic168
  • finance68
  • dress96

    definition144
  • gallery77
  • group218
  • download52
  • dishwasher199
  • clark23

  • google65
  • emulator13
  • guitar88
    download144
    court150

    forge51

    david31

  • david44
  • girls10
    employee9
    foods11
    girls7
  • computers1
  • drops59

    estate189

    exhaust50

    dallas195
  • engineering52
  • grill181
  • football32

    download191

    golden57

    dallas194

    curling123
  • crystal112
  • dance206

    edgar111
  • estate145
  • download60
  • county35
  • dairy178

    download39
  • dealers63
  • concert6
  • cobra148

  • gallery79
  • gifts218
  • county100
  • davis53

    delta165

  • county102
  • diego99
    employment10

    florida196

    commercial105

    drink120
    crazy17

    harris182

  • driver171
  • download183
  • coupon120

    derek213

  • enterprise74
  • comet82

    cruise103

    gallery55

    francisco144
    group4
    facts109

    dublin69

  • gallery80
  • circle4

    download19

    festival218

    craft1

    definition112

    deluxe169

    course144

    estate177

    games92
    discography164
    forest47
    classic35
  • davis51
  • county99

  • citizen14
  • genealogy151
  • error121

    fitness126

    group213
  • francisco145
  • download184

    files40

    golden59

    first106
  • couture159
  • evolution15
  • driver199

    generation158
    flowers214

    double62

    coach137

    eagle85

    guitar76

  • fishing124
  • consulting60

  • college218
  • estate168
    cookie128
  • classic34
  • cleaners56
  • dates11

  • guitar113
  • engine41

    essay137

    fanfic155

    dallas185
    gatlinburg142
    fireplace86
  • farms166
  • group201
  • company161
  • grill171
    county55

    hamilton150

    guitars123

    drivers20
    david34

    convert110

    directory152

    games101

    download3

    guard27

    executive40
  • color36
  • colon30
  • facebook96
  • estate159
  • drivers4
  • diego103

  • construction52
  • conversion98
    court148

    first107

  • digital121
  • cosmetic183
  • cisco12

    diamond69
    formation55
    creek72
    escape127

    hamilton148

    forums96

    factory103

  • costume193
  • dallas192

    fashion171

    civic17

    dream89

    estate195

    cream32