added the capability to crudely resize images by half in image.cc
[laserbrain_demo] / src / image.cc
index c245212..e79073d 100644 (file)
@@ -143,6 +143,34 @@ void Image::rotate_180()
        flip_horizontal();
 }
 
+void Image::resize_half()
+{
+       int pixsz = pixel_size(fmt);
+       int newxsz = width / 2;
+       int newysz = height / 2;
+
+       if(!newxsz || !newysz) return;
+
+       unsigned char *newpix = new unsigned char[newxsz * newysz * pixsz];
+
+       unsigned char *sptr = (unsigned char*)pixels;
+       unsigned char *dptr = newpix;
+
+       for(int i=0; i<newysz; i++) {
+               if(i & 1) sptr += width * pixsz;
+               for(int j=0; j<newxsz; j++) {
+                       memcpy(dptr, sptr, pixsz);
+                       dptr += pixsz;
+                       sptr += pixsz * 2;
+               }
+       }
+
+       delete [] (char*)pixels;
+       pixels = newpix;
+       width = newxsz;
+       height = newysz;
+}
+
 bool Image::load(const char *fname)
 {
        struct img_pixmap pixmap;