fix issue that grayscale jpeg can't be shwon
This commit is contained in:
parent
e09b57ca12
commit
cf71da94c4
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Pixel Buffer Implementation
|
* Pixel Buffer Implementation
|
||||||
* Nana C++ Library(http://www.nanapro.org)
|
* Nana C++ Library(http://www.nanapro.org)
|
||||||
* Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com)
|
* Copyright(C) 2003-2020 Jinhao(cnjinhao@hotmail.com)
|
||||||
*
|
*
|
||||||
* Distributed under the Boost Software License, Version 1.0.
|
* Distributed under the Boost Software License, Version 1.0.
|
||||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
@ -190,20 +190,22 @@ namespace nana{ namespace paint
|
|||||||
if (!raw_pixel_buffer)
|
if (!raw_pixel_buffer)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto rawptr = raw_pixel_buffer;
|
if ((32 == bits_per_pixel) && (pixel_size.width == width) && (pixel_size.height == height) && (this->bytes_per_line == bytes_per_line) && is_negative)
|
||||||
if(32 == bits_per_pixel)
|
|
||||||
{
|
{
|
||||||
if((pixel_size.width == width) && (pixel_size.height == height) && is_negative)
|
memcpy(raw_pixel_buffer, rawbits, (bytes_per_line * pixel_size.height));
|
||||||
{
|
return;
|
||||||
memcpy(rawptr, rawbits, (pixel_size.width * pixel_size.height) * 4);
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
std::size_t line_bytes = (pixel_size.width < width ? pixel_size.width : width) * sizeof(pixel_color_t);
|
if(pixel_size.width < width)
|
||||||
|
width = pixel_size.width;
|
||||||
|
|
||||||
if(pixel_size.height < height)
|
if(pixel_size.height < height)
|
||||||
height = pixel_size.height;
|
height = pixel_size.height;
|
||||||
|
|
||||||
|
auto rawptr = raw_pixel_buffer;
|
||||||
|
if(32 == bits_per_pixel)
|
||||||
|
{
|
||||||
auto d = rawptr;
|
auto d = rawptr;
|
||||||
const unsigned char* s;
|
const unsigned char* s;
|
||||||
int src_line_bytes;
|
int src_line_bytes;
|
||||||
@ -221,12 +223,11 @@ namespace nana{ namespace paint
|
|||||||
|
|
||||||
for(std::size_t i = 0; i < height; ++i)
|
for(std::size_t i = 0; i < height; ++i)
|
||||||
{
|
{
|
||||||
memcpy(d, s, line_bytes);
|
memcpy(d, s, this->bytes_per_line);
|
||||||
d += pixel_size.width;
|
d += pixel_size.width;
|
||||||
s -= src_line_bytes;
|
s -= src_line_bytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if(24 == bits_per_pixel)
|
else if(24 == bits_per_pixel)
|
||||||
{
|
{
|
||||||
if(pixel_size.width < width)
|
if(pixel_size.width < width)
|
||||||
@ -269,12 +270,6 @@ namespace nana{ namespace paint
|
|||||||
}
|
}
|
||||||
else if(16 == bits_per_pixel)
|
else if(16 == bits_per_pixel)
|
||||||
{
|
{
|
||||||
if(pixel_size.width < width)
|
|
||||||
width = pixel_size.width;
|
|
||||||
|
|
||||||
if(pixel_size.height < height)
|
|
||||||
height = pixel_size.height;
|
|
||||||
|
|
||||||
unsigned char rgb_table[32];
|
unsigned char rgb_table[32];
|
||||||
for(std::size_t i =0; i < 32; ++i)
|
for(std::size_t i =0; i < 32; ++i)
|
||||||
rgb_table[i] = static_cast<unsigned char>(i * 255 / 31);
|
rgb_table[i] = static_cast<unsigned char>(i * 255 / 31);
|
||||||
@ -310,6 +305,32 @@ namespace nana{ namespace paint
|
|||||||
rawbits -= src_bytes_per_line;
|
rawbits -= src_bytes_per_line;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(8 == bits_per_pixel)
|
||||||
|
{
|
||||||
|
int src_bytes_per_line;
|
||||||
|
if(!is_negative)
|
||||||
|
{
|
||||||
|
rawbits += bytes_per_line * (height - 1);
|
||||||
|
src_bytes_per_line = -static_cast<int>(bytes_per_line);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
src_bytes_per_line = static_cast<int>(bytes_per_line);
|
||||||
|
|
||||||
|
for(std::size_t top = 0; top < height; ++top)
|
||||||
|
{
|
||||||
|
auto dst = rawptr;
|
||||||
|
for(auto p = rawbits, end = rawbits + width; p < end; ++p)
|
||||||
|
{
|
||||||
|
dst->element.red = *p;
|
||||||
|
dst->element.green = *p;
|
||||||
|
dst->element.blue = *p;
|
||||||
|
++dst;
|
||||||
|
}
|
||||||
|
|
||||||
|
rawbits += src_bytes_per_line;
|
||||||
|
rawptr += this->bytes_per_line;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(NANA_X11)
|
#if defined(NANA_X11)
|
||||||
@ -691,6 +712,17 @@ namespace nana{ namespace paint
|
|||||||
++px;
|
++px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(8 == bits_per_pixel)
|
||||||
|
{
|
||||||
|
//Grayscale
|
||||||
|
for (auto p = row_ptr, end = row_ptr + px_count; p != end; ++p)
|
||||||
|
{
|
||||||
|
p->element.red = *buffer;
|
||||||
|
p->element.green = *buffer;
|
||||||
|
p->element.blue = *buffer;
|
||||||
|
++buffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user