[Rework image export into state mashine Part I
Andreas Röver <roever@users.sourceforge.net>**20060222174704
 
 The image export can not be done in a thread, bu we need to do it
 in the draw function, but for that not to freeze the application
 we need to be able to do everything in small steps, this
 is the first part of this work
] {
hunk ./src/gui/Image.cpp 44
-Image::Image(unsigned int w, unsigned int h, unsigned char *b) : width(w), height(h), bitmap(b) { }
-
-Image::Image(unsigned int w, unsigned int h, ShadowView * dr) : width(w), height(h) {
+Image::Image(unsigned int w, unsigned int h) : width(w), height(h), tr(0) {
hunk ./src/gui/Image.cpp 46
+}
hunk ./src/gui/Image.cpp 48
-  TRcontext *tr = trNew();
+Image::Image(unsigned int w, unsigned int h, unsigned char *b) : width(w), height(h), bitmap(b) { }
hunk ./src/gui/Image.cpp 50
-  trTileSize(tr, dr->getView()->w(), dr->getView()->h(), 0);
-  trImageSize(tr, w, h);
-  trPerspective(tr, 25, (double)w/h, dr->getView()->getSize(), dr->getView()->getSize()+100);
+bool Image::getOpenGlImagePart(ShadowView * dr) {
hunk ./src/gui/Image.cpp 52
-  trImageBuffer(tr, GL_RGBA, GL_UNSIGNED_BYTE, bitmap);
+  if (!tr) {
+    tr = trNew();
hunk ./src/gui/Image.cpp 55
+    trTileSize(tr, dr->getView()->w(), dr->getView()->h(), 0);
+    trImageSize(tr, width, height);
+    trPerspective(tr, 25, (double)width/height, dr->getView()->getSize(), dr->getView()->getSize()+100);
+
+    trImageBuffer(tr, GL_RGBA, GL_UNSIGNED_BYTE, bitmap);
+  }
hunk ./src/gui/Image.cpp 88
-  do {
-    trBeginTile(tr);
-    dr->drawData();
+  trBeginTile(tr);
+  dr->drawData();
+
+  int result = trEndTile(tr);
+
+  if (!result) {
+    // we finished
hunk ./src/gui/Image.cpp 96
-  } while (trEndTile(tr));
+    // now flip vertically
+    for (unsigned int y = 0; y < height/2; y++)
+      for (unsigned int x = 0; x < width*4; x++) {
+        unsigned char tmp = bitmap[y*4*width+x];
+        bitmap[y*4*width+x] = bitmap[(height-y-1)*4*width+x];
+        bitmap[(height-y-1)*4*width+x] = tmp;
+      }
hunk ./src/gui/Image.cpp 104
-  // now flip vertically
-  for (unsigned int y = 0; y < h/2; y++)
-    for (unsigned int x = 0; x < w*4; x++) {
-      unsigned char tmp = bitmap[y*4*w+x];
-      bitmap[y*4*w+x] = bitmap[(h-y-1)*4*w+x];
-      bitmap[(h-y-1)*4*w+x] = tmp;
-    }
+    trDelete(tr);
+    tr = 0;
+  }
hunk ./src/gui/Image.cpp 108
-  trDelete(tr);
+  return (result != 0);
hunk ./src/gui/Image.h 33
+    TRcontext *tr;
hunk ./src/gui/Image.h 39
-    Image(unsigned int width, unsigned int height, ShadowView * dr);
+    Image(unsigned int width, unsigned int height);
hunk ./src/gui/Image.h 43
+    // returns true, as long as we need to call it again
+    bool getOpenGlImagePart(ShadowView * dr);
+
hunk ./src/gui/ImageExport.cpp 37
-      i = new Image(600, 200, dr);
+      i = new Image(600, 200);
+
+      while (i->getOpenGlImagePart(dr));
+
hunk ./src/gui/ImageExport.cpp 48
-      Image * i = new Image ((h*3)*aa, h*aa, dr);
+      Image * i = new Image ((h*3)*aa, h*aa);
+
+      while (i->getOpenGlImagePart(dr));
}
