greenhouse
a creative coding toolkit for spatial interfaces

ImageData

ImageData is the raw data representation of an image – it’s a field of pixels. Unlike most objects in Greenhouse, it has no spatial characteristics of its own. It’s just pixel data.

ImageData objects have some basic methods of their own; there are also some helper functions in Greenhouse for working with ImageData. They are kept in the Image class, as public static methods. Call these methods as (e.g.):

  Image::FetchImageData(...)
  • FetchImageData ()
  • BlankImageData ()
  • ImageDataAspect ()
  • Height ()
  • Width ()
  • ImageDataFromIngest ()

Example

#include "Greenhouse.h"

class Im  :  public Image
{ public:

  Protein p;

  Im (Str i)  :  Image (i)
    { SetFireTimer (4, 2);
      SlapOnFeld ();
      Tag ("first-time");

      //  Preserves aspect ratio
      SetDiagonal (100);
    }

  void Fired ()
  {if (HasTag ("first-time"))
      { //  Get some different ImageData
        if (ImageData *heart_data = Image::FetchImageData ("images/heart.png"))
          { //  Pack the old (oblong_ob.png) image data into a protein
            AppendIngest (p, "ob_data", Data ());

            //  Change the image we're showing; we take the aspect ratio
            //  of the new image automatically
            SetImage (heart_data);

            INFORM ("aspect ratio of heart = " +
                    ToStr (Image::ImageDataAspect (heart_data)));
            INFORM ("heart_data size in pixels! [" +
                    ToStr (heart_data -> Width ()) + " x " +
                    ToStr (heart_data -> Height ()) + "]");

            //  Go small (but keep aspect ratio)
            SetWidthUniformly (50);

            UnTag ("first-time");
          }
      }
    else if (ImageData *ob_data = ImageDataFromIngest (p, "ob_data"))
      { //  Change image back to the ob
        SetImage (ob_data);

        INFORM ("aspect ratio of ob = " +
                ToStr (Image::ImageDataAspect(ob_data)));

        //  Size back to original diagonal size
        SetDiagonal (100);
      }
  }
};

void Setup ()
{ new Im ("images/oblong_ob.png"); }