Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members

mxcpcJPEGSequenceWriter.cpp

00001 //           ///          //
00002 //          /////        ////
00003 //         /// XXX     XXX ///
00004 //        ///    XXX XXX    ///     $RCSfile: mxcpcJPEGSequenceWriter.cpp,v $  
00005 //       ///       XXX       ///     $Revision: 1.2 $
00006 //      ///      XXX XXX      ///     $Date: 2005/08/09 13:57:26 $
00007 //     ////    XXX     XXX    ////     $Author: cvs-steve $
00008 //    ////                     ////
00009 //   ////  M  O  B  O  T  I  X  ////////////////////////////////////////////////
00010 //  //// Security Vision Systems ///////////////////////////////////////////////
00011 
00012 // Copyright (c) 2005, MOBOTIX AG.
00013 // This software is made available under the BSD licence. Please refer 
00014 // to the file LICENCE.TXT contained in this distribution for details.
00015 
00016 
00017 #include <mxcpcJPEGSequenceWriter.h>
00018 
00019 #include <cstdio>
00020 #include <cstring>
00021 #include <memory>
00022 
00023 
00024 
00025 mxcpcJPEGSequenceWriter::mxcpcJPEGSequenceWriter(const char *filename_prefix) {
00026 
00027   int prefix_len;
00028 
00029   prefix_len = std::strlen(filename_prefix);
00030   
00031   FileNamePrefix = 0;
00032   FileName       = 0;
00033   
00034   try {
00035     
00036     FileNamePrefix = new char[prefix_len + 1];
00037     FileName       = new char[prefix_len + 20 + 1];
00038                            // so we can append a sequence number...
00039   
00040   } catch(std::bad_alloc) {
00041     
00042       delete[] FileNamePrefix;
00043       delete[] FileName;
00044       
00045       throw;
00046     }
00047     
00048   std::strcpy(FileNamePrefix, filename_prefix);
00049 
00050   OutFile = 0;
00051   FrameNum = 0;
00052   
00053   ErrorEncountered = false;
00054 }
00055 
00056 
00057 mxcpcJPEGSequenceWriter::~mxcpcJPEGSequenceWriter() {
00058 
00059   delete[] FileNamePrefix;
00060   delete[] FileName;
00061   
00062   if(OutFile) std::fclose(OutFile);
00063 }
00064 
00065 
00066 void mxcpcJPEGSequenceWriter::beginFrame(void) {
00067 
00068   if(OutFile) {   // being paranoid
00069     
00070     std::fclose(OutFile);
00071     OutFile = 0;
00072     
00073     ErrorEncountered = true;
00074   }
00075   
00076   std::sprintf(FileName, "%s%06d.jpg", FileNamePrefix, FrameNum);
00077   
00078   OutFile = std::fopen(FileName, "w");
00079   if(!OutFile) ErrorEncountered = true;
00080 }
00081 
00082 
00083 void mxcpcJPEGSequenceWriter::endFrame(void) {
00084 
00085   if(OutFile) std::fclose(OutFile);
00086   
00087   OutFile = 0;
00088   
00089   FrameNum++;
00090 }
00091   
00092 
00093 void mxcpcJPEGSequenceWriter::receiveJPEGBytes(mxcpc::u8 *buffer, int num) {
00094 
00095   if(!OutFile) {
00096   
00097     ErrorEncountered = true;
00098     return;
00099   }
00100   
00101   if(num < 1) {
00102     
00103     ErrorEncountered = true;  
00104   
00105     return;
00106   }
00107   
00108   if(fwrite(buffer, num, 1, OutFile) != 1) {
00109     
00110     std::fclose(OutFile);
00111     OutFile = 0;
00112     
00113     ErrorEncountered = true;
00114   }
00115 }

Generated on Mon Aug 15 03:39:30 2005 for mxcpc by  doxygen 1.4.2-20050421