Analysis image finally working!

This commit is contained in:
Kfir Itzhak 2011-10-27 17:22:36 +02:00
parent af821828b8
commit d7e9c6ad5c
3 changed files with 89 additions and 23 deletions

View File

@ -457,25 +457,57 @@ void Image::Assign( const Image &image ) {
(*fptr_imgbufcpy)(buffer, image.buffer, size);
}
/* RGB24 only */
Image *Image::HighlightEdges( Rgb colour, const Box *limits )
Image *Image::HighlightEdges( Rgb colour, int p_colours, int p_subpixelorder, const Box *limits )
{
if ( colours != ZM_COLOUR_GRAY8 )
{
Panic( "Attempt to highlight image edges when colours = %d", colours );
}
Image *high_image = new Image( width, height, ZM_COLOUR_RGB24, ZM_SUBPIX_ORDER_RGB);
uint8_t* high_buff = high_image->WriteBuffer(width, height, ZM_COLOUR_RGB24, ZM_SUBPIX_ORDER_RGB);
/* Convert the colour's RGBA subpixel order into the image's subpixel order */
colour = rgb_convert(colour,p_subpixelorder);
/* Create a new image of the target format */
Image *high_image = new Image( width, height, p_colours, p_subpixelorder );
uint8_t* high_buff = high_image->WriteBuffer(width, height, p_colours, p_subpixelorder);
/* Set image to all black */
high_image->Clear();
int lo_x = limits?limits->Lo().X():0;
int lo_y = limits?limits->Lo().Y():0;
int hi_x = limits?limits->Hi().X():width-1;
int hi_y = limits?limits->Hi().Y():height-1;
if ( p_colours == ZM_COLOUR_GRAY8 )
{
for ( int y = lo_y; y <= hi_y; y++ )
{
uint8_t *p = &buffer[(y*width)+lo_x];
uint8_t *phigh = high_buff + (((y * width) + lo_x) * 3);
const uint8_t* p = buffer + (y * width) + lo_x;
uint8_t* phigh = high_buff + (y * width) + lo_x;
for ( int x = lo_x; x <= hi_x; x++, p++, phigh++ )
{
bool edge = false;
if ( *p )
{
if ( !edge && x > 0 && !*(p-1) ) edge = true;
if ( !edge && x < (width-1) && !*(p+1) ) edge = true;
if ( !edge && y > 0 && !*(p-width) ) edge = true;
if ( !edge && y < (height-1) && !*(p+width) ) edge = true;
}
if ( edge )
{
*phigh = colour;
}
}
}
}
else if ( p_colours == ZM_COLOUR_RGB24 )
{
for ( int y = lo_y; y <= hi_y; y++ )
{
const uint8_t* p = buffer + (y * width) + lo_x;
uint8_t* phigh = high_buff + (((y * width) + lo_x) * 3);
for ( int x = lo_x; x <= hi_x; x++, p++, phigh += 3 )
{
bool edge = false;
@ -494,6 +526,31 @@ Image *Image::HighlightEdges( Rgb colour, const Box *limits )
}
}
}
}
else if ( p_colours == ZM_COLOUR_RGB32 )
{
for ( int y = lo_y; y <= hi_y; y++ )
{
const uint8_t* p = buffer + (y * width) + lo_x;
Rgb* phigh = (Rgb*)(high_buff + (((y * width) + lo_x) * 4));
for ( int x = lo_x; x <= hi_x; x++, p++, phigh++ )
{
bool edge = false;
if ( *p )
{
if ( !edge && x > 0 && !*(p-1) ) edge = true;
if ( !edge && x < (width-1) && !*(p+1) ) edge = true;
if ( !edge && y > 0 && !*(p-width) ) edge = true;
if ( !edge && y < (height-1) && !*(p+width) ) edge = true;
}
if ( edge )
{
*phigh = colour;
}
}
}
}
return( high_image );
}
@ -1126,6 +1183,10 @@ void Image::Overlay( const Image &image )
Panic( "Attempt to overlay different sized images, expected %dx%d, got %dx%d", width, height, image.width, image.height );
}
if( colours == image.colours && subpixelorder != image.subpixelorder ) {
Warning("Attempt to overlay images of same format but with different subpixel order.");
}
/* Grayscale ontop of grayscale - complete */
if ( colours == ZM_COLOUR_GRAY8 && image.colours == ZM_COLOUR_GRAY8 ) {
const uint8_t* const max_ptr = buffer+size;
@ -1289,7 +1350,6 @@ void Image::Overlay( const Image &image )
prsrc++;
}
}
}
}

View File

@ -226,7 +226,7 @@ public:
const Coord centreCoord( const char *text ) const;
void Annotate( const char *p_text, const Coord &coord, const Rgb fg_colour=RGB_WHITE, const Rgb bg_colour=RGB_BLACK );
Image *HighlightEdges( Rgb colour, const Box *limits=0 );
Image *HighlightEdges( Rgb colour, int p_colours, int p_subpixelorder, const Box *limits=0 );
//Image *HighlightEdges( Rgb colour, const Polygon &polygon );
void Timestamp( const char *label, const time_t when, const Coord &coord );
void Colourise(const int p_reqcolours, const int p_reqsubpixelorder);

View File

@ -725,7 +725,13 @@ bool Zone::CheckAlarms( const Image *delta_image )
}
}
}
image = diff_image->HighlightEdges( alarm_rgb, &polygon.Extent() );
if( monitor->Colours() == ZM_COLOUR_GRAY8 ) {
image = diff_image->HighlightEdges( alarm_rgb, ZM_COLOUR_RGB24, ZM_SUBPIX_ORDER_RGB, &polygon.Extent() );
} else {
image = diff_image->HighlightEdges( alarm_rgb, monitor->Colours(), monitor->SubpixelOrder(), &polygon.Extent() );
}
// Only need to delete this when 'image' becomes detached and points somewhere else
delete diff_image;
}