00001
00002
00003
00004
00005 template <unsigned int n>
00006 ImageBuffer<n>::ImageBuffer (unsigned int ndims[n]) {
00007 assert (n > 0);
00008 for (unsigned int i = 0; i < n; i ++) {
00009 dims[i] = ndims[i];
00010 assert (dims[i] > 0);
00011 }
00012 count[n] = 1;
00013 for (unsigned int i = n; i > 0; i --)
00014 count[i-1] = count[i] * dims[i-1];
00015 data = new Color[count[0]];
00017 assert (data != NULL);
00018 }
00019
00020 template <unsigned int n>
00021 unsigned int ImageBuffer<n>::getSize (unsigned int d) const {
00022 assert (d < n);
00023 return dims[d];
00024 }
00025
00026 template <unsigned int n>
00027 const Color& ImageBuffer<n>::getColor (unsigned int pos[n]) const {
00028 int offset = 0;
00029 for (unsigned int i = 0; i < n; i ++) {
00030 assert (pos[i] < dims[i]);
00031 offset += count[i+1] * pos[i];
00032 }
00033 return data[offset];
00034 }
00035
00036 template <unsigned int n>
00037 void ImageBuffer<n>::setColor (unsigned int pos[n], const Color &c) {
00038 int offset = 0;
00039 for (unsigned int i = 0; i < n; i ++) {
00040 assert (pos[i] < dims[i]);
00041 offset += count[i+1] * pos[i];
00042 }
00043 data[offset] = c;
00044 }