set linesize in WriteBuffer which also sets colours, width, etc. Fixes segfault when streaming from jpegs
This commit is contained in:
parent
4f3b6a063e
commit
cceb010048
|
@ -504,6 +504,7 @@ uint8_t* Image::WriteBuffer(
|
|||
}
|
||||
|
||||
if ( p_width != width || p_height != height || p_colours != colours || p_subpixelorder != subpixelorder ) {
|
||||
|
||||
unsigned int newsize = (p_width * p_height) * p_colours;
|
||||
|
||||
if ( buffer == NULL ) {
|
||||
|
@ -524,6 +525,7 @@ uint8_t* Image::WriteBuffer(
|
|||
width = p_width;
|
||||
height = p_height;
|
||||
colours = p_colours;
|
||||
linesize = p_width * p_colours;
|
||||
subpixelorder = p_subpixelorder;
|
||||
pixels = height*width;
|
||||
size = newsize;
|
||||
|
@ -899,14 +901,11 @@ bool Image::ReadJpeg(const char *filename, unsigned int p_colours, unsigned int
|
|||
|
||||
switch ( p_colours ) {
|
||||
case ZM_COLOUR_GRAY8:
|
||||
{
|
||||
cinfo->out_color_space = JCS_GRAYSCALE;
|
||||
new_colours = ZM_COLOUR_GRAY8;
|
||||
new_subpixelorder = ZM_SUBPIX_ORDER_NONE;
|
||||
break;
|
||||
}
|
||||
case ZM_COLOUR_RGB32:
|
||||
{
|
||||
#ifdef JCS_EXTENSIONS
|
||||
new_colours = ZM_COLOUR_RGB32;
|
||||
if ( p_subpixelorder == ZM_SUBPIX_ORDER_BGRA ) {
|
||||
|
@ -927,10 +926,8 @@ bool Image::ReadJpeg(const char *filename, unsigned int p_colours, unsigned int
|
|||
#else
|
||||
Warning("libjpeg-turbo is required for reading a JPEG directly into a RGB32 buffer, reading into a RGB24 buffer instead.");
|
||||
#endif
|
||||
}
|
||||
case ZM_COLOUR_RGB24:
|
||||
default:
|
||||
{
|
||||
new_colours = ZM_COLOUR_RGB24;
|
||||
if ( p_subpixelorder == ZM_SUBPIX_ORDER_BGR ) {
|
||||
#ifdef JCS_EXTENSIONS
|
||||
|
@ -954,8 +951,7 @@ cinfo->out_color_space = JCS_RGB;
|
|||
new_subpixelorder = ZM_SUBPIX_ORDER_RGB;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // end switch p_colours
|
||||
|
||||
if ( WriteBuffer(new_width, new_height, new_colours, new_subpixelorder) == NULL ) {
|
||||
Error("Failed requesting writeable buffer for reading JPEG image.");
|
||||
|
@ -2787,7 +2783,7 @@ 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 < height; y++ ) {
|
||||
h_count += factor;
|
||||
h_index = h_count/ZM_SCALE_BASE;
|
||||
if ( h_index > last_h_index ) {
|
||||
|
@ -2796,7 +2792,7 @@ void Image::Scale( unsigned int factor ) {
|
|||
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 < width; x++ ) {
|
||||
w_count += factor;
|
||||
w_index = w_count/ZM_SCALE_BASE;
|
||||
|
||||
|
|
|
@ -201,9 +201,22 @@ public:
|
|||
width = linesize = height = colours = size = pixels = subpixelorder = 0;
|
||||
}
|
||||
|
||||
void Assign( unsigned int p_width, unsigned int p_height, unsigned int p_colours, unsigned int p_subpixelorder, const uint8_t* new_buffer, const size_t buffer_size);
|
||||
void Assign(
|
||||
unsigned int p_width,
|
||||
unsigned int p_height,
|
||||
unsigned int p_colours,
|
||||
unsigned int p_subpixelorder,
|
||||
const uint8_t* new_buffer,
|
||||
const size_t buffer_size);
|
||||
void Assign(const Image &image);
|
||||
void AssignDirect( const unsigned int p_width, const unsigned int p_height, const unsigned int p_colours, const unsigned int p_subpixelorder, uint8_t *new_buffer, const size_t buffer_size, const int p_buffertype);
|
||||
void AssignDirect(
|
||||
const unsigned int p_width,
|
||||
const unsigned int p_height,
|
||||
const unsigned int p_colours,
|
||||
const unsigned int p_subpixelorder,
|
||||
uint8_t *new_buffer,
|
||||
const size_t buffer_size,
|
||||
const int p_buffertype);
|
||||
|
||||
inline void CopyBuffer(const Image &image) {
|
||||
Assign(image);
|
||||
|
|
Loading…
Reference in New Issue