mostly spacing. Also set new_size from line_size in Assign(Image&) and set linesize in the assigned image
This commit is contained in:
parent
e746f0babe
commit
07165aed98
|
@ -263,14 +263,6 @@ Image::~Image() {
|
||||||
/* Should be called as part of program shutdown to free everything */
|
/* Should be called as part of program shutdown to free everything */
|
||||||
void Image::Deinitialise() {
|
void Image::Deinitialise() {
|
||||||
if ( !initialised ) return;
|
if ( !initialised ) return;
|
||||||
/*
|
|
||||||
delete[] y_table;
|
|
||||||
delete[] uv_table;
|
|
||||||
delete[] r_v_table;
|
|
||||||
delete[] g_v_table;
|
|
||||||
delete[] g_u_table;
|
|
||||||
delete[] b_u_table;
|
|
||||||
*/
|
|
||||||
initialised = false;
|
initialised = false;
|
||||||
if ( readjpg_dcinfo ) {
|
if ( readjpg_dcinfo ) {
|
||||||
jpeg_destroy_decompress( readjpg_dcinfo );
|
jpeg_destroy_decompress( readjpg_dcinfo );
|
||||||
|
@ -491,9 +483,17 @@ void Image::Initialise() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Requests a writeable buffer to the image. This is safer than buffer() because this way we can guarantee that a buffer of required size exists */
|
/* Requests a writeable buffer to the image. This is safer than buffer() because this way we can guarantee that a buffer of required size exists */
|
||||||
uint8_t* Image::WriteBuffer(const unsigned int p_width, const unsigned int p_height, const unsigned int p_colours, const unsigned int p_subpixelorder) {
|
uint8_t* Image::WriteBuffer(
|
||||||
|
const unsigned int p_width,
|
||||||
|
const unsigned int p_height,
|
||||||
|
const unsigned int p_colours,
|
||||||
|
const unsigned int p_subpixelorder) {
|
||||||
|
|
||||||
if ( p_colours != ZM_COLOUR_GRAY8 && p_colours != ZM_COLOUR_RGB24 && p_colours != ZM_COLOUR_RGB32 ) {
|
if ( p_colours != ZM_COLOUR_GRAY8
|
||||||
|
&&
|
||||||
|
p_colours != ZM_COLOUR_RGB24
|
||||||
|
&&
|
||||||
|
p_colours != ZM_COLOUR_RGB32 ) {
|
||||||
Error("WriteBuffer called with unexpected colours: %d", p_colours);
|
Error("WriteBuffer called with unexpected colours: %d", p_colours);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -605,7 +605,13 @@ void Image::AssignDirect(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Image::Assign(const unsigned int p_width, const unsigned int p_height, const unsigned int p_colours, const unsigned int p_subpixelorder, const uint8_t* new_buffer, const size_t buffer_size) {
|
void Image::Assign(
|
||||||
|
const unsigned int p_width,
|
||||||
|
const unsigned int p_height,
|
||||||
|
const unsigned int p_colours,
|
||||||
|
const unsigned int p_subpixelorder,
|
||||||
|
const uint8_t* new_buffer,
|
||||||
|
const size_t buffer_size) {
|
||||||
unsigned int new_size = (p_width * p_height) * p_colours;
|
unsigned int new_size = (p_width * p_height) * p_colours;
|
||||||
|
|
||||||
if ( new_buffer == NULL ) {
|
if ( new_buffer == NULL ) {
|
||||||
|
@ -652,24 +658,30 @@ void Image::Assign(const unsigned int p_width, const unsigned int p_height, cons
|
||||||
|
|
||||||
if ( new_buffer != buffer )
|
if ( new_buffer != buffer )
|
||||||
(*fptr_imgbufcpy)(buffer, new_buffer, size);
|
(*fptr_imgbufcpy)(buffer, new_buffer, size);
|
||||||
Debug(1,"Assign");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Image::Assign(const Image &image) {
|
void Image::Assign(const Image &image) {
|
||||||
unsigned int new_size = (image.width * image.height) * image.colours;
|
unsigned int new_size = image.height * image.linesize;
|
||||||
|
|
||||||
if ( image.buffer == NULL ) {
|
if ( image.buffer == NULL ) {
|
||||||
Error("Attempt to assign image with an empty buffer");
|
Error("Attempt to assign image with an empty buffer");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( image.colours != ZM_COLOUR_GRAY8 && image.colours != ZM_COLOUR_RGB24 && image.colours != ZM_COLOUR_RGB32 ) {
|
if ( image.colours != ZM_COLOUR_GRAY8
|
||||||
|
&&
|
||||||
|
image.colours != ZM_COLOUR_RGB24
|
||||||
|
&&
|
||||||
|
image.colours != ZM_COLOUR_RGB32 ) {
|
||||||
Error("Attempt to assign image with unexpected colours per pixel: %d", image.colours);
|
Error("Attempt to assign image with unexpected colours per pixel: %d", image.colours);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !buffer || image.width != width || image.height != height
|
if ( !buffer
|
||||||
|| image.colours != colours || image.subpixelorder != subpixelorder) {
|
|| image.width != width || image.height != height
|
||||||
|
|| image.colours != colours || image.subpixelorder != subpixelorder
|
||||||
|
|| image.linesize != linesize
|
||||||
|
) {
|
||||||
|
|
||||||
if ( holdbuffer && buffer ) {
|
if ( holdbuffer && buffer ) {
|
||||||
if ( new_size > allocation ) {
|
if ( new_size > allocation ) {
|
||||||
|
@ -689,13 +701,19 @@ void Image::Assign( const Image &image ) {
|
||||||
colours = image.colours;
|
colours = image.colours;
|
||||||
subpixelorder = image.subpixelorder;
|
subpixelorder = image.subpixelorder;
|
||||||
size = new_size;
|
size = new_size;
|
||||||
|
linesize = image.linesize;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( image.buffer != buffer )
|
if ( image.buffer != buffer )
|
||||||
(*fptr_imgbufcpy)(buffer, image.buffer, size);
|
(*fptr_imgbufcpy)(buffer, image.buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
Image *Image::HighlightEdges( Rgb colour, unsigned int p_colours, unsigned int p_subpixelorder, const Box *limits ) {
|
Image *Image::HighlightEdges(
|
||||||
|
Rgb colour,
|
||||||
|
unsigned int p_colours,
|
||||||
|
unsigned int p_subpixelorder,
|
||||||
|
const Box *limits
|
||||||
|
) {
|
||||||
if ( colours != ZM_COLOUR_GRAY8 ) {
|
if ( colours != ZM_COLOUR_GRAY8 ) {
|
||||||
Panic("Attempt to highlight image edges when colours = %d", colours);
|
Panic("Attempt to highlight image edges when colours = %d", colours);
|
||||||
}
|
}
|
||||||
|
@ -722,10 +740,13 @@ Image *Image::HighlightEdges( Rgb colour, unsigned int p_colours, unsigned int p
|
||||||
for ( unsigned int x = lo_x; x <= hi_x; x++, p++, phigh++ ) {
|
for ( unsigned int x = lo_x; x <= hi_x; x++, p++, phigh++ ) {
|
||||||
bool edge = false;
|
bool edge = false;
|
||||||
if ( *p ) {
|
if ( *p ) {
|
||||||
|
edge = (x > 0 && !*(p-1)) || (x < (width-1) && !*(p+1)) || (y > 0 && !*(p-width)) || (y < (height-1) && !*(p+width));
|
||||||
|
#if 0
|
||||||
if ( !edge && x > 0 && !*(p-1) ) edge = true;
|
if ( !edge && x > 0 && !*(p-1) ) edge = true;
|
||||||
if ( !edge && x < (width-1) && !*(p+1) ) edge = true;
|
if ( !edge && x < (width-1) && !*(p+1) ) edge = true;
|
||||||
if ( !edge && y > 0 && !*(p-width) ) edge = true;
|
if ( !edge && y > 0 && !*(p-width) ) edge = true;
|
||||||
if ( !edge && y < (height-1) && !*(p+width) ) edge = true;
|
if ( !edge && y < (height-1) && !*(p+width) ) edge = true;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if ( edge ) {
|
if ( edge ) {
|
||||||
*phigh = colour;
|
*phigh = colour;
|
||||||
|
@ -739,10 +760,13 @@ Image *Image::HighlightEdges( Rgb colour, unsigned int p_colours, unsigned int p
|
||||||
for ( unsigned int x = lo_x; x <= hi_x; x++, p++, phigh += 3 ) {
|
for ( unsigned int x = lo_x; x <= hi_x; x++, p++, phigh += 3 ) {
|
||||||
bool edge = false;
|
bool edge = false;
|
||||||
if ( *p ) {
|
if ( *p ) {
|
||||||
|
edge = (x > 0 && !*(p-1)) || (x < (width-1) && !*(p+1)) || (y > 0 && !*(p-width)) || (y < (height-1) && !*(p+width));
|
||||||
|
#if 0
|
||||||
if ( !edge && x > 0 && !*(p-1) ) edge = true;
|
if ( !edge && x > 0 && !*(p-1) ) edge = true;
|
||||||
if ( !edge && x < (width-1) && !*(p+1) ) edge = true;
|
if ( !edge && x < (width-1) && !*(p+1) ) edge = true;
|
||||||
if ( !edge && y > 0 && !*(p-width) ) edge = true;
|
if ( !edge && y > 0 && !*(p-width) ) edge = true;
|
||||||
if ( !edge && y < (height-1) && !*(p+width) ) edge = true;
|
if ( !edge && y < (height-1) && !*(p+width) ) edge = true;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if ( edge ) {
|
if ( edge ) {
|
||||||
RED_PTR_RGBA(phigh) = RED_VAL_RGBA(colour);
|
RED_PTR_RGBA(phigh) = RED_VAL_RGBA(colour);
|
||||||
|
@ -758,10 +782,13 @@ Image *Image::HighlightEdges( Rgb colour, unsigned int p_colours, unsigned int p
|
||||||
for ( unsigned int x = lo_x; x <= hi_x; x++, p++, phigh++ ) {
|
for ( unsigned int x = lo_x; x <= hi_x; x++, p++, phigh++ ) {
|
||||||
bool edge = false;
|
bool edge = false;
|
||||||
if ( *p ) {
|
if ( *p ) {
|
||||||
|
edge = (x > 0 && !*(p-1)) || (x < (width-1) && !*(p+1)) || (y > 0 && !*(p-width)) || (y < (height-1) && !*(p+width));
|
||||||
|
#if 0
|
||||||
if ( !edge && x > 0 && !*(p-1) ) edge = true;
|
if ( !edge && x > 0 && !*(p-1) ) edge = true;
|
||||||
if ( !edge && x < (width-1) && !*(p+1) ) edge = true;
|
if ( !edge && x < (width-1) && !*(p+1) ) edge = true;
|
||||||
if ( !edge && y > 0 && !*(p-width) ) edge = true;
|
if ( !edge && y > 0 && !*(p-width) ) edge = true;
|
||||||
if ( !edge && y < (height-1) && !*(p+width) ) edge = true;
|
if ( !edge && y < (height-1) && !*(p+width) ) edge = true;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if ( edge ) {
|
if ( edge ) {
|
||||||
*phigh = colour;
|
*phigh = colour;
|
||||||
|
@ -1760,7 +1787,7 @@ Image *Image::Highlight( unsigned int n_images, Image *images[], const Rgb thres
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* New function to allow buffer re-using instead of allocationg memory for the delta image every time */
|
/* New function to allow buffer re-using instead of allocating 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
|
#ifdef ZM_IMAGE_PROFILING
|
||||||
struct timespec start,end,diff;
|
struct timespec start,end,diff;
|
||||||
|
@ -3634,6 +3661,7 @@ __attribute__((noinline)) void fast_delta8_argb(const uint8_t* col1, const uint8
|
||||||
result += 4;
|
result += 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((noinline)) void std_delta8_argb(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count) {
|
__attribute__((noinline)) void std_delta8_argb(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count) {
|
||||||
/* Loop unrolling is used to work on 16 bytes (4 rgb32 pixels) at a time */
|
/* Loop unrolling is used to work on 16 bytes (4 rgb32 pixels) at a time */
|
||||||
int r,g,b;
|
int r,g,b;
|
||||||
|
|
Loading…
Reference in New Issue