diff --git a/src/zm_image.cpp b/src/zm_image.cpp index ea7ad446b..491ae8470 100644 --- a/src/zm_image.cpp +++ b/src/zm_image.cpp @@ -1094,8 +1094,7 @@ bool Image::DecodeJpeg( const JOCTET *inbuffer, int inbuffer_size, unsigned int jpeg_read_header( cinfo, TRUE ); - if ( cinfo->num_components != 1 && cinfo->num_components != 3 ) - { + if ( cinfo->num_components != 1 && cinfo->num_components != 3 ) { Error( "Unexpected colours when reading jpeg image: %d", colours ); jpeg_abort_decompress( cinfo ); return( false ); @@ -1110,8 +1109,7 @@ bool Image::DecodeJpeg( const JOCTET *inbuffer, int inbuffer_size, unsigned int new_width = cinfo->image_width; new_height = cinfo->image_height; - if ( width != new_width || height != new_height ) - { + if ( width != new_width || height != new_height ) { Debug(9,"Image dimensions differ. Old: %ux%u New: %ux%u",width,height,new_width,new_height); } @@ -1173,7 +1171,7 @@ cinfo->out_color_space = JCS_RGB; } break; } - } + } // end switch if(WriteBuffer(new_width, new_height, new_colours, new_subpixelorder) == NULL) { Error("Failed requesting writeable buffer for reading JPEG image."); @@ -1185,21 +1183,18 @@ cinfo->out_color_space = JCS_RGB; JSAMPROW row_pointer; /* pointer to a single row */ int row_stride = width * colours; /* physical row width in buffer */ - while ( cinfo->output_scanline < cinfo->output_height ) - { + while ( cinfo->output_scanline < cinfo->output_height ) { row_pointer = &buffer[cinfo->output_scanline * row_stride]; jpeg_read_scanlines( cinfo, &row_pointer, 1 ); } jpeg_finish_decompress( cinfo ); - return( true ); + return true; } -bool Image::EncodeJpeg( JOCTET *outbuffer, int *outbuffer_size, int quality_override ) const -{ - if ( config.colour_jpeg_files && colours == ZM_COLOUR_GRAY8 ) - { +bool Image::EncodeJpeg( JOCTET *outbuffer, int *outbuffer_size, int quality_override ) const { + if ( config.colour_jpeg_files && colours == ZM_COLOUR_GRAY8 ) { Image temp_image( *this ); temp_image.Colourise(ZM_COLOUR_RGB24, ZM_SUBPIX_ORDER_RGB ); return( temp_image.EncodeJpeg( outbuffer, outbuffer_size, quality_override ) ); @@ -1209,8 +1204,7 @@ bool Image::EncodeJpeg( JOCTET *outbuffer, int *outbuffer_size, int quality_over struct jpeg_compress_struct *cinfo = encodejpg_ccinfo[quality]; - if ( !cinfo ) - { + if ( !cinfo ) { cinfo = encodejpg_ccinfo[quality] = new jpeg_compress_struct; cinfo->err = jpeg_std_error( &jpg_err.pub ); jpg_err.pub.error_exit = zm_jpeg_error_exit; @@ -1276,7 +1270,7 @@ cinfo->out_color_space = JCS_RGB; } break; } - } + } // end switch jpeg_set_defaults( cinfo ); jpeg_set_quality( cinfo, quality, FALSE ); @@ -1286,44 +1280,38 @@ cinfo->out_color_space = JCS_RGB; JSAMPROW row_pointer; /* pointer to a single row */ int row_stride = cinfo->image_width * colours; /* physical row width in buffer */ - while ( cinfo->next_scanline < cinfo->image_height ) - { + while ( cinfo->next_scanline < cinfo->image_height ) { row_pointer = &buffer[cinfo->next_scanline * row_stride]; jpeg_write_scanlines( cinfo, &row_pointer, 1 ); } jpeg_finish_compress( cinfo ); - return( true ); + return true; } #if HAVE_ZLIB_H -bool Image::Unzip( const Bytef *inbuffer, unsigned long inbuffer_size ) -{ +bool Image::Unzip( const Bytef *inbuffer, unsigned long inbuffer_size ) { unsigned long zip_size = size; int result = uncompress( buffer, &zip_size, inbuffer, inbuffer_size ); - if ( result != Z_OK ) - { - Error( "Unzip failed, result = %d", result ); - return( false ); + if ( result != Z_OK ) { + Error("Unzip failed, result = %d", result); + return false; } - if ( zip_size != (unsigned int)size ) - { - Error( "Unzip failed, size mismatch, expected %d bytes, got %ld", size, zip_size ); - return( false ); + if ( zip_size != (unsigned int)size ) { + Error("Unzip failed, size mismatch, expected %d bytes, got %ld", size, zip_size); + return false; } - return( true ); + return true; } -bool Image::Zip( Bytef *outbuffer, unsigned long *outbuffer_size, int compression_level ) const -{ +bool Image::Zip( Bytef *outbuffer, unsigned long *outbuffer_size, int compression_level ) const { int result = compress2( outbuffer, outbuffer_size, buffer, size, compression_level ); - if ( result != Z_OK ) - { - Error( "Zip failed, result = %d", result ); - return( false ); + if ( result != Z_OK ) { + Error("Zip failed, result = %d", result); + return false; } - return( true ); + return true; } #endif // HAVE_ZLIB_H @@ -1337,11 +1325,11 @@ bool Image::Crop( unsigned int lo_x, unsigned int lo_y, unsigned int hi_x, unsig } if ( hi_x > (width-1) || ( hi_y > (height-1) ) ) { Error( "Attempting to crop outside image, %d,%d -> %d,%d not in %d,%d", lo_x, lo_y, hi_x, hi_y, width-1, height-1 ); - return( false ); + return false; } if ( new_width == width && new_height == height ) { - return( true ); + return true; } unsigned int new_size = new_width*new_height*colours; @@ -1356,24 +1344,22 @@ bool Image::Crop( unsigned int lo_x, unsigned int lo_y, unsigned int hi_x, unsig AssignDirect(new_width, new_height, colours, subpixelorder, new_buffer, new_size, ZM_BUFTYPE_ZM); - return( true ); + return true; } -bool Image::Crop( const Box &limits ) -{ - return( Crop( limits.LoX(), limits.LoY(), limits.HiX(), limits.HiY() ) ); +bool Image::Crop( const Box &limits ) { + return Crop( limits.LoX(), limits.LoY(), limits.HiX(), limits.HiY() ); } /* Far from complete */ /* Need to implement all possible of overlays possible */ -void Image::Overlay( const Image &image ) -{ - if ( !(width == image.width && height == image.height) ) - { - Panic( "Attempt to overlay different sized images, expected %dx%d, got %dx%d", width, height, image.width, image.height ); +void Image::Overlay( const Image &image ) { + if ( !(width == image.width && height == image.height) ) { + 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 ) { + if ( colours == image.colours && subpixelorder != image.subpixelorder ) { Warning("Attempt to overlay images of same format but with different subpixel order."); } @@ -1383,10 +1369,8 @@ void Image::Overlay( const Image &image ) const uint8_t* psrc = image.buffer; uint8_t* pdest = buffer; - while( pdest < max_ptr ) - { - if ( *psrc ) - { + while( pdest < max_ptr ) { + if ( *psrc ) { *pdest = *psrc; } pdest++; @@ -1401,10 +1385,8 @@ void Image::Overlay( const Image &image ) const uint8_t* psrc = image.buffer; uint8_t* pdest = buffer; - while( pdest < max_ptr ) - { - if ( RED_PTR_RGBA(psrc) || GREEN_PTR_RGBA(psrc) || BLUE_PTR_RGBA(psrc) ) - { + while( pdest < max_ptr ) { + if ( RED_PTR_RGBA(psrc) || GREEN_PTR_RGBA(psrc) || BLUE_PTR_RGBA(psrc) ) { RED_PTR_RGBA(pdest) = RED_PTR_RGBA(psrc); GREEN_PTR_RGBA(pdest) = GREEN_PTR_RGBA(psrc); BLUE_PTR_RGBA(pdest) = BLUE_PTR_RGBA(psrc); @@ -1421,11 +1403,10 @@ void Image::Overlay( const Image &image ) const Rgb* prsrc = (Rgb*)image.buffer; Rgb* prdest = (Rgb*)buffer; - if(subpixelorder == ZM_SUBPIX_ORDER_RGBA || subpixelorder == ZM_SUBPIX_ORDER_BGRA) { + if ( subpixelorder == ZM_SUBPIX_ORDER_RGBA || subpixelorder == ZM_SUBPIX_ORDER_BGRA ) { /* RGB\BGR\RGBA\BGRA subpixel order - Alpha byte is last */ while (prdest < max_ptr) { - if ( RED_PTR_RGBA(prsrc) || GREEN_PTR_RGBA(prsrc) || BLUE_PTR_RGBA(prsrc) ) - { + if ( RED_PTR_RGBA(prsrc) || GREEN_PTR_RGBA(prsrc) || BLUE_PTR_RGBA(prsrc) ) { *prdest = *prsrc; } prdest++; @@ -1434,8 +1415,7 @@ void Image::Overlay( const Image &image ) } else { /* ABGR\ARGB subpixel order - Alpha byte is first */ while (prdest < max_ptr) { - if ( RED_PTR_ABGR(prsrc) || GREEN_PTR_ABGR(prsrc) || BLUE_PTR_ABGR(prsrc) ) - { + if ( RED_PTR_ABGR(prsrc) || GREEN_PTR_ABGR(prsrc) || BLUE_PTR_ABGR(prsrc) ) { *prdest = *prsrc; } prdest++; @@ -1449,10 +1429,8 @@ void Image::Overlay( const Image &image ) const uint8_t* psrc = image.buffer; uint8_t* pdest = buffer; - while( pdest < max_ptr ) - { - if ( *psrc ) - { + while( pdest < max_ptr ) { + if ( *psrc ) { RED_PTR_RGBA(pdest) = GREEN_PTR_RGBA(pdest) = BLUE_PTR_RGBA(pdest) = *psrc; } pdest += 3; @@ -1465,10 +1443,8 @@ void Image::Overlay( const Image &image ) const uint8_t* psrc = image.buffer; uint8_t* pdest = buffer; - while( pdest < max_ptr ) - { - if ( RED_PTR_RGBA(psrc) || GREEN_PTR_RGBA(psrc) || BLUE_PTR_RGBA(psrc) ) - { + while( pdest < max_ptr ) { + if ( RED_PTR_RGBA(psrc) || GREEN_PTR_RGBA(psrc) || BLUE_PTR_RGBA(psrc) ) { RED_PTR_RGBA(pdest) = RED_PTR_RGBA(psrc); GREEN_PTR_RGBA(pdest) = GREEN_PTR_RGBA(psrc); BLUE_PTR_RGBA(pdest) = BLUE_PTR_RGBA(psrc); @@ -1487,11 +1463,10 @@ void Image::Overlay( const Image &image ) Rgb* prdest = (Rgb*)buffer; const uint8_t* psrc = image.buffer; - if(subpixelorder == ZM_SUBPIX_ORDER_RGBA || subpixelorder == ZM_SUBPIX_ORDER_BGRA) { + if ( subpixelorder == ZM_SUBPIX_ORDER_RGBA || subpixelorder == ZM_SUBPIX_ORDER_BGRA ) { /* RGBA\BGRA subpixel order - Alpha byte is last */ - while (prdest < max_ptr) { - if ( *psrc ) - { + while ( prdest < max_ptr ) { + if ( *psrc ) { RED_PTR_RGBA(prdest) = GREEN_PTR_RGBA(prdest) = BLUE_PTR_RGBA(prdest) = *psrc; } prdest++; @@ -1499,9 +1474,8 @@ void Image::Overlay( const Image &image ) } } else { /* ABGR\ARGB subpixel order - Alpha byte is first */ - while (prdest < max_ptr) { - if ( *psrc ) - { + while ( prdest < max_ptr ) { + if ( *psrc ) { RED_PTR_ABGR(prdest) = GREEN_PTR_ABGR(prdest) = BLUE_PTR_ABGR(prdest) = *psrc; } prdest++; @@ -1519,11 +1493,10 @@ void Image::Overlay( const Image &image ) Rgb* prdest = (Rgb*)buffer; const Rgb* prsrc = (Rgb*)image.buffer; - if(image.subpixelorder == ZM_SUBPIX_ORDER_RGBA || image.subpixelorder == ZM_SUBPIX_ORDER_BGRA) { + if ( image.subpixelorder == ZM_SUBPIX_ORDER_RGBA || image.subpixelorder == ZM_SUBPIX_ORDER_BGRA ) { /* RGB\BGR\RGBA\BGRA subpixel order - Alpha byte is last */ - while (prdest < max_ptr) { - if ( RED_PTR_RGBA(prsrc) || GREEN_PTR_RGBA(prsrc) || BLUE_PTR_RGBA(prsrc) ) - { + while ( prdest < max_ptr ) { + if ( RED_PTR_RGBA(prsrc) || GREEN_PTR_RGBA(prsrc) || BLUE_PTR_RGBA(prsrc) ) { *prdest = *prsrc; } prdest++; @@ -1531,9 +1504,8 @@ void Image::Overlay( const Image &image ) } } else { /* ABGR\ARGB subpixel order - Alpha byte is first */ - while (prdest < max_ptr) { - if ( RED_PTR_ABGR(prsrc) || GREEN_PTR_ABGR(prsrc) || BLUE_PTR_ABGR(prsrc) ) - { + while ( prdest < max_ptr ) { + if ( RED_PTR_ABGR(prsrc) || GREEN_PTR_ABGR(prsrc) || BLUE_PTR_ABGR(prsrc) ) { *prdest = *prsrc; } prdest++; @@ -1545,61 +1517,49 @@ void Image::Overlay( const Image &image ) } /* RGB32 compatible: complete */ -void Image::Overlay( const Image &image, unsigned int x, unsigned int y ) -{ - if ( !(width < image.width || height < image.height) ) - { - Panic( "Attempt to overlay image too big for destination, %dx%d > %dx%d", image.width, image.height, width, height ); +void Image::Overlay( const Image &image, unsigned int x, unsigned int y ) { + if ( !(width < image.width || height < image.height) ) { + Panic("Attempt to overlay image too big for destination, %dx%d > %dx%d", + image.width, image.height, width, height ); } - if ( !(width < (x+image.width) || height < (y+image.height)) ) - { - Panic( "Attempt to overlay image outside of destination bounds, %dx%d @ %dx%d > %dx%d", image.width, image.height, x, y, width, height ); + if ( !(width < (x+image.width) || height < (y+image.height)) ) { + Panic("Attempt to overlay image outside of destination bounds, %dx%d @ %dx%d > %dx%d", + image.width, image.height, x, y, width, height ); } - if ( !(colours == image.colours) ) - { - Panic( "Attempt to partial overlay differently coloured images, expected %d, got %d", colours, image.colours ); + if ( !(colours == image.colours) ) { + Panic("Attempt to partial overlay differently coloured images, expected %d, got %d", + colours, image.colours); } unsigned int lo_x = x; unsigned int lo_y = y; unsigned int hi_x = (x+image.width)-1; unsigned int hi_y = (y+image.height-1); - if ( colours == ZM_COLOUR_GRAY8 ) - { + if ( colours == ZM_COLOUR_GRAY8 ) { const uint8_t *psrc = image.buffer; - for ( unsigned int y = lo_y; y <= hi_y; y++ ) - { + for ( unsigned int y = lo_y; y <= hi_y; y++ ) { uint8_t *pdest = &buffer[(y*width)+lo_x]; - for ( unsigned int x = lo_x; x <= hi_x; x++ ) - { + for ( unsigned int x = lo_x; x <= hi_x; x++ ) { *pdest++ = *psrc++; } } - } - else if ( colours == ZM_COLOUR_RGB24 ) - { + } else if ( colours == ZM_COLOUR_RGB24 ) { const uint8_t *psrc = image.buffer; - for ( unsigned int y = lo_y; y <= hi_y; y++ ) - { + for ( unsigned int y = lo_y; y <= hi_y; y++ ) { uint8_t *pdest = &buffer[colours*((y*width)+lo_x)]; - for ( unsigned int x = lo_x; x <= hi_x; x++ ) - { + for ( unsigned int x = lo_x; x <= hi_x; x++ ) { *pdest++ = *psrc++; *pdest++ = *psrc++; *pdest++ = *psrc++; } } - } - else if ( colours == ZM_COLOUR_RGB32 ) - { + } else if ( colours == ZM_COLOUR_RGB32 ) { const Rgb *psrc = (Rgb*)(image.buffer); - for ( unsigned int y = lo_y; y <= hi_y; y++ ) - { + for ( unsigned int y = lo_y; y <= hi_y; y++ ) { Rgb *pdest = (Rgb*)&buffer[((y*width)+lo_x)<<2]; - for ( unsigned int x = lo_x; x <= hi_x; x++ ) - { + for ( unsigned int x = lo_x; x <= hi_x; x++ ) { *pdest++ = *psrc++; } } @@ -1609,8 +1569,7 @@ void Image::Overlay( const Image &image, unsigned int x, unsigned int y ) } -void Image::Blend( const Image &image, int transparency ) -{ +void Image::Blend( const Image &image, int transparency ) { #ifdef ZM_IMAGE_PROFILING struct timespec start,end,diff; unsigned long long executetime; @@ -1618,12 +1577,16 @@ void Image::Blend( const Image &image, int transparency ) #endif uint8_t* new_buffer; - if ( !(width == image.width && height == image.height && colours == image.colours && subpixelorder == image.subpixelorder) ) - { - Panic( "Attempt to blend different sized images, expected %dx%dx%d %d, got %dx%dx%d %d", width, height, colours, subpixelorder, image.width, image.height, image.colours, image.subpixelorder ); + if ( !( + width == image.width && height == image.height + && colours == image.colours + && subpixelorder == image.subpixelorder + ) ) { + Panic("Attempt to blend different sized images, expected %dx%dx%d %d, got %dx%dx%d %d", + width, height, colours, subpixelorder, image.width, image.height, image.colours, image.subpixelorder ); } - if(transparency <= 0) + if ( transparency <= 0 ) return; new_buffer = AllocBuffer(size); @@ -1644,7 +1607,7 @@ void Image::Blend( const Image &image, int transparency ) Debug(5, "Blend: %u colours blended in %llu nanoseconds, %lu million colours/s\n",size,executetime,milpixels); #endif - AssignDirect( width, height, colours, subpixelorder, new_buffer, size, ZM_BUFTYPE_ZM); + AssignDirect(width, height, colours, subpixelorder, new_buffer, size, ZM_BUFTYPE_ZM); } Image *Image::Merge( unsigned int n_images, Image *images[] ) { @@ -1655,7 +1618,8 @@ Image *Image::Merge( unsigned int n_images, Image *images[] ) { unsigned int colours = images[0]->colours; for ( unsigned int i = 1; i < n_images; i++ ) { if ( !(width == images[i]->width && height == images[i]->height && colours == images[i]->colours) ) { - Panic( "Attempt to merge different sized images, expected %dx%dx%d, got %dx%dx%d, for image %d", width, height, colours, images[i]->width, images[i]->height, images[i]->colours, i ); + Panic("Attempt to merge different sized images, expected %dx%dx%d, got %dx%dx%d, for image %d", + width, height, colours, images[i]->width, images[i]->height, images[i]->colours, i ); } } @@ -1683,7 +1647,8 @@ Image *Image::Merge( unsigned int n_images, Image *images[], double weight ) { unsigned int colours = images[0]->colours; for ( unsigned int i = 1; i < n_images; i++ ) { if ( !(width == images[i]->width && height == images[i]->height && colours == images[i]->colours) ) { - Panic( "Attempt to merge different sized images, expected %dx%dx%d, got %dx%dx%d, for image %d", width, height, colours, images[i]->width, images[i]->height, images[i]->colours, i ); + Panic("Attempt to merge different sized images, expected %dx%dx%d, got %dx%dx%d, for image %d", + width, height, colours, images[i]->width, images[i]->height, images[i]->colours, i ); } } @@ -1703,8 +1668,7 @@ Image *Image::Merge( unsigned int n_images, Image *images[], double weight ) { return result; } -Image *Image::Highlight( unsigned int n_images, Image *images[], const Rgb threshold, const Rgb ref_colour ) -{ +Image *Image::Highlight( unsigned int n_images, Image *images[], const Rgb threshold, const Rgb ref_colour ) { if ( n_images == 1 ) return new Image(*images[0]); unsigned int width = images[0]->width; @@ -1712,7 +1676,8 @@ Image *Image::Highlight( unsigned int n_images, Image *images[], const Rgb thres unsigned int colours = images[0]->colours; for ( unsigned int i = 1; i < n_images; i++ ) { if ( !(width == images[i]->width && height == images[i]->height && colours == images[i]->colours) ) { - Panic( "Attempt to highlight different sized images, expected %dx%dx%d, got %dx%dx%d, for image %d", width, height, colours, images[i]->width, images[i]->height, images[i]->colours, i ); + Panic( "Attempt to highlight different sized images, expected %dx%dx%d, got %dx%dx%d, for image %d", + width, height, colours, images[i]->width, images[i]->height, images[i]->colours, i ); } } @@ -1738,26 +1703,25 @@ Image *Image::Highlight( unsigned int n_images, Image *images[], const Rgb thres pdest += 3; } } - return( result ); + return result; } /* New function to allow buffer re-using instead of allocationg memory for the delta image every time */ -void Image::Delta( const Image &image, Image* targetimage) const -{ +void Image::Delta( const Image &image, Image* targetimage) const { #ifdef ZM_IMAGE_PROFILING struct timespec start,end,diff; unsigned long long executetime; unsigned long milpixels; #endif - if ( !(width == image.width && height == image.height && colours == image.colours && subpixelorder == image.subpixelorder) ) - { - Panic( "Attempt to get delta of different sized images, expected %dx%dx%d %d, got %dx%dx%d %d", width, height, colours, subpixelorder, image.width, image.height, image.colours, image.subpixelorder); + if ( !(width == image.width && height == image.height && colours == image.colours && subpixelorder == image.subpixelorder) ) { + Panic( "Attempt to get delta of different sized images, expected %dx%dx%d %d, got %dx%dx%d %d", + width, height, colours, subpixelorder, image.width, image.height, image.colours, image.subpixelorder); } uint8_t *pdiff = targetimage->WriteBuffer(width, height, ZM_COLOUR_GRAY8, ZM_SUBPIX_ORDER_NONE); - if(pdiff == NULL) { + if ( pdiff == NULL ) { Panic("Failed requesting writeable buffer for storing the delta image"); } @@ -1847,34 +1811,24 @@ void Image::MaskPrivacy( const unsigned char *p_bitmask, const Rgb pixel_colour unsigned char *ptr = &buffer[0]; unsigned int i = 0; - for ( unsigned int y = 0; y < height; y++ ) - { - if ( colours == ZM_COLOUR_GRAY8 ) - { - for ( unsigned int x = 0; x < width; x++, ptr++ ) - { + for ( unsigned int y = 0; y < height; y++ ) { + if ( colours == ZM_COLOUR_GRAY8 ) { + for ( unsigned int x = 0; x < width; x++, ptr++ ) { if ( p_bitmask[i] ) *ptr = pixel_bw_col; i++; } - } - else if ( colours == ZM_COLOUR_RGB24 ) - { - for ( unsigned int x = 0; x < width; x++, ptr += colours ) - { - if ( p_bitmask[i] ) - { + } else if ( colours == ZM_COLOUR_RGB24 ) { + for ( unsigned int x = 0; x < width; x++, ptr += colours ) { + if ( p_bitmask[i] ) { RED_PTR_RGBA(ptr) = pixel_r_col; GREEN_PTR_RGBA(ptr) = pixel_g_col; BLUE_PTR_RGBA(ptr) = pixel_b_col; } i++; } - } - else if ( colours == ZM_COLOUR_RGB32 ) - { - for ( unsigned int x = 0; x < width; x++, ptr += colours ) - { + } else if ( colours == ZM_COLOUR_RGB32 ) { + for ( unsigned int x = 0; x < width; x++, ptr += colours ) { Rgb *temp_ptr = (Rgb*)ptr; if ( p_bitmask[i] ) *temp_ptr = pixel_rgb_col; @@ -1884,8 +1838,7 @@ void Image::MaskPrivacy( const unsigned char *p_bitmask, const Rgb pixel_colour Panic("MaskPrivacy called with unexpected colours: %d", colours); return; } - - } + } // end foreach y } /* RGB32 compatible: complete */ @@ -1917,8 +1870,7 @@ void Image::Annotate( const char *p_text, const Coord &coord, const unsigned int if (size == 2) zm_text_bitmask = 0x8000; - while ( (index < text_len) && (line_len = strcspn( line, "\n" )) ) - { + while ( (index < text_len) && (line_len = strcspn( line, "\n" )) ) { unsigned int line_width = line_len * ZM_CHAR_WIDTH * size; @@ -1948,62 +1900,46 @@ void Image::Annotate( const char *p_text, const Coord &coord, const unsigned int if ( hi_line_y > height ) hi_line_y = height; - if ( colours == ZM_COLOUR_GRAY8 ) - { + if ( colours == ZM_COLOUR_GRAY8 ) { unsigned char *ptr = &buffer[(lo_line_y*width)+lo_line_x]; - for ( unsigned int y = lo_line_y, r = 0; y < hi_line_y && r < (ZM_CHAR_HEIGHT * size); y++, r++, ptr += width ) - { + for ( unsigned int y = lo_line_y, r = 0; y < hi_line_y && r < (ZM_CHAR_HEIGHT * size); y++, r++, ptr += width ) { unsigned char *temp_ptr = ptr; - for ( unsigned int x = lo_line_x, c = 0; x < hi_line_x && c < line_len; c++ ) - { + for ( unsigned int x = lo_line_x, c = 0; x < hi_line_x && c < line_len; c++ ) { int f; if (size == 2) f = bigfontdata[(line[c] * ZM_CHAR_HEIGHT * size) + r]; else f = fontdata[(line[c] * ZM_CHAR_HEIGHT) + r]; - for ( unsigned int i = 0; i < (ZM_CHAR_WIDTH * size) && x < hi_line_x; i++, x++, temp_ptr++ ) - { - if ( f & (zm_text_bitmask >> i) ) - { + for ( unsigned int i = 0; i < (ZM_CHAR_WIDTH * size) && x < hi_line_x; i++, x++, temp_ptr++ ) { + if ( f & (zm_text_bitmask >> i) ) { if ( !fg_trans ) *temp_ptr = fg_bw_col; - } - else if ( !bg_trans ) - { + } else if ( !bg_trans ) { *temp_ptr = bg_bw_col; } } } } - } - else if ( colours == ZM_COLOUR_RGB24 ) - { + } else if ( colours == ZM_COLOUR_RGB24 ) { unsigned int wc = width * colours; unsigned char *ptr = &buffer[((lo_line_y*width)+lo_line_x)*colours]; - for ( unsigned int y = lo_line_y, r = 0; y < hi_line_y && r < (ZM_CHAR_HEIGHT * size); y++, r++, ptr += wc ) - { + for ( unsigned int y = lo_line_y, r = 0; y < hi_line_y && r < (ZM_CHAR_HEIGHT * size); y++, r++, ptr += wc ) { unsigned char *temp_ptr = ptr; - for ( unsigned int x = lo_line_x, c = 0; x < hi_line_x && c < line_len; c++ ) - { + for ( unsigned int x = lo_line_x, c = 0; x < hi_line_x && c < line_len; c++ ) { int f; if (size == 2) f = bigfontdata[(line[c] * ZM_CHAR_HEIGHT * size) + r]; else f = fontdata[(line[c] * ZM_CHAR_HEIGHT) + r]; - for ( unsigned int i = 0; i < (ZM_CHAR_WIDTH * size) && x < hi_line_x; i++, x++, temp_ptr += colours ) - { - if ( f & (zm_text_bitmask >> i) ) - { - if ( !fg_trans ) - { + for ( unsigned int i = 0; i < (ZM_CHAR_WIDTH * size) && x < hi_line_x; i++, x++, temp_ptr += colours ) { + if ( f & (zm_text_bitmask >> i) ) { + if ( !fg_trans ) { RED_PTR_RGBA(temp_ptr) = fg_r_col; GREEN_PTR_RGBA(temp_ptr) = fg_g_col; BLUE_PTR_RGBA(temp_ptr) = fg_b_col; } - } - else if ( !bg_trans ) - { + } else if ( !bg_trans ) { RED_PTR_RGBA(temp_ptr) = bg_r_col; GREEN_PTR_RGBA(temp_ptr) = bg_g_col; BLUE_PTR_RGBA(temp_ptr) = bg_b_col; @@ -2011,33 +1947,24 @@ void Image::Annotate( const char *p_text, const Coord &coord, const unsigned int } } } - } - else if ( colours == ZM_COLOUR_RGB32 ) - { + } else if ( colours == ZM_COLOUR_RGB32 ) { unsigned int wc = width * colours; uint8_t *ptr = &buffer[((lo_line_y*width)+lo_line_x)<<2]; - for ( unsigned int y = lo_line_y, r = 0; y < hi_line_y && r < (ZM_CHAR_HEIGHT * size); y++, r++, ptr += wc ) - { + for ( unsigned int y = lo_line_y, r = 0; y < hi_line_y && r < (ZM_CHAR_HEIGHT * size); y++, r++, ptr += wc ) { Rgb* temp_ptr = (Rgb*)ptr; - for ( unsigned int x = lo_line_x, c = 0; x < hi_line_x && c < line_len; c++ ) - { + for ( unsigned int x = lo_line_x, c = 0; x < hi_line_x && c < line_len; c++ ) { int f; if (size == 2) f = bigfontdata[(line[c] * ZM_CHAR_HEIGHT * size) + r]; else f = fontdata[(line[c] * ZM_CHAR_HEIGHT) + r]; - for ( unsigned int i = 0; i < (ZM_CHAR_WIDTH * size) && x < hi_line_x; i++, x++, temp_ptr++ ) - { - if ( f & (zm_text_bitmask >> i) ) - { - if ( !fg_trans ) - { + for ( unsigned int i = 0; i < (ZM_CHAR_WIDTH * size) && x < hi_line_x; i++, x++, temp_ptr++ ) { + if ( f & (zm_text_bitmask >> i) ) { + if ( !fg_trans ) { *temp_ptr = fg_rgb_col; } - } - else if ( !bg_trans ) - { + } else if ( !bg_trans ) { *temp_ptr = bg_rgb_col; } } @@ -2050,8 +1977,7 @@ void Image::Annotate( const char *p_text, const Coord &coord, const unsigned int } index += line_len; - while ( text[index] == '\n' ) - { + while ( text[index] == '\n' ) { index++; } line = text+index; @@ -2072,8 +1998,7 @@ void Image::Timestamp( const char *label, const time_t when, const Coord &coord, } /* RGB32 compatible: complete */ -void Image::Colourise(const unsigned int p_reqcolours, const unsigned int p_reqsubpixelorder) -{ +void Image::Colourise(const unsigned int p_reqcolours, const unsigned int p_reqsubpixelorder) { Debug(9, "Colourise: Req colours: %u Req subpixel order: %u Current colours: %u Current subpixel order: %u",p_reqcolours,p_reqsubpixelorder,colours,subpixelorder); if ( colours != ZM_COLOUR_GRAY8) { @@ -2090,9 +2015,9 @@ void Image::Colourise(const unsigned int p_reqcolours, const unsigned int p_reqs Rgb subpixel; Rgb newpixel; - if ( p_reqsubpixelorder == ZM_SUBPIX_ORDER_ABGR || p_reqsubpixelorder == ZM_SUBPIX_ORDER_ARGB) { + if ( p_reqsubpixelorder == ZM_SUBPIX_ORDER_ABGR || p_reqsubpixelorder == ZM_SUBPIX_ORDER_ARGB ) { /* ARGB\ABGR subpixel order. alpha byte is first (mem+0), so we need to shift the pixel left in the end */ - for(unsigned int i=0;iLo().Y():0; unsigned int hi_x = limits?limits->Hi().X():width-1; unsigned int hi_y = limits?limits->Hi().Y():height-1; - if ( colours == ZM_COLOUR_GRAY8 ) - { - for ( unsigned int y = lo_y; y <= hi_y; y++ ) - { + if ( colours == ZM_COLOUR_GRAY8 ) { + for ( unsigned int y = lo_y; y <= hi_y; y++ ) { unsigned char *p = &buffer[(y*width)+lo_x]; - for ( unsigned int x = lo_x; x <= hi_x; x++, p++) - { + for ( unsigned int x = lo_x; x <= hi_x; x++, p++) { *p = colour; } } - } - else if ( colours == ZM_COLOUR_RGB24 ) - { - for ( unsigned int y = lo_y; y <= hi_y; y++ ) - { + } else if ( colours == ZM_COLOUR_RGB24 ) { + for ( unsigned int y = lo_y; y <= hi_y; y++ ) { unsigned char *p = &buffer[colours*((y*width)+lo_x)]; - for ( unsigned int x = lo_x; x <= hi_x; x++, p += 3) - { + for ( unsigned int x = lo_x; x <= hi_x; x++, p += 3) { RED_PTR_RGBA(p) = RED_VAL_RGBA(colour); GREEN_PTR_RGBA(p) = GREEN_VAL_RGBA(colour); BLUE_PTR_RGBA(p) = BLUE_VAL_RGBA(colour); } } - } - else if ( colours == ZM_COLOUR_RGB32 ) /* RGB32 */ - { - for ( unsigned int y = lo_y; y <= (unsigned int)hi_y; y++ ) - { + } else if ( colours == ZM_COLOUR_RGB32 ) /* RGB32 */ { + for ( unsigned int y = lo_y; y <= (unsigned int)hi_y; y++ ) { Rgb *p = (Rgb*)&buffer[((y*width)+lo_x)<<2]; - for ( unsigned int x = lo_x; x <= (unsigned int)hi_x; x++, p++) - { + for ( unsigned int x = lo_x; x <= (unsigned int)hi_x; x++, p++) { /* Fast, copies the entire pixel in a single pass */ *p = colour; } @@ -2245,15 +2153,13 @@ void Image::Fill( Rgb colour, const Box *limits ) } /* RGB32 compatible: complete */ -void Image::Fill( Rgb colour, int density, const Box *limits ) -{ +void Image::Fill( Rgb colour, int density, const Box *limits ) { /* Allow the faster version to be used if density is not used (density=1) */ - if(density <= 1) + if ( density <= 1 ) return Fill(colour,limits); - if ( !(colours == ZM_COLOUR_GRAY8 || colours == ZM_COLOUR_RGB24 || colours == ZM_COLOUR_RGB32 ) ) - { - Panic( "Attempt to fill image with unexpected colours %d", colours ); + if ( !(colours == ZM_COLOUR_GRAY8 || colours == ZM_COLOUR_RGB24 || colours == ZM_COLOUR_RGB32 ) ) { + Panic("Attempt to fill image with unexpected colours %d", colours); } /* Convert the colour's RGBA subpixel order into the image's subpixel order */ @@ -2263,25 +2169,18 @@ void Image::Fill( Rgb colour, int density, const Box *limits ) unsigned int lo_y = limits?limits->Lo().Y():0; unsigned int hi_x = limits?limits->Hi().X():width-1; unsigned int hi_y = limits?limits->Hi().Y():height-1; - if ( colours == ZM_COLOUR_GRAY8 ) - { - for ( unsigned int y = lo_y; y <= hi_y; y++ ) - { + if ( colours == ZM_COLOUR_GRAY8 ) { + for ( unsigned int y = lo_y; y <= hi_y; y++ ) { unsigned char *p = &buffer[(y*width)+lo_x]; - for ( unsigned int x = lo_x; x <= hi_x; x++, p++) - { + for ( unsigned int x = lo_x; x <= hi_x; x++, p++) { if ( ( x == lo_x || x == hi_x || y == lo_y || y == hi_y ) || (!(x%density) && !(y%density) ) ) *p = colour; } } - } - else if ( colours == ZM_COLOUR_RGB24 ) - { - for ( unsigned int y = lo_y; y <= hi_y; y++ ) - { + } else if ( colours == ZM_COLOUR_RGB24 ) { + for ( unsigned int y = lo_y; y <= hi_y; y++ ) { unsigned char *p = &buffer[colours*((y*width)+lo_x)]; - for ( unsigned int x = lo_x; x <= hi_x; x++, p += 3) - { + for ( unsigned int x = lo_x; x <= hi_x; x++, p += 3) { if ( ( x == lo_x || x == hi_x || y == lo_y || y == hi_y ) || (!(x%density) && !(y%density) ) ) { RED_PTR_RGBA(p) = RED_VAL_RGBA(colour); GREEN_PTR_RGBA(p) = GREEN_VAL_RGBA(colour); @@ -2289,38 +2188,30 @@ void Image::Fill( Rgb colour, int density, const Box *limits ) } } } - } - else if ( colours == ZM_COLOUR_RGB32 ) /* RGB32 */ - { - for ( unsigned int y = lo_y; y <= hi_y; y++ ) - { + } else if ( colours == ZM_COLOUR_RGB32 ) /* RGB32 */ { + for ( unsigned int y = lo_y; y <= hi_y; y++ ) { Rgb* p = (Rgb*)&buffer[((y*width)+lo_x)<<2]; - for ( unsigned int x = lo_x; x <= hi_x; x++, p++) - { + for ( unsigned int x = lo_x; x <= hi_x; x++, p++) { if ( ( x == lo_x || x == hi_x || y == lo_y || y == hi_y ) || (!(x%density) && !(y%density) ) ) /* Fast, copies the entire pixel in a single pass */ *p = colour; } } } - } /* RGB32 compatible: complete */ -void Image::Outline( Rgb colour, const Polygon &polygon ) -{ - if ( !(colours == ZM_COLOUR_GRAY8 || colours == ZM_COLOUR_RGB24 || colours == ZM_COLOUR_RGB32 ) ) - { - Panic( "Attempt to outline image with unexpected colours %d", colours ); +void Image::Outline( Rgb colour, const Polygon &polygon ) { + if ( !(colours == ZM_COLOUR_GRAY8 || colours == ZM_COLOUR_RGB24 || colours == ZM_COLOUR_RGB32 ) ) { + Panic("Attempt to outline image with unexpected colours %d", colours); } /* Convert the colour's RGBA subpixel order into the image's subpixel order */ colour = rgb_convert(colour,subpixelorder); int n_coords = polygon.getNumCoords(); - for ( int j = 0, i = n_coords-1; j < n_coords; i = j++ ) - { + for ( int j = 0, i = n_coords-1; j < n_coords; i = j++ ) { const Coord &p1 = polygon.getCoord( i ); const Coord &p2 = polygon.getCoord( j ); @@ -2335,8 +2226,7 @@ void Image::Outline( Rgb colour, const Polygon &polygon ) double grad; //Debug( 9, "dx: %.2lf, dy: %.2lf", dx, dy ); - if ( fabs(dx) <= fabs(dy) ) - { + if ( fabs(dx) <= fabs(dy) ) { //Debug( 9, "dx <= dy" ); if ( y1 != y2 ) grad = dx/dy; @@ -2346,35 +2236,25 @@ void Image::Outline( Rgb colour, const Polygon &polygon ) double x; int y, yinc = (y1 dy" ); if ( x1 != x2 ) grad = dy/dx; @@ -2385,42 +2265,31 @@ void Image::Outline( Rgb colour, const Polygon &polygon ) double y; int x, xinc = (x1= Logger::DEBUG9 ) - { - for ( int i = 0; i < n_global_edges; i++ ) - { + if ( logLevel() >= Logger::DEBUG9 ) { + for ( int i = 0; i < n_global_edges; i++ ) { Debug( 9, "%d: min_y: %d, max_y:%d, min_x:%.2f, 1/m:%.2f", i, global_edges[i].min_y, global_edges[i].max_y, global_edges[i].min_x, global_edges[i]._1_m ); } } @@ -2468,60 +2334,46 @@ void Image::Fill( Rgb colour, int density, const Polygon &polygon ) int n_active_edges = 0; Edge active_edges[n_global_edges]; int y = global_edges[0].min_y; - do - { - for ( int i = 0; i < n_global_edges; i++ ) - { - if ( global_edges[i].min_y == y ) - { - Debug( 9, "Moving global edge" ); + do { + for ( int i = 0; i < n_global_edges; i++ ) { + if ( global_edges[i].min_y == y ) { + Debug(9, "Moving global edge"); active_edges[n_active_edges++] = global_edges[i]; - if ( i < (n_global_edges-1) ) - { + if ( i < (n_global_edges-1) ) { //memcpy( &global_edges[i], &global_edges[i+1], sizeof(*global_edges)*(n_global_edges-i) ); memmove( &global_edges[i], &global_edges[i+1], sizeof(*global_edges)*(n_global_edges-i) ); i--; } n_global_edges--; - } - else - { + } else { break; } } qsort( active_edges, n_active_edges, sizeof(*active_edges), Edge::CompareX ); #ifndef ZM_DBG_OFF - if ( logLevel() >= Logger::DEBUG9 ) - { - for ( int i = 0; i < n_active_edges; i++ ) - { + if ( logLevel() >= Logger::DEBUG9 ) { + for ( int i = 0; i < n_active_edges; i++ ) { Debug( 9, "%d - %d: min_y: %d, max_y:%d, min_x:%.2f, 1/m:%.2f", y, i, active_edges[i].min_y, active_edges[i].max_y, active_edges[i].min_x, active_edges[i]._1_m ); } } #endif - if ( !(y%density) ) - { + if ( !(y%density) ) { //Debug( 9, "%d", y ); - for ( int i = 0; i < n_active_edges; ) - { + for ( int i = 0; i < n_active_edges; ) { int lo_x = int(round(active_edges[i++].min_x)); int hi_x = int(round(active_edges[i++].min_x)); - if( colours == ZM_COLOUR_GRAY8 ) { + if ( colours == ZM_COLOUR_GRAY8 ) { unsigned char *p = &buffer[(y*width)+lo_x]; - for ( int x = lo_x; x <= hi_x; x++, p++) - { - if ( !(x%density) ) - { + for ( int x = lo_x; x <= hi_x; x++, p++) { + if ( !(x%density) ) { //Debug( 9, " %d", x ); *p = colour; } } - } else if( colours == ZM_COLOUR_RGB24 ) { + } else if ( colours == ZM_COLOUR_RGB24 ) { unsigned char *p = &buffer[colours*((y*width)+lo_x)]; - for ( int x = lo_x; x <= hi_x; x++, p += 3) - { - if ( !(x%density) ) - { + for ( int x = lo_x; x <= hi_x; x++, p += 3) { + if ( !(x%density) ) { RED_PTR_RGBA(p) = RED_VAL_RGBA(colour); GREEN_PTR_RGBA(p) = GREEN_VAL_RGBA(colour); BLUE_PTR_RGBA(p) = BLUE_VAL_RGBA(colour); @@ -2529,10 +2381,8 @@ void Image::Fill( Rgb colour, int density, const Polygon &polygon ) } } else if( colours == ZM_COLOUR_RGB32 ) { Rgb *p = (Rgb*)&buffer[((y*width)+lo_x)<<2]; - for ( int x = lo_x; x <= hi_x; x++, p++) - { - if ( !(x%density) ) - { + for ( int x = lo_x; x <= hi_x; x++, p++) { + if ( !(x%density) ) { /* Fast, copies the entire pixel in a single pass */ *p = colour; } @@ -2541,43 +2391,35 @@ void Image::Fill( Rgb colour, int density, const Polygon &polygon ) } } y++; - for ( int i = n_active_edges-1; i >= 0; i-- ) - { - if ( y >= active_edges[i].max_y ) // Or >= as per sheets - { + for ( int i = n_active_edges-1; i >= 0; i-- ) { + if ( y >= active_edges[i].max_y ) { + // Or >= as per sheets Debug( 9, "Deleting active_edge" ); - if ( i < (n_active_edges-1) ) - { + if ( i < (n_active_edges-1) ) { //memcpy( &active_edges[i], &active_edges[i+1], sizeof(*active_edges)*(n_active_edges-i) ); memmove( &active_edges[i], &active_edges[i+1], sizeof(*active_edges)*(n_active_edges-i) ); } n_active_edges--; - } - else - { + } else { active_edges[i].min_x += active_edges[i]._1_m; } } } while ( n_global_edges || n_active_edges ); } -void Image::Fill( Rgb colour, const Polygon &polygon ) -{ +void Image::Fill( Rgb colour, const Polygon &polygon ) { Fill( colour, 1, polygon ); } /* RGB32 compatible: complete */ -void Image::Rotate( int angle ) -{ +void Image::Rotate( int angle ) { angle %= 360; - if ( !angle ) - { + if ( !angle ) { return; } - if ( angle%90 ) - { + if ( angle%90 ) { return; } @@ -2708,39 +2550,28 @@ void Image::Flip( bool leftright ) { unsigned char *d_ptr = flip_buffer; unsigned char *max_d_ptr = flip_buffer + size; - if ( colours == ZM_COLOUR_GRAY8 ) - { - while( d_ptr < max_d_ptr ) - { - for ( unsigned int j = 0; j < width; j++ ) - { + if ( colours == ZM_COLOUR_GRAY8 ) { + while( d_ptr < max_d_ptr ) { + for ( unsigned int j = 0; j < width; j++ ) { s_ptr--; *d_ptr++ = *s_ptr; } s_ptr += line_bytes2; } - } - else if ( colours == ZM_COLOUR_RGB32 ) - { + } else if ( colours == ZM_COLOUR_RGB32 ) { Rgb* s_rptr = (Rgb*)s_ptr; Rgb* d_rptr = (Rgb*)flip_buffer; Rgb* max_d_rptr = (Rgb*)max_d_ptr; - while( d_rptr < max_d_rptr ) - { - for ( unsigned int j = 0; j < width; j++ ) - { + while( d_rptr < max_d_rptr ) { + for ( unsigned int j = 0; j < width; j++ ) { s_rptr--; *d_rptr++ = *s_rptr; } s_rptr += width * 2; } - } - else /* Assume RGB24 */ - { - while( d_ptr < max_d_ptr ) - { - for ( unsigned int j = 0; j < width; j++ ) - { + } else /* Assume RGB24 */ { + while( d_ptr < max_d_ptr ) { + for ( unsigned int j = 0; j < width; j++ ) { s_ptr -= 3; *d_ptr++ = *s_ptr; *d_ptr++ = *(s_ptr+1); @@ -2749,15 +2580,12 @@ void Image::Flip( bool leftright ) { s_ptr += line_bytes2; } } - } - else - { + } else { // Vertical flip, top to bottom unsigned char *s_ptr = buffer+(height*line_bytes); unsigned char *d_ptr = flip_buffer; - while( s_ptr > buffer ) - { + while( s_ptr > buffer ) { s_ptr -= line_bytes; memcpy( d_ptr, s_ptr, line_bytes ); d_ptr += line_bytes; @@ -2768,15 +2596,12 @@ void Image::Flip( bool leftright ) { } -void Image::Scale( unsigned int factor ) -{ - if ( !factor ) - { +void Image::Scale( unsigned int factor ) { + if ( !factor ) { Error( "Bogus scale factor %d found", factor ); return; } - if ( factor == ZM_SCALE_BASE ) - { + if ( factor == ZM_SCALE_BASE ) { return; } @@ -2787,8 +2612,7 @@ void Image::Scale( unsigned int factor ) uint8_t* scale_buffer = AllocBuffer(scale_buffer_size); - if ( factor > ZM_SCALE_BASE ) - { + if ( factor > ZM_SCALE_BASE ) { unsigned char *pd = scale_buffer; unsigned int wc = width*colours; unsigned int nwc = new_width*colours; @@ -2796,20 +2620,16 @@ void Image::Scale( unsigned int factor ) unsigned int last_h_index = 0; unsigned int last_w_index = 0; unsigned int h_index; - for ( unsigned int y = 0; y < height; y++ ) - { + for ( unsigned int y = 0; y < height; y++ ) { unsigned char *ps = &buffer[y*wc]; unsigned int w_count = ZM_SCALE_BASE/2; unsigned int w_index; last_w_index = 0; - for ( unsigned int x = 0; x < width; x++ ) - { + for ( unsigned int x = 0; x < width; x++ ) { w_count += factor; w_index = w_count/ZM_SCALE_BASE; - for (unsigned int f = last_w_index; f < w_index; f++ ) - { - for ( unsigned int c = 0; c < colours; c++ ) - { + for (unsigned int f = last_w_index; f < w_index; f++ ) { + for ( unsigned int c = 0; c < colours; c++ ) { *pd++ = *(ps+c); } } @@ -2818,8 +2638,7 @@ void Image::Scale( unsigned int factor ) } h_count += factor; h_index = h_count/ZM_SCALE_BASE; - for ( unsigned int f = last_h_index+1; f < h_index; f++ ) - { + for ( unsigned int f = last_h_index+1; f < h_index; f++ ) { memcpy( pd, pd-nwc, nwc ); pd += nwc; } @@ -2827,9 +2646,7 @@ void Image::Scale( unsigned int factor ) } new_width = last_w_index; new_height = last_h_index; - } - else - { + } else { unsigned char *pd = scale_buffer; unsigned int wc = width*colours; unsigned int xstart = factor/2; @@ -2838,31 +2655,24 @@ void Image::Scale( unsigned int factor ) unsigned int last_h_index = 0; unsigned int last_w_index = 0; unsigned int h_index; - for ( unsigned int y = 0; y < (unsigned int)height; y++ ) - { + for ( unsigned int y = 0; y < (unsigned int)height; y++ ) { h_count += factor; h_index = h_count/ZM_SCALE_BASE; - if ( h_index > last_h_index ) - { + if ( h_index > last_h_index ) { unsigned int w_count = xstart; unsigned int w_index; last_w_index = 0; unsigned char *ps = &buffer[y*wc]; - for ( unsigned int x = 0; x < (unsigned int)width; x++ ) - { + for ( unsigned int x = 0; x < (unsigned int)width; x++ ) { w_count += factor; w_index = w_count/ZM_SCALE_BASE; - if ( w_index > last_w_index ) - { - for ( unsigned int c = 0; c < colours; c++ ) - { + if ( w_index > last_w_index ) { + for ( unsigned int c = 0; c < colours; c++ ) { *pd++ = *ps++; } - } - else - { + } else { ps += colours; } last_w_index = w_index; @@ -2878,29 +2688,23 @@ void Image::Scale( unsigned int factor ) } -void Image::Deinterlace_Discard() -{ +void Image::Deinterlace_Discard() { /* Simple deinterlacing. Copy the even lines into the odd lines */ - if ( colours == ZM_COLOUR_GRAY8 ) - { + if ( colours == ZM_COLOUR_GRAY8 ) { const uint8_t *psrc; uint8_t *pdest; - for (unsigned int y = 0; y < (unsigned int)height; y += 2) - { + for (unsigned int y = 0; y < (unsigned int)height; y += 2) { psrc = buffer + (y * width); pdest = buffer + ((y+1) * width); for (unsigned int x = 0; x < (unsigned int)width; x++) { *pdest++ = *psrc++; } } - } - else if ( colours == ZM_COLOUR_RGB24 ) - { + } else if ( colours == ZM_COLOUR_RGB24 ) { const uint8_t *psrc; uint8_t *pdest; - for (unsigned int y = 0; y < (unsigned int)height; y += 2) - { + for (unsigned int y = 0; y < (unsigned int)height; y += 2) { psrc = buffer + ((y * width) * 3); pdest = buffer + (((y+1) * width) * 3); for (unsigned int x = 0; x < (unsigned int)width; x++) { @@ -2909,13 +2713,10 @@ void Image::Deinterlace_Discard() *pdest++ = *psrc++; } } - } - else if ( colours == ZM_COLOUR_RGB32 ) - { + } else if ( colours == ZM_COLOUR_RGB32 ) { const Rgb *psrc; Rgb *pdest; - for (unsigned int y = 0; y < (unsigned int)height; y += 2) - { + for (unsigned int y = 0; y < (unsigned int)height; y += 2) { psrc = (Rgb*)(buffer + ((y * width) << 2)); pdest = (Rgb*)(buffer + (((y+1) * width) << 2)); for (unsigned int x = 0; x < (unsigned int)width; x++) { @@ -2928,17 +2729,14 @@ void Image::Deinterlace_Discard() } -void Image::Deinterlace_Linear() -{ +void Image::Deinterlace_Linear() { /* Simple deinterlacing. The odd lines are average of the line above and line below */ const uint8_t *pbelow, *pabove; uint8_t *pcurrent; - if ( colours == ZM_COLOUR_GRAY8 ) - { - for (unsigned int y = 1; y < (unsigned int)(height-1); y += 2) - { + if ( colours == ZM_COLOUR_GRAY8 ) { + for (unsigned int y = 1; y < (unsigned int)(height-1); y += 2) { pabove = buffer + ((y-1) * width); pbelow = buffer + ((y+1) * width); pcurrent = buffer + (y * width); @@ -2952,11 +2750,8 @@ void Image::Deinterlace_Linear() for (unsigned int x = 0; x < (unsigned int)width; x++) { *pcurrent++ = *pabove++; } - } - else if ( colours == ZM_COLOUR_RGB24 ) - { - for (unsigned int y = 1; y < (unsigned int)(height-1); y += 2) - { + } else if ( colours == ZM_COLOUR_RGB24 ) { + for (unsigned int y = 1; y < (unsigned int)(height-1); y += 2) { pabove = buffer + (((y-1) * width) * 3); pbelow = buffer + (((y+1) * width) * 3); pcurrent = buffer + ((y * width) * 3); @@ -2974,11 +2769,8 @@ void Image::Deinterlace_Linear() *pcurrent++ = *pabove++; *pcurrent++ = *pabove++; } - } - else if ( colours == ZM_COLOUR_RGB32 ) - { - for (unsigned int y = 1; y < (unsigned int)(height-1); y += 2) - { + } else if ( colours == ZM_COLOUR_RGB32 ) { + for (unsigned int y = 1; y < (unsigned int)(height-1); y += 2) { pabove = buffer + (((y-1) * width) << 2); pbelow = buffer + (((y+1) * width) << 2); pcurrent = buffer + ((y * width) << 2); @@ -3004,16 +2796,13 @@ void Image::Deinterlace_Linear() } -void Image::Deinterlace_Blend() -{ +void Image::Deinterlace_Blend() { /* Simple deinterlacing. Blend the fields together. 50% blend */ uint8_t *pabove, *pcurrent; - if ( colours == ZM_COLOUR_GRAY8 ) - { - for (unsigned int y = 1; y < (unsigned int)height; y += 2) - { + if ( colours == ZM_COLOUR_GRAY8 ) { + for (unsigned int y = 1; y < (unsigned int)height; y += 2) { pabove = buffer + ((y-1) * width); pcurrent = buffer + (y * width); for (unsigned int x = 0; x < (unsigned int)width; x++) { @@ -3021,11 +2810,8 @@ void Image::Deinterlace_Blend() *pcurrent++ = *pabove++; } } - } - else if ( colours == ZM_COLOUR_RGB24 ) - { - for (unsigned int y = 1; y < (unsigned int)height; y += 2) - { + } else if ( colours == ZM_COLOUR_RGB24 ) { + for (unsigned int y = 1; y < (unsigned int)height; y += 2) { pabove = buffer + (((y-1) * width) * 3); pcurrent = buffer + ((y * width) * 3); for (unsigned int x = 0; x < (unsigned int)width; x++) { @@ -3037,11 +2823,8 @@ void Image::Deinterlace_Blend() *pcurrent++ = *pabove++; } } - } - else if ( colours == ZM_COLOUR_RGB32 ) - { - for (unsigned int y = 1; y < (unsigned int)height; y += 2) - { + } else if ( colours == ZM_COLOUR_RGB32 ) { + for (unsigned int y = 1; y < (unsigned int)height; y += 2) { pabove = buffer + (((y-1) * width) << 2); pcurrent = buffer + ((y * width) << 2); for (unsigned int x = 0; x < (unsigned int)width; x++) { @@ -3061,8 +2844,7 @@ void Image::Deinterlace_Blend() } -void Image::Deinterlace_Blend_CustomRatio(int divider) -{ +void Image::Deinterlace_Blend_CustomRatio(int divider) { /* Simple deinterlacing. Blend the fields together at a custom ratio. */ /* 1 = 50% blending */ /* 2 = 25% blending */ @@ -3076,10 +2858,8 @@ void Image::Deinterlace_Blend_CustomRatio(int divider) Error("Deinterlace called with invalid blend ratio"); } - if ( colours == ZM_COLOUR_GRAY8 ) - { - for (unsigned int y = 1; y < (unsigned int)height; y += 2) - { + if ( colours == ZM_COLOUR_GRAY8 ) { + for (unsigned int y = 1; y < (unsigned int)height; y += 2) { pabove = buffer + ((y-1) * width); pcurrent = buffer + (y * width); for (unsigned int x = 0; x < (unsigned int)width; x++) { @@ -3089,11 +2869,8 @@ void Image::Deinterlace_Blend_CustomRatio(int divider) *pabove++ = subpix2; } } - } - else if ( colours == ZM_COLOUR_RGB24 ) - { - for (unsigned int y = 1; y < (unsigned int)height; y += 2) - { + } else if ( colours == ZM_COLOUR_RGB24 ) { + for (unsigned int y = 1; y < (unsigned int)height; y += 2) { pabove = buffer + (((y-1) * width) * 3); pcurrent = buffer + ((y * width) * 3); for (unsigned int x = 0; x < (unsigned int)width; x++) { @@ -3111,11 +2888,8 @@ void Image::Deinterlace_Blend_CustomRatio(int divider) *pabove++ = subpix2; } } - } - else if ( colours == ZM_COLOUR_RGB32 ) - { - for (unsigned int y = 1; y < (unsigned int)height; y += 2) - { + } else if ( colours == ZM_COLOUR_RGB32 ) { + for (unsigned int y = 1; y < (unsigned int)height; y += 2) { pabove = buffer + (((y-1) * width) << 2); pcurrent = buffer + ((y * width) << 2); for (unsigned int x = 0; x < (unsigned int)width; x++) { @@ -3203,25 +2977,25 @@ void sse2_fastblend(const uint8_t* col1, const uint8_t* col2, uint8_t* result, u static uint32_t clearmask = 0; static double current_blendpercent = 0.0; - if(current_blendpercent != blendpercent) { + if ( current_blendpercent != blendpercent ) { /* Attempt to match the blending percent to one of the possible values */ - if(blendpercent < 2.34375) { + if ( blendpercent < 2.34375 ) { // 1.5625% blending divider = 6; clearmask = 0x03030303; - } else if(blendpercent < 4.6875) { + } else if ( blendpercent < 4.6875 ) { // 3.125% blending divider = 5; clearmask = 0x07070707; - } else if(blendpercent < 9.375) { + } else if ( blendpercent < 9.375 ) { // 6.25% blending divider = 4; clearmask = 0x0F0F0F0F; - } else if(blendpercent < 18.75) { + } else if ( blendpercent < 18.75 ) { // 12.5% blending divider = 3; clearmask = 0x1F1F1F1F; - } else if(blendpercent < 37.5) { + } else if ( blendpercent < 37.5 ) { // 25% blending divider = 2; clearmask = 0x3F3F3F3F; @@ -3267,21 +3041,21 @@ __attribute__((noinline)) void std_fastblend(const uint8_t* col1, const uint8_t* static double current_blendpercent = 0.0; const uint8_t* const max_ptr = result + count; - if(current_blendpercent != blendpercent) { + if ( current_blendpercent != blendpercent ) { /* Attempt to match the blending percent to one of the possible values */ - if(blendpercent < 2.34375) { + if ( blendpercent < 2.34375 ) { // 1.5625% blending divider = 6; - } else if(blendpercent < 4.6875) { + } else if ( blendpercent < 4.6875 ) { // 3.125% blending divider = 5; - } else if(blendpercent < 9.375) { + } else if ( blendpercent < 9.375 ) { // 6.25% blending divider = 4; - } else if(blendpercent < 18.75) { + } else if ( blendpercent < 18.75 ) { // 12.5% blending divider = 3; - } else if(blendpercent < 37.5) { + } else if ( blendpercent < 37.5 ) { // 25% blending divider = 2; } else { @@ -3291,8 +3065,7 @@ __attribute__((noinline)) void std_fastblend(const uint8_t* col1, const uint8_t* current_blendpercent = blendpercent; } - - while(result < max_ptr) { + while ( result < max_ptr ) { result[0] = ((col2[0] - col1[0])>>divider) + col1[0]; result[1] = ((col2[1] - col1[1])>>divider) + col1[1]; result[2] = ((col2[2] - col1[2])>>divider) + col1[2]; @@ -3490,9 +3263,8 @@ __attribute__((noinline)) void std_blend(const uint8_t* col1, const uint8_t* col double opacity = 1.0 - divide; const uint8_t* const max_ptr = result + count; - while(result < max_ptr) { + while ( result < max_ptr ) { *result++ = (*col1++ * opacity) + (*col2++ * divide); - } } @@ -4692,8 +4464,7 @@ __attribute__((noinline)) void zm_convert_rgb565_rgba(const uint8_t* col1, uint8 /************************************************* DEINTERLACE FUNCTIONS *************************************************/ /* Grayscale */ -__attribute__((noinline)) void std_deinterlace_4field_gray8(uint8_t* col1, uint8_t* col2, unsigned int threshold, unsigned int width, unsigned int height) -{ +__attribute__((noinline)) void std_deinterlace_4field_gray8(uint8_t* col1, uint8_t* col2, unsigned int threshold, unsigned int width, unsigned int height) { uint8_t *pcurrent, *pabove, *pncurrent, *pnabove, *pbelow; const uint8_t* const max_ptr = col1 + (width*(height-1)); const uint8_t *max_ptr2; @@ -4703,8 +4474,7 @@ __attribute__((noinline)) void std_deinterlace_4field_gray8(uint8_t* col1, uint8 pabove = col1; pnabove = col2; pbelow = col1 + (width*2); - while(pcurrent < max_ptr) - { + while(pcurrent < max_ptr) { max_ptr2 = pcurrent + width; while(pcurrent < max_ptr2) { if((unsigned int)((abs(*pnabove - *pabove) + abs(*pncurrent - *pcurrent)) >> 1) >= threshold) { @@ -4721,7 +4491,6 @@ __attribute__((noinline)) void std_deinterlace_4field_gray8(uint8_t* col1, uint8 pabove += width; pnabove += width; pbelow += width; - } /* Special case for the last line */ @@ -4738,8 +4507,7 @@ __attribute__((noinline)) void std_deinterlace_4field_gray8(uint8_t* col1, uint8 } /* RGB */ -__attribute__((noinline)) void std_deinterlace_4field_rgb(uint8_t* col1, uint8_t* col2, unsigned int threshold, unsigned int width, unsigned int height) -{ +__attribute__((noinline)) void std_deinterlace_4field_rgb(uint8_t* col1, uint8_t* col2, unsigned int threshold, unsigned int width, unsigned int height) { uint8_t *pcurrent, *pabove, *pncurrent, *pnabove, *pbelow; const unsigned int row_width = width*3; const uint8_t* const max_ptr = col1 + (row_width * (height-1)); @@ -4752,8 +4520,7 @@ __attribute__((noinline)) void std_deinterlace_4field_rgb(uint8_t* col1, uint8_t pabove = col1; pnabove = col2; pbelow = col1 + ((width*2)*3); - while(pcurrent < max_ptr) - { + while(pcurrent < max_ptr) { max_ptr2 = pcurrent + row_width; while(pcurrent < max_ptr2) { r = abs(pnabove[0] - pabove[0]); @@ -4780,7 +4547,6 @@ __attribute__((noinline)) void std_deinterlace_4field_rgb(uint8_t* col1, uint8_t pabove += row_width; pnabove += row_width; pbelow += row_width; - } /* Special case for the last line */ @@ -4807,8 +4573,7 @@ __attribute__((noinline)) void std_deinterlace_4field_rgb(uint8_t* col1, uint8_t } /* BGR */ -__attribute__((noinline)) void std_deinterlace_4field_bgr(uint8_t* col1, uint8_t* col2, unsigned int threshold, unsigned int width, unsigned int height) -{ +__attribute__((noinline)) void std_deinterlace_4field_bgr(uint8_t* col1, uint8_t* col2, unsigned int threshold, unsigned int width, unsigned int height) { uint8_t *pcurrent, *pabove, *pncurrent, *pnabove, *pbelow; const unsigned int row_width = width*3; const uint8_t* const max_ptr = col1 + (row_width * (height-1)); @@ -4821,8 +4586,7 @@ __attribute__((noinline)) void std_deinterlace_4field_bgr(uint8_t* col1, uint8_t pabove = col1; pnabove = col2; pbelow = col1 + ((width*2)*3); - while(pcurrent < max_ptr) - { + while(pcurrent < max_ptr) { max_ptr2 = pcurrent + row_width; while(pcurrent < max_ptr2) { b = abs(pnabove[0] - pabove[0]); @@ -4876,8 +4640,7 @@ __attribute__((noinline)) void std_deinterlace_4field_bgr(uint8_t* col1, uint8_t } /* RGBA */ -__attribute__((noinline)) void std_deinterlace_4field_rgba(uint8_t* col1, uint8_t* col2, unsigned int threshold, unsigned int width, unsigned int height) -{ +__attribute__((noinline)) void std_deinterlace_4field_rgba(uint8_t* col1, uint8_t* col2, unsigned int threshold, unsigned int width, unsigned int height) { uint8_t *pcurrent, *pabove, *pncurrent, *pnabove, *pbelow; const unsigned int row_width = width*4; const uint8_t* const max_ptr = col1 + (row_width * (height-1)); @@ -4890,8 +4653,7 @@ __attribute__((noinline)) void std_deinterlace_4field_rgba(uint8_t* col1, uint8_ pabove = col1; pnabove = col2; pbelow = col1 + (row_width*2); - while(pcurrent < max_ptr) - { + while(pcurrent < max_ptr) { max_ptr2 = pcurrent + row_width; while(pcurrent < max_ptr2) { r = abs(pnabove[0] - pabove[0]); @@ -4918,7 +4680,6 @@ __attribute__((noinline)) void std_deinterlace_4field_rgba(uint8_t* col1, uint8_ pabove += row_width; pnabove += row_width; pbelow += row_width; - } /* Special case for the last line */ @@ -4945,8 +4706,7 @@ __attribute__((noinline)) void std_deinterlace_4field_rgba(uint8_t* col1, uint8_ } /* BGRA */ -__attribute__((noinline)) void std_deinterlace_4field_bgra(uint8_t* col1, uint8_t* col2, unsigned int threshold, unsigned int width, unsigned int height) -{ +__attribute__((noinline)) void std_deinterlace_4field_bgra(uint8_t* col1, uint8_t* col2, unsigned int threshold, unsigned int width, unsigned int height) { uint8_t *pcurrent, *pabove, *pncurrent, *pnabove, *pbelow; const unsigned int row_width = width*4; const uint8_t* const max_ptr = col1 + (row_width * (height-1)); @@ -4959,8 +4719,7 @@ __attribute__((noinline)) void std_deinterlace_4field_bgra(uint8_t* col1, uint8_ pabove = col1; pnabove = col2; pbelow = col1 + (row_width*2); - while(pcurrent < max_ptr) - { + while(pcurrent < max_ptr) { max_ptr2 = pcurrent + row_width; while(pcurrent < max_ptr2) { b = abs(pnabove[0] - pabove[0]); @@ -4987,7 +4746,6 @@ __attribute__((noinline)) void std_deinterlace_4field_bgra(uint8_t* col1, uint8_ pabove += row_width; pnabove += row_width; pbelow += row_width; - } /* Special case for the last line */ @@ -5014,8 +4772,7 @@ __attribute__((noinline)) void std_deinterlace_4field_bgra(uint8_t* col1, uint8_ } /* ARGB */ -__attribute__((noinline)) void std_deinterlace_4field_argb(uint8_t* col1, uint8_t* col2, unsigned int threshold, unsigned int width, unsigned int height) -{ +__attribute__((noinline)) void std_deinterlace_4field_argb(uint8_t* col1, uint8_t* col2, unsigned int threshold, unsigned int width, unsigned int height) { uint8_t *pcurrent, *pabove, *pncurrent, *pnabove, *pbelow; const unsigned int row_width = width*4; const uint8_t* const max_ptr = col1 + (row_width * (height-1)); @@ -5028,8 +4785,7 @@ __attribute__((noinline)) void std_deinterlace_4field_argb(uint8_t* col1, uint8_ pabove = col1; pnabove = col2; pbelow = col1 + (row_width*2); - while(pcurrent < max_ptr) - { + while(pcurrent < max_ptr) { max_ptr2 = pcurrent + row_width; while(pcurrent < max_ptr2) { r = abs(pnabove[1] - pabove[1]); @@ -5056,7 +4812,6 @@ __attribute__((noinline)) void std_deinterlace_4field_argb(uint8_t* col1, uint8_ pabove += row_width; pnabove += row_width; pbelow += row_width; - } /* Special case for the last line */ @@ -5083,8 +4838,7 @@ __attribute__((noinline)) void std_deinterlace_4field_argb(uint8_t* col1, uint8_ } /* ABGR */ -__attribute__((noinline)) void std_deinterlace_4field_abgr(uint8_t* col1, uint8_t* col2, unsigned int threshold, unsigned int width, unsigned int height) -{ +__attribute__((noinline)) void std_deinterlace_4field_abgr(uint8_t* col1, uint8_t* col2, unsigned int threshold, unsigned int width, unsigned int height) { uint8_t *pcurrent, *pabove, *pncurrent, *pnabove, *pbelow; const unsigned int row_width = width*4; const uint8_t* const max_ptr = col1 + (row_width * (height-1)); @@ -5097,8 +4851,7 @@ __attribute__((noinline)) void std_deinterlace_4field_abgr(uint8_t* col1, uint8_ pabove = col1; pnabove = col2; pbelow = col1 + (row_width*2); - while(pcurrent < max_ptr) - { + while(pcurrent < max_ptr) { max_ptr2 = pcurrent + row_width; while(pcurrent < max_ptr2) { b = abs(pnabove[1] - pabove[1]); diff --git a/src/zm_image.h b/src/zm_image.h index dafd067f1..66e7ef32e 100644 --- a/src/zm_image.h +++ b/src/zm_image.h @@ -274,6 +274,7 @@ void std_delta8_rgba(const uint8_t* col1, const uint8_t* col2, uint8_t* result, void std_delta8_bgra(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count); void std_delta8_argb(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count); void std_delta8_abgr(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count); + void neon32_armv7_delta8_gray8(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count); void neon32_armv7_delta8_rgba(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count); void neon32_armv7_delta8_bgra(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count); diff --git a/web/api/app/Controller/HostController.php b/web/api/app/Controller/HostController.php index f0df3797e..017bce798 100644 --- a/web/api/app/Controller/HostController.php +++ b/web/api/app/Controller/HostController.php @@ -69,7 +69,7 @@ class HostController extends AppController { $this->Session->read('user'); # this is needed for command line/curl to recognize a session $zmAuthRelay = $this->Config->find('first',array('conditions' => array('Config.' . $this->Config->primaryKey => 'ZM_AUTH_RELAY')))['Config']['Value']; if ( $zmAuthRelay == 'hashed' ) { - $zmAuthHashIps= $this->Config->find('first',array('conditions' => array('Config.' . $this->Config->primaryKey => 'ZM_AUTH_HASH_IPS')))['Config']['Value']; + $zmAuthHashIps = $this->Config->find('first',array('conditions' => array('Config.' . $this->Config->primaryKey => 'ZM_AUTH_HASH_IPS')))['Config']['Value']; $credentials = 'auth='.generateAuthHash($zmAuthHashIps); } else if ( $zmAuthRelay == 'plain' ) { // user will need to append the store password here diff --git a/web/includes/auth.php b/web/includes/auth.php index 13f259572..c74c13b80 100644 --- a/web/includes/auth.php +++ b/web/includes/auth.php @@ -155,7 +155,7 @@ function generateAuthHash($useRemoteAddr, $force=false) { $time = time(); $mintime = $time - ( ZM_AUTH_HASH_TTL * 1800 ); - if ( $force or ( !isset($_SESSION['AuthHash']) ) or ( $_SESSION['AuthHashGeneratedAt'] < $mintime ) ) { + if ( $force or ( !isset($_SESSION['AuthHash'.$_SESSION['remoteAddr']]) ) or ( $_SESSION['AuthHashGeneratedAt'] < $mintime ) ) { # Don't both regenerating Auth Hash if an hour hasn't gone by yet $local_time = localtime(); $authKey = ''; @@ -172,7 +172,7 @@ function generateAuthHash($useRemoteAddr, $force=false) { session_start(); $close_session = 1; } - $_SESSION['AuthHash'] = $auth; + $_SESSION['AuthHash'.$_SESSION['remoteAddr']] = $auth; $_SESSION['AuthHashGeneratedAt'] = $time; session_write_close(); } else { @@ -182,7 +182,7 @@ function generateAuthHash($useRemoteAddr, $force=false) { #} else { #Logger::Debug("Using cached auth " . $_SESSION['AuthHash'] ." beacuse generatedat:" . $_SESSION['AuthHashGeneratedAt'] . ' < now:'. $time . ' - ' . ZM_AUTH_HASH_TTL . ' * 1800 = '. $mintime); } # end if AuthHash is not cached - return $_SESSION['AuthHash']; + return $_SESSION['AuthHash'.$_SESSION['remoteAddr']]; } # end if using AUTH and AUTH_RELAY return ''; } diff --git a/web/lang/en_gb.php b/web/lang/en_gb.php index 92c171cb6..7b2addeb4 100644 --- a/web/lang/en_gb.php +++ b/web/lang/en_gb.php @@ -237,6 +237,7 @@ $SLANG = array( 'Cause' => 'Cause', 'CheckMethod' => 'Alarm Check Method', 'ChooseDetectedCamera' => 'Choose Detected Camera', + 'ChooseDetectedProfile' => 'Choose Detected Profile', 'ChooseFilter' => 'Choose Filter', 'ChooseLogFormat' => 'Choose a log format', 'ChooseLogSelection' => 'Choose a log selection', diff --git a/web/skins/classic/js/skin.js.php b/web/skins/classic/js/skin.js.php index f072a911e..b15ff51a5 100644 --- a/web/skins/classic/js/skin.js.php +++ b/web/skins/classic/js/skin.js.php @@ -55,7 +55,7 @@ if ( ! empty($refreshParent) ) { ?>; var closePopup = "; var auth_hash; -auth_hash = ''; +auth_hash = ''; diff --git a/web/skins/classic/views/js/zone.js b/web/skins/classic/views/js/zone.js index 023671588..6389e3ce9 100644 --- a/web/skins/classic/views/js/zone.js +++ b/web/skins/classic/views/js/zone.js @@ -471,7 +471,13 @@ function setAlarmState( currentAlarmState ) { } var streamCmdParms = "view=request&request=stream&connkey="+connKey; -var streamCmdReq = new Request.JSON( { url: monitorUrl+thisUrl, method: 'post', timeout: AJAX_TIMEOUT, link: 'cancel', onSuccess: getStreamCmdResponse } ); +var streamCmdReq = new Request.JSON( { + url: monitorUrl, + method: 'get', + timeout: AJAX_TIMEOUT, + link: 'cancel', + onSuccess: getStreamCmdResponse +} ); var streamCmdTimer = null; var streamStatus; @@ -546,7 +552,14 @@ function streamCmdQuery() { } var statusCmdParms = "view=request&request=status&entity=monitor&id="+monitorId+"&element[]=Status&element[]=FrameRate"; -var statusCmdReq = new Request.JSON( { url: monitorUrl+thisUrl, method: 'post', data: statusCmdParms, timeout: AJAX_TIMEOUT, link: 'cancel', onSuccess: getStatusCmdResponse } ); +var statusCmdReq = new Request.JSON( { + url: monitorUrl, + method: 'get', + data: statusCmdParms, + timeout: AJAX_TIMEOUT, + link: 'cancel', + onSuccess: getStatusCmdResponse +} ); var statusCmdTimer = null; function getStatusCmdResponse( respObj, respText ) { @@ -652,11 +665,13 @@ function initPage() { // Imported from watch.js and modified for new zone edit view // + var delay = (Math.random()+0.1)*statusRefreshTimeout; + //console.log("Delay for status updates is: " + delay ); if ( streamMode == "single" ) { - statusCmdTimer = statusCmdQuery.delay( (Math.random()+0.1)*statusRefreshTimeout ); + statusCmdTimer = statusCmdQuery.delay( delay ); watchdogCheck.pass('status').periodical(statusRefreshTimeout*2); } else { - streamCmdTimer = streamCmdQuery.delay( (Math.random()+0.1)*statusRefreshTimeout ); + streamCmdTimer = streamCmdQuery.delay( delay ); watchdogCheck.pass('stream').periodical(statusRefreshTimeout*2); } diff --git a/web/skins/classic/views/js/zone.js.php b/web/skins/classic/views/js/zone.js.php index 49946f767..434fec679 100644 --- a/web/skins/classic/views/js/zone.js.php +++ b/web/skins/classic/views/js/zone.js.php @@ -101,7 +101,7 @@ var streamMode = ""; var connKey = ''; var monitorId = Id() ?>; -var monitorUrl = 'Server()->Url() ) ?>'; +var monitorUrl = 'Url() ) ?>'; var streamSrc = ""; diff --git a/web/skins/classic/views/js/zones.js b/web/skins/classic/views/js/zones.js index a01f8b56f..9ada175bc 100644 --- a/web/skins/classic/views/js/zones.js +++ b/web/skins/classic/views/js/zones.js @@ -1,5 +1,5 @@ var streamCmdParms = "view=request&request=stream&connkey="+connKey; -var streamCmdReq = new Request.JSON( { url: monitorUrl+thisUrl, method: 'post', timeout: AJAX_TIMEOUT, link: 'cancel' } ); +var streamCmdReq = new Request.JSON( { url: monitorUrl, method: 'post', timeout: AJAX_TIMEOUT, link: 'cancel' } ); function streamCmdQuit( action ) { if ( action ) diff --git a/web/skins/classic/views/js/zones.js.php b/web/skins/classic/views/js/zones.js.php index ca234085e..d7144d18a 100644 --- a/web/skins/classic/views/js/zones.js.php +++ b/web/skins/classic/views/js/zones.js.php @@ -1,4 +1,4 @@ var connKey = ''; -var monitorUrl = 'Server()->Url() ) ?>'; +var monitorUrl = 'Url() ) ?>'; var CMD_QUIT = ; diff --git a/web/skins/classic/views/log.php b/web/skins/classic/views/log.php index 4f2650865..d13381e2f 100644 --- a/web/skins/classic/views/log.php +++ b/web/skins/classic/views/log.php @@ -45,17 +45,16 @@ xhtmlHeaders(__FILE__, translate('SystemLog') );
- - - - - + + + + +
- - - - + + +
@@ -89,7 +88,7 @@ xhtmlHeaders(__FILE__, translate('SystemLog') ); - +
@@ -137,8 +136,8 @@ xhtmlHeaders(__FILE__, translate('SystemLog') );
:
- - + +
diff --git a/web/skins/classic/views/monitor.php b/web/skins/classic/views/monitor.php index fa2ebd44f..193b08d36 100644 --- a/web/skins/classic/views/monitor.php +++ b/web/skins/classic/views/monitor.php @@ -173,7 +173,7 @@ if ( !empty($_REQUEST['preset']) ) { } } if ( !empty($_REQUEST['probe']) ) { - $probe = unserialize(base64_decode($_REQUEST['probe'])); + $probe = json_decode(base64_decode($_REQUEST['probe'])); foreach ( $probe as $name=>$value ) { if ( isset($value) ) { # Does isset handle NULL's? I don't think this code is correct. diff --git a/web/skins/classic/views/onvifprobe.php b/web/skins/classic/views/onvifprobe.php index f9c766846..ddbd895b6 100644 --- a/web/skins/classic/views/onvifprobe.php +++ b/web/skins/classic/views/onvifprobe.php @@ -18,7 +18,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // -if ( !canEdit( 'Monitors' ) ) { +if ( !canEdit('Monitors') ) { $view = 'error'; return; } @@ -73,26 +73,26 @@ function probeCameras( $localIp ) { } elseif ( $tokens[1] == 'location' ) { // $camera['location'] = $tokens[2]; } else { - Logger::Debug('Unknown token ' . $tokens[1] ); + Logger::Debug('Unknown token ' . $tokens[1]); } } } // end foreach token $cameras[] = $camera; } } // end foreach line - } - return( $cameras ); -} + } // end if results from execOnvif + return $cameras; +} // end function probeCameras function probeProfiles( $device_ep, $soapversion, $username, $password ) { $profiles = array(); if ( $lines = @execONVIF( "profiles $device_ep $soapversion $username $password" ) ) { foreach ( $lines as $line ) { $line = rtrim( $line ); - if ( preg_match( '|^(.+),\s*(.+),\s*(.+),\s*(.+),\s*(.+),\s*(.+),\s*(.+)\s*$|', $line, $matches ) ) { + if ( preg_match('|^(.+),\s*(.+),\s*(.+),\s*(.+),\s*(.+),\s*(.+),\s*(.+)\s*$|', $line, $matches) ) { $stream_uri = $matches[7]; // add user@pass to URI - if ( preg_match( '|^(\S+://)(.+)$|', $stream_uri, $tokens ) ) { + if ( preg_match('|^(\S+://)(.+)$|', $stream_uri, $tokens) ) { $stream_uri = $tokens[1].$username.':'.$password.'@'.$tokens[2]; } @@ -106,17 +106,15 @@ function probeProfiles( $device_ep, $soapversion, $username, $password ) { 'Profile' => $matches[1], 'Name' => $matches[2], 'Encoding' => $matches[3], - ); $profiles[] = $profile; } else { Logger::Debug("Line did not match preg: $line"); } - } - } - return( $profiles ); -} - + } // end foreach line + } // end if results from execONVIF + return $profiles; +} // end function probeProfiles //==== STEP 1 ============================================================ @@ -124,20 +122,20 @@ $focusWindow = true; xhtmlHeaders(__FILE__, translate('MonitorProbe') ); -if( !isset($_REQUEST['step']) || ($_REQUEST['step'] == "1")) { +if ( !isset($_REQUEST['step']) || ($_REQUEST['step'] == '1') ) { $monitors = array(); - foreach ( dbFetchAll( "select Id, Name, Host from Monitors where Type = 'Remote' order by Host" ) as $monitor ) { - if ( preg_match( '/^(.+)@(.+)$/', $monitor['Host'], $matches ) ) { - //echo "1: ".$matches[2]." = ".gethostbyname($matches[2])."
"; - $monitors[gethostbyname($matches[2])] = $monitor; - } else { - //echo "2: ".$monitor['Host']." = ".gethostbyname($monitor['Host'])."
"; - $monitors[gethostbyname($monitor['Host'])] = $monitor; - } + foreach ( dbFetchAll("SELECT Id, Name, Host FROM Monitors WHERE Type = 'Remote' ORDER BY Host") as $monitor ) { + if ( preg_match( '/^(.+)@(.+)$/', $monitor['Host'], $matches ) ) { + //echo "1: ".$matches[2]." = ".gethostbyname($matches[2])."
"; + $monitors[gethostbyname($matches[2])] = $monitor; + } else { + //echo "2: ".$monitor['Host']." = ".gethostbyname($monitor['Host'])."
"; + $monitors[gethostbyname($monitor['Host'])] = $monitor; + } } - $detcameras = probeCameras( '' ); + $detcameras = probeCameras(''); foreach ( $detcameras as $camera ) { if ( preg_match( '|([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)|', $camera['monitor']['Host'], $matches ) ) { $ip = $matches[1]; @@ -157,13 +155,13 @@ if( !isset($_REQUEST['step']) || ($_REQUEST['step'] == "1")) { } */ // $sourceDesc = htmlspecialchars(serialize($camera['monitor'])); - $sourceDesc = base64_encode(serialize($camera['monitor'])); - $sourceString = $camera['model'].' @ '.$host . ' using version ' . $camera['monitor']['SOAP'] ; - $cameras[$sourceDesc] = $sourceString; + $sourceDesc = base64_encode(json_encode($camera['monitor'])); + $sourceString = $camera['model'].' @ '.$host . ' using version ' . $camera['monitor']['SOAP'] ; + $cameras[$sourceDesc] = $sourceString; } if ( count($cameras) <= 0 ) - $cameras[0] = translate('NoDetectedCameras'); + $cameras[0] = translate('NoDetectedCameras'); ?> @@ -180,22 +178,23 @@ if( !isset($_REQUEST['step']) || ($_REQUEST['step'] == "1")) {

- + + 'configureButtons(this)')); ?>

- +

- +

- +
@@ -205,44 +204,42 @@ if( !isset($_REQUEST['step']) || ($_REQUEST['step'] == "1")) { $value ) { - if ( isset($value) ) { - $monitor[$name] = $value; - } + if ( isset($value) ) { + $monitor[$name] = $value; + } } $camera['monitor'] = $monitor; //print $monitor['Host'].", ".$_REQUEST['username'].", ".$_REQUEST['password']."
"; - $detprofiles = probeProfiles( $monitor['Host'], $monitor['SOAP'], $_REQUEST['username'], $_REQUEST['password']); + $detprofiles = probeProfiles($monitor['Host'], $monitor['SOAP'], $_REQUEST['username'], $_REQUEST['password']); foreach ( $detprofiles as $profile ) { - $monitor = $camera['monitor']; - - $sourceString = "${profile['Name']} : ${profile['Encoding']}" . - " (${profile['Width']}x${profile['Height']} @ ${profile['MaxFPS']}fps)"; - // copy technical details - $monitor['Width'] = $profile['Width']; - $monitor['Height'] = $profile['Height']; -// The maxfps fields do not work for ip streams. Can re-enable if that is fixed. -// $monitor['MaxFPS'] = $profile['MaxFPS']; -// $monitor['AlarmMaxFPS'] = $profile['AlarmMaxFPS']; - $monitor['Path'] = $profile['Path']; -// $sourceDesc = htmlspecialchars(serialize($monitor)); - $sourceDesc = base64_encode(serialize($monitor)); - $profiles[$sourceDesc] = $sourceString; + $monitor = $camera['monitor']; + + $sourceString = "${profile['Name']} : ${profile['Encoding']}" . + " (${profile['Width']}x${profile['Height']} @ ${profile['MaxFPS']}fps)"; + // copy technical details + $monitor['Width'] = $profile['Width']; + $monitor['Height'] = $profile['Height']; + // The maxfps fields do not work for ip streams. Can re-enable if that is fixed. + // $monitor['MaxFPS'] = $profile['MaxFPS']; + // $monitor['AlarmMaxFPS'] = $profile['AlarmMaxFPS']; + $monitor['Path'] = $profile['Path']; + $sourceDesc = base64_encode(json_encode($monitor)); + $profiles[$sourceDesc] = $sourceString; } if ( count($profiles) <= 0 ) - $profiles[0] = translate('NoDetectedProfiles'); + $profiles[0] = translate('NoDetectedProfiles'); ?> @@ -254,17 +251,18 @@ else if($_REQUEST['step'] == "2")
- +

- + + 'configureButtons(this)')); ?>

