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

mxcpcJPEGSequenceWriter_win.cpp

Go to the documentation of this file.
00001 //           ///          //                                        Mx clientSDK
00002 //          /////        ////                    Mx Crossplatform Client Library
00003 //         /// XXX     XXX ///
00004 //        ///    XXX XXX    ///     $RCSfile: mxcpcJPEGSequenceWriter_win.cpp,v $
00005 //       ///       XXX       ///     $Revision: 1.1 $
00006 //      ///      XXX XXX      ///     $Date: 2005/12/14 10:38:52 $
00007 //     ////    XXX     XXX    ////     $Author: cvs-kai $
00008 //    ////                     ////
00009 //   ////  M  O  B  O  T  I  X  ////////////////////////////////////////////////
00010 //  //// Security Vision Systems //////////////////////////////////////////////
00011 //                                                                          //
00012 //  Copyright (C) 2005 - 2006, MOBOTIX AG, Germany                         //
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 
00018 
00019 
00020 #include <mxcpcJPEGSequenceWriter.h>
00021 
00022 #include <cstdio>
00023 #include <cstring>
00024 #include <memory>
00025 
00026 
00027 
00028 /*! 
00029  *  \file mxcpcJPEGSequenceWriter_win.cpp
00030  *
00031  *  \brief Alternate implementation for the <tt>WINDOWS</tt> platform
00032  * 
00033  *  Differs from the original <tt>POSIX</tt>-dependent implementation in that 
00034  *  we explicitly have to request binary mode when doing an <tt>open()</tt> or
00035  *  <tt>fopen()</tt> to avoid having our carriage returns (13s) implicitly 
00036  *  toasted.
00037  */
00038 
00039 
00040  
00041 mxcpcJPEGSequenceWriter::mxcpcJPEGSequenceWriter(const char *filename_prefix) {
00042 
00043   int prefix_len;
00044 
00045   prefix_len = std::strlen(filename_prefix);
00046   
00047   FileNamePrefix = 0;
00048   FileName       = 0;
00049   
00050   try {
00051     
00052     FileNamePrefix = new char[prefix_len + 1];
00053     FileName       = new char[prefix_len + 20 + 1];
00054                            // so we can append a sequence number...
00055   
00056   } catch(std::bad_alloc) {
00057     
00058       delete[] FileNamePrefix;
00059       delete[] FileName;
00060       
00061       throw;
00062     }
00063     
00064   std::strcpy(FileNamePrefix, filename_prefix);
00065 
00066   OutFile = 0;
00067   FrameNum = 0;
00068   
00069   ErrorEncountered = false;
00070 }
00071 
00072 
00073 mxcpcJPEGSequenceWriter::~mxcpcJPEGSequenceWriter() {
00074 
00075   delete[] FileNamePrefix;
00076   delete[] FileName;
00077   
00078   if(OutFile) std::fclose(OutFile);
00079 }
00080 
00081 
00082 void mxcpcJPEGSequenceWriter::beginFrame(void) {
00083 
00084   if(OutFile) {   // being paranoid
00085     
00086     std::fclose(OutFile);
00087     OutFile = 0;
00088     
00089     ErrorEncountered = true;
00090   }
00091   
00092   std::sprintf(FileName, "%s%06d.jpg", FileNamePrefix, FrameNum);
00093   
00094   OutFile = std::fopen(FileName, "wb");
00095   if(!OutFile) ErrorEncountered = true;
00096 }
00097 
00098 
00099 void mxcpcJPEGSequenceWriter::endFrame(void) {
00100 
00101   if(OutFile) std::fclose(OutFile);
00102   
00103   OutFile = 0;
00104   
00105   FrameNum++;
00106 }
00107   
00108 
00109 void mxcpcJPEGSequenceWriter::receiveJPEGBytes(const mxcpc::u8 *buffer, 
00110                                                int num)                 {
00111 
00112   if(!OutFile) {
00113   
00114     ErrorEncountered = true;
00115     return;
00116   }
00117   
00118   if(num < 1) {
00119     
00120     ErrorEncountered = true;  
00121   
00122     return;
00123   }
00124   
00125   if(fwrite(buffer, num, 1, OutFile) != 1) {
00126     
00127     std::fclose(OutFile);
00128     OutFile = 0;
00129     
00130     ErrorEncountered = true;
00131   }
00132 }

Generated on Fri Jan 20 13:33:33 2006 for mxcpc by  doxygen 1.4.4