File rotate.patch of Package ZoneMinder
diff -U 3 -H -d -r -N -x '*~' -- ZoneMinder-1.22.3/src/zm_event.cpp ZoneMinder-1.22.3-patch/src/zm_event.cpp
--- ZoneMinder-1.22.3/src/zm_event.cpp 2006-05-24 15:51:50.000000000 +0200
+++ ZoneMinder-1.22.3-patch/src/zm_event.cpp 2007-02-06 17:59:56.000000000 +0100
@@ -397,7 +397,7 @@
}
}
-void Event::StreamEvent( int event_id, int frame_id, int scale, int rate, int maxfps )
+void Event::StreamEvent( int event_id, int frame_id, int scale, int rate, int maxfps, int rotate )
{
static char sql[BUFSIZ];
static char eventpath[PATH_MAX];
@@ -515,6 +515,8 @@
image.Scale( scale );
+ image.Rotate( rotate );
+
image.EncodeJpeg( buffer, &n_bytes );
}
fprintf( stdout, "--ZoneMinderFrame\r\n" );
@@ -546,7 +548,7 @@
#if HAVE_LIBAVCODEC
-void Event::StreamMpeg( int event_id, int frame_id, const char *format, int scale, int rate, int maxfps, int bitrate )
+void Event::StreamMpeg( int event_id, int frame_id, const char *format, int scale, int rate, int maxfps, int bitrate, int rotate )
{
static char sql[BUFSIZ];
static char eventpath[PATH_MAX];
@@ -645,6 +647,11 @@
image.Scale( scale );
}
+ if ( rotate != 0)
+ {
+ image.Rotate( rotate );
+ }
+
double temp_delta = ((id-last_id)*(db_delta-last_delta))/(db_id-last_id);
delta_ms = (unsigned int)((last_delta+temp_delta)*1000);
if ( rate != ZM_RATE_SCALE )
diff -U 3 -H -d -r -N -x '*~' -- ZoneMinder-1.22.3/src/zm_event.h ZoneMinder-1.22.3-patch/src/zm_event.h
--- ZoneMinder-1.22.3/src/zm_event.h 2006-05-25 16:02:38.000000000 +0200
+++ ZoneMinder-1.22.3-patch/src/zm_event.h 2007-02-06 17:59:35.000000000 +0100
@@ -116,9 +116,9 @@
void AddFrames( int n_frames, Image **images, struct timeval **timestamps );
void AddFrame( Image *image, struct timeval timestamp, int score=0, Image *alarm_frame=NULL );
- static void StreamEvent( int event_id, int frame_id, int scale=100, int rate=100, int maxfps=10 );
+ static void StreamEvent( int event_id, int frame_id, int scale=100, int rate=100, int maxfps=10, int rotate=0 );
#if HAVE_LIBAVCODEC
- static void StreamMpeg( int event_id, int frame_id, const char *format, int scale=100, int rate=100, int maxfps=10, int bitrate=100000 );
+ static void StreamMpeg( int event_id, int frame_id, const char *format, int scale=100, int rate=100, int maxfps=10, int bitrate=100000, int rotate=0 );
#endif // HAVE_LIBAVCODEC
public:
diff -U 3 -H -d -r -N -x '*~' -- ZoneMinder-1.22.3/src/zm_monitor.cpp ZoneMinder-1.22.3-patch/src/zm_monitor.cpp
--- ZoneMinder-1.22.3/src/zm_monitor.cpp 2006-11-16 12:34:53.000000000 +0100
+++ ZoneMinder-1.22.3-patch/src/zm_monitor.cpp 2007-02-06 18:03:41.000000000 +0100
@@ -438,7 +438,7 @@
return( shared_data->state );
}
-int Monitor::GetImage( int index, int scale ) const
+int Monitor::GetImage( int index, int scale, int rotate ) const
{
if ( index < 0 || index > image_buffer_count )
{
@@ -454,6 +454,10 @@
{
snap_image.Scale( scale );
}
+ if (rotate != 0)
+ {
+ snap_image.Rotate( rotate );
+ }
static char filename[PATH_MAX];
snprintf( filename, sizeof(filename), "%s.jpg", name );
@@ -2046,7 +2050,7 @@
return( monitor );
}
-void Monitor::StreamImages( int scale, int maxfps, time_t ttl )
+void Monitor::StreamImages( int scale, int maxfps, time_t ttl, int rotate )
{
fprintf( stdout, "Content-Type: multipart/x-mixed-replace;boundary=ZoneMinderFrame\r\n\r\n" );
@@ -2079,7 +2083,7 @@
struct DeltaTimeval delta_time;
int img_buffer_size = 0;
static JOCTET img_buffer[ZM_MAX_IMAGE_SIZE];
- Image scaled_image;
+ Image scaled_image, rotated_image;
while ( true )
{
if ( feof( stdout ) || ferror( stdout ) )
@@ -2105,6 +2109,15 @@
snap_image = &scaled_image;
}
+ if (rotate != 0)
+ {
+ rotated_image.Assign( *snap_image );
+
+ rotated_image.Rotate( rotate );
+
+ snap_image = &rotated_image;
+
+ }
if ( !config.timestamp_on_capture )
{
TimestampImage( snap_image, snap->timestamp->tv_sec );
@@ -2132,7 +2145,7 @@
}
}
-void Monitor::StreamImagesRaw( int scale, int maxfps, time_t ttl )
+void Monitor::StreamImagesRaw( int scale, int maxfps, time_t ttl, int rotate )
{
fprintf( stdout, "Content-Type: multipart/x-mixed-replace;boundary=ZoneMinderFrame\r\n\r\n" );
@@ -2163,7 +2176,7 @@
int frame_count = 0;
struct timeval base_time;
struct DeltaTimeval delta_time;
- Image scaled_image;
+ Image scaled_image, rotated_image;
while ( true )
{
if ( feof( stdout ) || ferror( stdout ) )
@@ -2189,6 +2202,15 @@
snap_image = &scaled_image;
}
+ if (rotate != 0)
+ {
+ rotated_image.Assign( *snap_image );
+
+ rotated_image.Rotate( rotate );
+
+ snap_image = &rotated_image;
+
+ }
if ( !config.timestamp_on_capture )
{
TimestampImage( snap_image, snap->timestamp->tv_sec );
@@ -2214,7 +2236,7 @@
}
}
-void Monitor::StreamImagesZip( int scale, int maxfps, time_t ttl )
+void Monitor::StreamImagesZip( int scale, int maxfps, time_t ttl, int rotate )
{
fprintf( stdout, "Content-Type: multipart/x-mixed-replace;boundary=ZoneMinderFrame\r\n\r\n" );
@@ -2247,7 +2269,7 @@
struct DeltaTimeval delta_time;
unsigned long img_buffer_size = 0;
static Bytef img_buffer[ZM_MAX_IMAGE_SIZE];
- Image scaled_image;
+ Image scaled_image, rotated_image;
while ( true )
{
if ( feof( stdout ) || ferror( stdout ) )
@@ -2273,6 +2295,15 @@
snap_image = &scaled_image;
}
+ if (rotate != 0)
+ {
+ rotated_image.Assign( *snap_image );
+
+ rotated_image.Rotate( rotate );
+
+ snap_image = & rotated_image;
+
+ }
if ( !config.timestamp_on_capture )
{
TimestampImage( snap_image, snap->timestamp->tv_sec );
@@ -2300,12 +2331,12 @@
}
}
-void Monitor::SingleImage( int scale)
+void Monitor::SingleImage( int scale, int rotate )
{
int last_read_index = shared_data->last_write_index;
int img_buffer_size = 0;
static JOCTET img_buffer[ZM_MAX_IMAGE_SIZE];
- Image scaled_image;
+ Image scaled_image, rotated_image;
int index = shared_data->last_write_index%image_buffer_count;
Snapshot *snap = &image_buffer[index];
Image *snap_image = snap->image;
@@ -2316,6 +2347,15 @@
scaled_image.Scale( scale );
snap_image = &scaled_image;
}
+ if (rotate != 0)
+ {
+ rotated_image.Assign( *snap_image );
+
+ rotated_image.Rotate( rotate );
+
+ snap_image = & rotated_image;
+
+ }
if ( !config.timestamp_on_capture )
{
TimestampImage( snap_image, snap->timestamp->tv_sec );
@@ -2327,10 +2367,10 @@
fwrite( img_buffer, img_buffer_size, 1, stdout );
}
-void Monitor::SingleImageRaw( int scale)
+void Monitor::SingleImageRaw( int scale, int rotate )
{
int last_read_index = shared_data->last_write_index;
- Image scaled_image;
+ Image scaled_image, rotated_image;
int index = shared_data->last_write_index%image_buffer_count;
Snapshot *snap = &image_buffer[index];
Image *snap_image = snap->image;
@@ -2341,6 +2381,13 @@
scaled_image.Scale( scale );
snap_image = &scaled_image;
}
+ if (rotate != 0)
+ {
+ rotated_image.Assign( *snap_image );
+ rotated_image.Rotate( rotate );
+ snap_image = &rotated_image;
+
+ }
if ( !config.timestamp_on_capture )
{
TimestampImage( snap_image, snap->timestamp->tv_sec );
@@ -2351,12 +2398,12 @@
fwrite( snap_image->Buffer(), snap_image->Size(), 1, stdout );
}
-void Monitor::SingleImageZip( int scale)
+void Monitor::SingleImageZip( int scale, int rotate )
{
int last_read_index = shared_data->last_write_index;
unsigned long img_buffer_size = 0;
static Bytef img_buffer[ZM_MAX_IMAGE_SIZE];
- Image scaled_image;
+ Image scaled_image, rotated_image;
int index = shared_data->last_write_index%image_buffer_count;
Snapshot *snap = &image_buffer[index];
Image *snap_image = snap->image;
@@ -2367,6 +2414,13 @@
scaled_image.Scale( scale );
snap_image = &scaled_image;
}
+ if (rotate != 0)
+ {
+ rotated_image.Assign( *snap_image );
+ rotated_image.Rotate( rotate );
+ snap_image = &rotated_image;
+
+ }
if ( !config.timestamp_on_capture )
{
TimestampImage( snap_image, snap->timestamp->tv_sec );
@@ -2380,7 +2434,7 @@
#if HAVE_LIBAVCODEC
-void Monitor::StreamMpeg( const char *format, int scale, int maxfps, int bitrate )
+void Monitor::StreamMpeg( const char *format, int scale, int maxfps, int bitrate, int rotate )
{
int fps = int(GetFPS());
if ( !fps )
@@ -2414,7 +2468,7 @@
int frame_count = 0;
struct timeval base_time;
struct DeltaTimeval delta_time;
- Image scaled_image;
+ Image scaled_image, rotated_image;
while ( true )
{
if ( feof( stdout ) || ferror( stdout ) )
@@ -2440,6 +2494,15 @@
snap_image = &scaled_image;
}
+ if (rotate != 0)
+ {
+ rotated_image.Assign( *snap_image );
+
+ rotated_image.Rotate( rotate );
+
+ snap_image = & rotated_image;
+
+ }
if ( !config.timestamp_on_capture )
{
TimestampImage( snap_image, snap->timestamp->tv_sec );
diff -U 3 -H -d -r -N -x '*~' -- ZoneMinder-1.22.3/src/zm_monitor.h ZoneMinder-1.22.3-patch/src/zm_monitor.h
--- ZoneMinder-1.22.3/src/zm_monitor.h 2006-11-16 12:34:53.000000000 +0100
+++ ZoneMinder-1.22.3-patch/src/zm_monitor.h 2007-02-06 18:03:19.000000000 +0100
@@ -277,7 +277,7 @@
unsigned int Height() const { return( height ); }
State GetState() const;
- int GetImage( int index=-1, int scale=100 ) const;
+ int GetImage( int index=-1, int scale=100, int rotate=0 ) const;
struct timeval GetTimestamp( int index=-1 ) const;
int GetCaptureDelay() const { return( capture_delay ); }
int GetAlarmCaptureDelay() const { return( alarm_capture_delay ); }
@@ -329,14 +329,14 @@
static int LoadRemoteMonitors( const char *host, const char*port, const char*path, Monitor **&monitors, Purpose purpose=QUERY );
static int LoadFileMonitors( const char *file, Monitor **&monitors, Purpose purpose=QUERY );
static Monitor *Load( int id, bool load_zones=false, Purpose purpose=QUERY );
- void StreamImages( int scale=100, int maxfps=10, time_t ttl=0 );
- void StreamImagesRaw( int scale=100, int maxfps=10, time_t ttl=0 );
- void StreamImagesZip( int scale=100, int maxfps=10, time_t ttl=0 );
- void SingleImage( int scale=100 );
- void SingleImageRaw( int scale=100 );
- void SingleImageZip( int scale=100 );
+ void StreamImages( int scale=100, int maxfps=10, time_t ttl=0, int rotate=0 );
+ void StreamImagesRaw( int scale=100, int maxfps=10, time_t ttl=0, int rotate=0 );
+ void StreamImagesZip( int scale=100, int maxfps=10, time_t ttl=0, int rotate=0 );
+ void SingleImage( int scale=100, int rotate=0 );
+ void SingleImageRaw( int scale=100, int rotate=0 );
+ void SingleImageZip( int scale=100, int rotate=0 );
#if HAVE_LIBAVCODEC
- void StreamMpeg( const char *format, int scale=100, int maxfps=10, int bitrate=100000 );
+ void StreamMpeg( const char *format, int scale=100, int maxfps=10, int bitrate=100000, int rotate=0 );
#endif // HAVE_LIBAVCODEC
};
diff -U 3 -H -d -r -N -x '*~' -- ZoneMinder-1.22.3/src/zms.cpp ZoneMinder-1.22.3-patch/src/zms.cpp
--- ZoneMinder-1.22.3/src/zms.cpp 2006-04-05 14:22:27.000000000 +0200
+++ ZoneMinder-1.22.3-patch/src/zms.cpp 2007-02-06 18:06:37.000000000 +0100
@@ -54,6 +54,7 @@
int id = 0;
int event = 0;
int frame = 1;
+ int rotate = 0;
unsigned int scale = 100;
unsigned int rate = 100;
unsigned int maxfps = 10;
@@ -86,9 +87,9 @@
char temp_query[1024];
strncpy( temp_query, query, sizeof(temp_query) );
char *q_ptr = temp_query;
- char *parms[16]; // Shouldn't be more than this
+ char *parms[17]; // Shouldn't be more than this
int parm_no = 0;
- while( (parm_no < 16) && (parms[parm_no] = strtok( q_ptr, "&" )) )
+ while( (parm_no < 17) && (parms[parm_no] = strtok( q_ptr, "&" )) )
{
parm_no++;
q_ptr = NULL;
@@ -113,6 +114,8 @@
frame = strtoull( value, (char **)NULL, 10 );
else if ( !strcmp( name, "format" ) )
strncpy( format, value, sizeof(format) );
+ else if ( !strcmp( name, "rotate" ) )
+ rotate = atoi( value );
else if ( !strcmp( name, "scale" ) )
scale = atoi( value );
else if ( !strcmp( name, "rate" ) )
@@ -223,24 +226,24 @@
{
if ( mode == ZMS_JPEG )
{
- monitor->StreamImages( scale, maxfps, ttl );
+ monitor->StreamImages( scale, maxfps, ttl, rotate );
}
else if ( mode == ZMS_RAW )
{
- monitor->StreamImagesRaw( scale, maxfps, ttl );
+ monitor->StreamImagesRaw( scale, maxfps, ttl, rotate );
}
else if ( mode == ZMS_ZIP )
{
- monitor->StreamImagesZip( scale, maxfps, ttl );
+ monitor->StreamImagesZip( scale, maxfps, ttl, rotate );
}
else if ( mode == ZMS_SINGLE )
{
- monitor->SingleImage( scale );
+ monitor->SingleImage( scale, rotate );
}
else
{
#if HAVE_LIBAVCODEC
- monitor->StreamMpeg( format, scale, maxfps, bitrate );
+ monitor->StreamMpeg( format, scale, maxfps, bitrate, rotate );
#else // HAVE_LIBAVCODEC
Error(( "MPEG streaming of '%s' attempted while disabled", query ));
fprintf( stderr, "MPEG streaming is disabled.\nYou should configure with the --with-ffmpeg option and rebuild to use this functionality.\n" );
@@ -253,12 +256,12 @@
{
if ( mode == ZMS_JPEG )
{
- Event::StreamEvent( event, frame, scale, rate, maxfps );
+ Event::StreamEvent( event, frame, scale, rate, maxfps, rotate );
}
else
{
#if HAVE_LIBAVCODEC
- Event::StreamMpeg( event, frame, format, scale, rate, maxfps, bitrate );
+ Event::StreamMpeg( event, frame, format, scale, rate, maxfps, bitrate, rotate );
#else // HAVE_LIBAVCODEC
Error(( "MPEG streaming of '%s' attempted while disabled", query ));
fprintf( stderr, "MPEG streaming is disabled.\nYou should configure with the --with-ffmpeg option and rebuild to use this functionality.\n" );