- + - +
@@ -272,5 +270,5 @@ else if($_REQUEST['step'] == "2") diff --git a/web/views/image.php b/web/views/image.php index 48e005c70..2c04f18e6 100644 --- a/web/views/image.php +++ b/web/views/image.php @@ -69,6 +69,7 @@ if ( empty($_REQUEST['path']) ) { } if ( !empty($_REQUEST['eid']) ) { +Logger::Debug("Loading by eid"); $Event = Event::find_one(array('Id'=>$_REQUEST['eid'])); if ( !$Event ) { header('HTTP/1.0 404 Not Found'); @@ -136,6 +137,7 @@ Logger::Debug("Got virtual frame from Bulk Frames previous delta: " . $previousB } // Frame can be non-existent. We have Bulk frames. So now we should try to load the bulk frame $path = $Event->Path().'/'.sprintf('%0'.ZM_EVENT_IMAGE_DIGITS.'d',$Frame->FrameId()).'-'.$show.'.jpg'; +Logger::Debug("Path: $path"); } } else { @@ -225,12 +227,14 @@ if ( !empty($_REQUEST['scale']) ) { $width = 0; if ( !empty($_REQUEST['width']) ) { +Logger::Debug("Setting width: " . $_REQUEST['width']); if ( is_numeric($_REQUEST['width']) ) { $x = $_REQUEST['width']; if ( $x >= 10 and $x <= 8000 ) $width = $x; } } + $height = 0; if ( !empty($_REQUEST['height']) ) { if ( is_numeric($_REQUEST['height']) ) { @@ -246,14 +250,12 @@ if ( $errorText ) { # Clears the output buffer. Not sure what is there, but have had troubles. ob_end_clean(); header('Content-type: image/jpeg'); - if ( ( $scale==0 || $scale==100 ) && $width==0 && $height==0 ) { + if ( ( $scale==0 || $scale==100 ) && ($width==0) && ($height==0) ) { # This is so that Save Image As give a useful filename if ( $Event ) { $filename = $Event->MonitorId().'_'.$Event->Id().'_'.$Frame->FrameId().'.jpg'; header('Content-Disposition: inline; filename="' . $filename . '"'); } - ob_clean(); - flush(); if ( !readfile($path) ) { Error('No bytes read from '. $path); } @@ -271,6 +273,7 @@ if ( $errorText ) { $width = ($height * $oldWidth) / $oldHeight; } elseif ( $width != 0 && $height == 0 ) { $height = ($width * $oldHeight) / $oldWidth; +Logger::Debug("Figuring out height using width: $height = ($width * $oldHeight) / $oldWidth"); } if ( $width == $oldWidth && $height == $oldHeight ) { Warning('No change to width despite scaling.'); @@ -283,8 +286,6 @@ if ( $errorText ) { $filename = $Event->MonitorId().'_'.$Event->Id().'_'.$Frame->FrameId()."-${width}x${height}.jpg"; header('Content-Disposition: inline; filename="' . $filename . '"'); } - //ob_clean(); - //flush(); if ( !( file_exists($scaled_path) and readfile($scaled_path) ) ) { Logger::Debug("Cached scaled image does not exist at $scaled_path or is no good.. Creating it"); ob_start();