+ return true;
+}
+
+// If false then suspension return
+bool WriteScanlines(struct jpeg_compress_struct &cinfo, void *input_buffer, int row_stride)
+{
+ JSAMPLE *image_buffer = (JSAMPLE*) input_buffer;
+ JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */
+ row_pointer[0] = image_buffer;
+
+ while (cinfo.next_scanline < cinfo.image_height) {
+ /* jpeg_write_scanlines expects an array of pointers to scanlines.
+ * Here the array is only one element long, but you could pass
+ * more than one scanline at a time if that's more convenient.
+ */
+ //row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride];
+
+ if( jpeg_write_scanlines(&cinfo, row_pointer, 1) != 1)
+ {
+ //entering suspension mode, basically we wrote the whole jpeg fragment
+ // technically we could enforce that by checkig the value of row_pointer to
+ // actually be at the end of the image...TODO
+ return false;
+ }
+ row_pointer[0] += row_stride;
+ }
+
+ // Well looks like we are done writting the scanlines
+ return true;
+}
+
+// input_buffer is ONE image
+// fragment_size is the size of this image (fragment)
+bool CreateOneFrame (std::ostream *fp, void *input_buffer, int fragment_size,
+ int image_width, int image_height, int numZ, int sample_pixel, int quality, JpegVector &v)
+{
+ struct jpeg_compress_struct cinfo;
+ int row_stride; /* physical row width in image buffer */
+ size_t beg = fp->tellp();
+ bool r = InitializeJpeg(fp, fragment_size, image_width, image_height,
+ sample_pixel, quality, cinfo, row_stride);
+ assert( r );
+ (void)numZ;
+
+ uint8_t *pbuffer = (uint8_t*)input_buffer;
+ //int i;
+ //for(i=0; i<numZ; ++i)
+// {
+ r = WriteScanlines(cinfo, pbuffer, row_stride);
+ assert( r );
+// pbuffer+=fragment_size; //shift to next image
+
+ //Upodate frag size
+// size_t end = fp->tellp();
+// std::cerr << "DIFF: " << end-beg << std::endl;
+
+// JpegPair &jp = v[i];
+// jp.second = end-beg;
+ //beg = end; //
+ // }
+
+ r = FinalizeJpeg(cinfo);
+ assert( r );
+ size_t end = fp->tellp();
+ static int i = 0;
+ JpegPair &jp = v[i];
+ jp.second = end-beg;
+ std::cerr << "DIFF: " << i <<" -> " << end-beg << std::endl;
+ ++i;
+
+ //JpegPair &jp = v[0];
+ //jp.second = 15328;