00001
00002 #include "Dump.h"
00003 #include <fstream>
00004
00005 namespace FCam {
00006
00007 void saveDump(Frame::Ptr frame, std::string filename) {
00008 if (!frame->image.valid()) {
00009 fprintf(stderr, "Cannot save non-valid image\n");
00010 }
00011
00012 int frames = 1;
00013 int width = frame->image.size.width;
00014 int height = frame->image.size.height;
00015 int channels;
00016 int type;
00017 switch (frame->image.type) {
00018 case FCam::UYVY:
00019 type = 1;
00020 channels = 2;
00021 break;
00022 case FCam::RAW:
00023 type = 2;
00024 channels = 2;
00025 break;
00026 default:
00027 fprintf(stderr, "Don't know how to save a dump file for format %d\n", frame->image.type);
00028 return;
00029 }
00030 printf("Saving %s as a dump image with header: %d %d %d %d %d. KBytes %f\n", filename.c_str(),
00031 frames, width, height, channels, type, width*height*2/1024.);
00032 std::ofstream file(filename.c_str(), std::ios::binary | std::ios::out);
00033 if (!file.is_open()) {
00034 fprintf(stderr,"Unable to open file %s for writing\n", filename.c_str());
00035 return;
00036 }
00037
00038 file.write((char *)&frames, sizeof(int));
00039 file.write((char *)&width, sizeof(int));
00040 file.write((char *)&height, sizeof(int));
00041 file.write((char *)&channels, sizeof(int));
00042 file.write((char *)&type, sizeof(int));
00043 file.flush();
00044 printf("%d %d %d %d %d\n", frames, width, height, channels, type);
00045
00046 file.write((char *)frame->image.data, width*height*2);
00047
00048 file.close();
00049 }
00050
00051 }
00052