本文整理汇总了C++中png_set_tRNS_to_alpha函数的典型用法代码示例。如果您正苦于以下问题:C++ png_set_tRNS_to_alpha函数的具体用法?C++ png_set_tRNS_to_alpha怎么用?C++ png_set_tRNS_to_alpha使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了png_set_tRNS_to_alpha函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: lload
static int
lload(lua_State *L) {
int top = lua_gettop(L);
FILE *fp;
struct png_source source;
if (top == 1) {
const char *filename = luaL_checkstring(L,1);
fp = fopen(filename, "rb");
if (fp == NULL) {
return luaL_error(L, strerror(errno));
}
unsigned char header[PNGSIGSIZE];
if (fread(header, 1, PNGSIGSIZE, fp) != PNGSIGSIZE) {
return luaL_error(L, "png invalid");
}
if (png_sig_cmp(header, 0, PNGSIGSIZE)) {
return luaL_error(L, "png sig invalid");
}
fseek(fp, 0, SEEK_SET);
} else if (top == 2) {
luaL_checktype(L,1,LUA_TLIGHTUSERDATA);
void *data = lua_touserdata(L,1);
size_t size = luaL_checkinteger(L,2);
if (size < PNGSIGSIZE) {
return luaL_error(L, "png invalid");
}
if (png_sig_cmp(data, 0, PNGSIGSIZE)) {
return luaL_error(L, "png sig invalid");
}
source.data = data;
source.size = size;
source.offset = 0;
} else {
return luaL_error(L, "invalid argument number");
}
png_structp png_ptr;
png_infop info_ptr;
png_uint_32 width, height;
int bit_depth, color_type, interlace_type;
int step;//, type;
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL) {
return 0;
}
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) {
png_destroy_read_struct(&png_ptr, NULL, NULL);
return 0;
}
if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return 0;
}
if (top == 1)
png_init_io(png_ptr, fp);
else
png_set_read_fn(png_ptr, (void *)&source, png_read_cb);
//png_set_sig_bytes(png_ptr, PNGSIGSIZE);
png_read_info(png_ptr, info_ptr);
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
&interlace_type, NULL, NULL);
if (color_type == PNG_COLOR_TYPE_PALETTE)
png_set_palette_to_rgb(png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) {
bit_depth = 8;
png_set_expand_gray_1_2_4_to_8(png_ptr);
}
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) != 0)
png_set_tRNS_to_alpha(png_ptr);
if (bit_depth == 16)
png_set_strip_16(png_ptr);
if (bit_depth < 8)
png_set_packing(png_ptr);
png_read_update_info(png_ptr, info_ptr);
bit_depth = png_get_bit_depth(png_ptr, info_ptr);
color_type = png_get_color_type(png_ptr, info_ptr);
switch (color_type) {
case PNG_COLOR_TYPE_GRAY:
// type = TEXTURE_DEPTH;
step = 1;
break;
case PNG_COLOR_TYPE_RGB:
//type = TEXTURE_RGB;
step = 3;
break;
case PNG_COLOR_TYPE_RGB_ALPHA:
//.........这里部分代码省略.........
开发者ID:lvshaco,项目名称:lpng,代码行数:101,代码来源:lpng.c
示例2: png_create_info_struct
CDibSection* InformApp::GetImage(const char* path)
{
// Check if it's a PNG file
CStdioFile imageFile;
if (!imageFile.Open(path,CFile::modeRead|CFile::typeBinary))
return 0;
png_byte fileHeader[8];
imageFile.Read(fileHeader,8);
bool isPNG = (png_sig_cmp(fileHeader,0,8) == 0);
if (isPNG)
{
// Prepare to read the PNG file
png_structp png_ptr = png_create_read_struct
(PNG_LIBPNG_VER_STRING,(png_voidp)NULL,NULL,NULL);
if (png_ptr == NULL)
return 0;
png_infop info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL)
{
png_destroy_read_struct(&png_ptr,(png_infopp)NULL,(png_infopp)NULL);
return 0;
}
png_infop end_info = png_create_info_struct(png_ptr);
if (end_info == NULL)
{
png_destroy_read_struct(&png_ptr,&info_ptr,(png_infopp)NULL);
return 0;
}
// Set up the point to return to in case of error
png_bytep* rowPointers = NULL;
if (setjmp(png_jmpbuf(png_ptr)))
{
if (rowPointers)
delete[] rowPointers;
png_destroy_read_struct(&png_ptr,&info_ptr,&end_info);
return 0;
}
png_init_io(png_ptr,imageFile.m_pStream);
png_set_sig_bytes(png_ptr,8);
png_read_info(png_ptr,info_ptr);
// Get details of the image
png_uint_32 width = png_get_image_width(png_ptr,info_ptr);
png_uint_32 height = png_get_image_height(png_ptr,info_ptr);
int bit_depth = png_get_bit_depth(png_ptr,info_ptr);
int color_type = png_get_color_type(png_ptr,info_ptr);
// Set up transforms to the required format
if (color_type == PNG_COLOR_TYPE_PALETTE && bit_depth <= 8)
png_set_palette_to_rgb(png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
png_set_expand_gray_1_2_4_to_8(png_ptr);
if (png_get_valid(png_ptr,info_ptr,PNG_INFO_tRNS))
png_set_tRNS_to_alpha(png_ptr);
double gamma;
if (png_get_gAMA(png_ptr,info_ptr,&gamma))
png_set_gamma(png_ptr,2.2,gamma);
if (bit_depth == 16)
png_set_strip_16(png_ptr);
if (bit_depth < 8)
png_set_packing(png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png_ptr);
png_set_bgr(png_ptr);
png_set_filler(png_ptr,0xFF,PNG_FILLER_AFTER);
// Create a bitmap
HDC dc = ::GetDC(NULL);
CDibSection* dib = new CDibSection();
BOOL created = dib->CreateBitmap(dc,width,height);
::ReleaseDC(NULL,dc);
if (!created)
{
png_destroy_read_struct(&png_ptr,&info_ptr,&end_info);
return NULL;
}
// Read in the image
rowPointers = new png_bytep[height];
for (int i = 0; i < (int)height; i++)
rowPointers[i] = ((png_bytep)dib->GetBits())+(width*i*4);
png_read_image(png_ptr,rowPointers);
png_read_end(png_ptr,end_info);
delete[] rowPointers;
png_destroy_read_struct(&png_ptr,&info_ptr,&end_info);
return dib;
}
else
{
imageFile.SeekToBegin();
struct jpeg_decompress_struct info;
struct JPEGErrorInfo error;
// Initialize the error handling
info.err = jpeg_std_error(&(error.base));
//.........这里部分代码省略.........
开发者ID:wyrover,项目名称:Windows-Inform7,代码行数:101,代码来源:Inform.cpp
示例3: fclose
// PNG 형식의 로드
void CDIB::LoadPNGFile(wstring file_name)
{
unsigned int sig_read=0;
int bit_depth, color_type, interlace_type;
// 파일 열기
FILE* fp=_wfopen(file_name.c_str(), L"rb");
if (!fp) return;
// png_struct 초기화
png_structp png_ptr=png_create_read_struct(
PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr) {
fclose(fp);
return;
}
png_init_io(png_ptr, fp);
// png_info 초기화
png_infop info_ptr=png_create_info_struct(png_ptr);
if (!info_ptr) {
fclose(fp);
png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL);
return;
}
// 화상정보 취득
png_read_info(png_ptr, info_ptr);
png_get_IHDR(png_ptr, info_ptr,
(unsigned long*)&W, (unsigned long*)&H,
&bit_depth, &color_type, &interlace_type, NULL, NULL);
// DIB 초기화
InitDIB();
// 변환방법 설정
// Palette를 RGB로
if (color_type==PNG_COLOR_TYPE_PALETTE)
png_set_palette_to_rgb(png_ptr);
// 투명색을 Alpha로
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
png_set_tRNS_to_alpha(png_ptr);
// Bit depth를 8bit로
if (bit_depth<8) png_set_packing(png_ptr); else
if (bit_depth==16) png_set_strip_16(png_ptr);
// 24bit(RGB)를 32bit(RGB0)로
if (color_type==PNG_COLOR_TYPE_RGB)
png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
// RGB를 BGR로
if (color_type==PNG_COLOR_TYPE_PALETTE ||
color_type==PNG_COLOR_TYPE_RGB ||
color_type==PNG_COLOR_TYPE_RGB_ALPHA)
png_set_bgr(png_ptr);
// 화상 읽기
png_bytep *row_pointers=new png_bytep[H];
for (int row=0; row<H; row++) row_pointers[row]=(png_bytep)(Pixel+row*W);
png_read_image(png_ptr, row_pointers);
png_read_end(png_ptr, info_ptr);
delete [] row_pointers;
// 뒷처리
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
// Alpha 값을 얻는다
DWORD* p=Pixel;
BYTE* a=Alpha;
for (int y=0; y<H; y++) {
for (int x=0; x<W; x++, p++, a++) {
*a=(BYTE)(*p>>24);
*p&=0x00ffffff;
}
}
// Region 초기화
InitRgn();
}
开发者ID:codebachi,项目名称:ProjectDirectX,代码行数:82,代码来源:DIB.cpp
示例4: res_create_surface
int res_create_surface(const char* name, gr_surface* pSurface) {
char resPath[256];
GGLSurface* surface = NULL;
int result = 0;
unsigned char header[8];
png_structp png_ptr = NULL;
png_infop info_ptr = NULL;
*pSurface = NULL;
snprintf(resPath, sizeof(resPath)-1, "/res/images/%s.png", name);
resPath[sizeof(resPath)-1] = '\0';
FILE* fp = fopen(resPath, "rb");
if (fp == NULL) {
result = -1;
goto exit;
}
size_t bytesRead = fread(header, 1, sizeof(header), fp);
if (bytesRead != sizeof(header)) {
result = -2;
goto exit;
}
if (png_sig_cmp(header, 0, sizeof(header))) {
result = -3;
goto exit;
}
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr) {
result = -4;
goto exit;
}
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
result = -5;
goto exit;
}
if (setjmp(png_jmpbuf(png_ptr))) {
result = -6;
goto exit;
}
png_init_io(png_ptr, fp);
png_set_sig_bytes(png_ptr, sizeof(header));
png_read_info(png_ptr, info_ptr);
int color_type, bit_depth;
size_t width, height;
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,
&color_type, NULL, NULL, NULL);
png_byte channels = png_get_channels(png_ptr, info_ptr);
if (!(bit_depth == 8 &&
((channels == 3 && color_type == PNG_COLOR_TYPE_RGB) ||
(channels == 4 && color_type == PNG_COLOR_TYPE_RGBA) ||
(channels == 1 && (color_type == PNG_COLOR_TYPE_PALETTE ||
color_type == PNG_COLOR_TYPE_GRAY))))) {
return -7;
goto exit;
}
size_t stride = (color_type == PNG_COLOR_TYPE_GRAY ? 1 : 4) * width;
size_t pixelSize = stride * height;
surface = malloc(sizeof(GGLSurface) + pixelSize);
if (surface == NULL) {
result = -8;
goto exit;
}
unsigned char* pData = (unsigned char*) (surface + 1);
surface->version = sizeof(GGLSurface);
surface->width = width;
surface->height = height;
surface->stride = width; /* Yes, pixels, not bytes */
surface->data = pData;
surface->format = (channels == 3) ? GGL_PIXEL_FORMAT_RGBX_8888 :
((color_type == PNG_COLOR_TYPE_PALETTE ? GGL_PIXEL_FORMAT_RGBA_8888 : GGL_PIXEL_FORMAT_L_8));
int alpha = 0;
if (color_type == PNG_COLOR_TYPE_PALETTE) {
png_set_palette_to_rgb(png_ptr);
}
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
png_set_tRNS_to_alpha(png_ptr);
alpha = 1;
}
if (color_type == PNG_COLOR_TYPE_GRAY) {
alpha = 1;
}
unsigned int y;
if (channels == 3 || (channels == 1 && !alpha)) {
for (y = 0; y < height; ++y) {
unsigned char* pRow = pData + y * stride;
//.........这里部分代码省略.........
开发者ID:umer936,项目名称:Team-Win-Recovery-Project,代码行数:101,代码来源:resources.c
示例5: simpl_gray_load_png
int simpl_gray_load_png(SimplGrayImage **image,
SimplInStream istream,
const SimplColorToGrayMethods method,
const SimplPixel bk_value)
{
png_structp png_ptr;
png_infop info_ptr;
png_byte color_type, bitdepth, *row_data=NULL;
png_bytep* row_ptrs=NULL;
png_uint_32 i, j, x, width, height, row_size;
SimplColorPixel *pixels=NULL;
SimplPixel *iptr, *alpha=NULL;
int value, out = SIMPL_INTERNAL;
/* Create a read struct. */
if (!(png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0))) {
return SIMPL_INTERNAL;
}
/* Create an info struct. */
if (!(info_ptr = png_create_info_struct(png_ptr))) {
goto error;
}
/* Handle libpng errors with a magic setjmp. */
if (setjmp(png_jmpbuf(png_ptr))) {
goto error;
}
/* Set the stream-based data source. */
png_set_read_fn(png_ptr, istream, StreamReadData);
/* Read the info chunk. */
png_read_info(png_ptr, info_ptr);
/* Get the dimensions and color information. */
width = png_get_image_width(png_ptr, info_ptr);
height = png_get_image_height(png_ptr, info_ptr);
bitdepth = png_get_bit_depth(png_ptr, info_ptr);
color_type = png_get_color_type(png_ptr, info_ptr);
/* If palette, low bit depth gray, transparent w/o alpha, or 16 bit, fix it. */
if (color_type == PNG_COLOR_TYPE_PALETTE) {
png_set_palette_to_rgb(png_ptr);
color_type = png_get_color_type(png_ptr, info_ptr);
} else if (color_type == PNG_COLOR_TYPE_GRAY) {
if (bitdepth<8) png_set_expand_gray_1_2_4_to_8(png_ptr);
bitdepth = 8;
}
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
png_set_tRNS_to_alpha(png_ptr);
color_type = png_get_color_type(png_ptr, info_ptr);
}
png_set_strip_16(png_ptr);
/* Either allocate a row, or load the entire image into a buffer. This is
* because single row access uses less memory but doesn't work for
* interlaced PNGs.
*/
row_size = png_get_rowbytes(png_ptr, info_ptr);
if (png_get_interlace_type(png_ptr, info_ptr)==PNG_INTERLACE_NONE) {
row_data = (png_byte *)malloc(sizeof(png_byte) * row_size);
if (!row_data) {
out = SIMPL_NOMEM;
goto error;
}
} else {
row_ptrs = (png_bytep*)calloc(height, sizeof(png_bytep));
if (!row_ptrs) {
out = SIMPL_NOMEM;
goto error;
}
for (j=0; j<height; ++j) {
row_ptrs[j] = (png_byte *)malloc(sizeof(png_byte) * row_size);
if (!row_ptrs[j]) {
out = SIMPL_NOMEM;
goto error;
}
}
png_read_image(png_ptr, row_ptrs);
}
/* Allocate an image of the specified size. */
out = simpl_gray(image, width, height);
if (out != SIMPL_OK) goto error;
/* Decode the image line by line. */
if (color_type == PNG_COLOR_TYPE_RGB || color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
pixels = (SimplColorPixel *)malloc(sizeof(SimplColorPixel) * width);
if (!pixels) {
out = SIMPL_NOMEM;
goto error;
}
//.........这里部分代码省略.........
开发者ID:componica,项目名称:Simpl,代码行数:101,代码来源:file_io_png.c
示例6: sizeof
void PNGImage::loadImage() {
FILE* file_descriptor = nullptr;
png_byte header[8];
png_structp png_ptr = nullptr;
png_infop info_ptr = nullptr;
png_byte* image_buffer = nullptr;
png_bytep* row_ptrs = nullptr;
png_int_32 row_size = 0;
bool transparency = false;
int error_code = 0;
size_t header_size = sizeof(header);
file_descriptor = std::fopen(m_filename, "rb");
if (file_descriptor == nullptr) { error_code = 10; goto ERROR_PNG; }
if (header_size != std::fread(header, 1, header_size, file_descriptor)) { error_code = 11; goto ERROR_PNG; }
if (png_sig_cmp(header, 0, 8) != 0) { error_code = 3; goto ERROR_PNG; }
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
if (png_ptr == nullptr) { error_code = 4; goto ERROR_PNG; }
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == nullptr) { error_code = 5; goto ERROR_PNG; }
png_set_read_fn(png_ptr, file_descriptor, callback_read_file);
{
int jump_code = 0;
if ( (jump_code = setjmp(png_jmpbuf(png_ptr))) != 0) {
ERR("PNGImage: setjump() returned code %i", jump_code);
error_code = 6; goto ERROR_PNG;
}
}
png_set_sig_bytes(png_ptr, 8);
png_read_info(png_ptr, info_ptr);
png_int_32 depth, color_type;
png_uint_32 width, height;
png_get_IHDR(png_ptr, info_ptr, &width, &height, &depth, &color_type, nullptr, nullptr, nullptr);
m_width = width; m_height = height;
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
png_set_tRNS_to_alpha(png_ptr);
transparency = true;
}
if (depth < 8) {
png_set_packing(png_ptr);
} else {
png_set_strip_16(png_ptr);
}
switch (color_type) {
case PNG_COLOR_TYPE_PALETTE:
png_set_palette_to_rgb(png_ptr);
break;
case PNG_COLOR_TYPE_GRAY:
png_set_expand_gray_1_2_4_to_8(png_ptr);
break;
case PNG_COLOR_TYPE_GA:
png_set_expand_gray_1_2_4_to_8(png_ptr);
break;
case PNG_COLOR_TYPE_RGB:
case PNG_COLOR_TYPE_RGBA:
default:
break;
}
png_read_update_info(png_ptr, info_ptr);
row_size = png_get_rowbytes(png_ptr, info_ptr);
m_size = row_size * height;
if (row_size <= 0) { error_code = 7; goto ERROR_PNG; }
image_buffer = new (std::nothrow) png_byte[m_size];
if (image_buffer == nullptr) { error_code = 8; goto ERROR_PNG; }
row_ptrs = new (std::nothrow) png_bytep[height];
if (row_ptrs == nullptr) { error_code = 9; goto ERROR_PNG; }
for (int32_t i = 0; i < height; ++i) {
row_ptrs[height - (i + 1)] = image_buffer + i * row_size;
}
png_read_image(png_ptr, row_ptrs);
std::fclose(file_descriptor);
png_destroy_read_struct(&png_ptr, &info_ptr, nullptr);
delete [] row_ptrs;
m_buffer = image_buffer;
return;
ERROR_PNG:
m_error_code = error_code;
ERR("Error while reading PNG file: %s, code %i", m_filename, m_error_code);
std::fclose(file_descriptor);
delete [] image_buffer; image_buffer = nullptr;
delete [] row_ptrs; row_ptrs = nullptr;
if (png_ptr != nullptr) {
png_infop* info_ptr_p = info_ptr != nullptr ? &info_ptr : nullptr;
png_destroy_read_struct(&png_ptr, info_ptr_p, nullptr);
}
}
开发者ID:duplyakin,项目名称:CppCourse,代码行数:98,代码来源:image.cpp
示例7: void
/* For little endian systems, ARGB is equivalent to the int32 BGRA.
* So, to read the image as RGB
*/
static SLang_Array_Type *read_image_internal (char *file, int flip, int *color_typep)
{
Png_Type *p;
png_uint_32 width, height, rowbytes;
png_struct *png;
png_info *info;
int bit_depth;
int interlace_type;
int color_type;
unsigned int sizeof_type;
SLindex_Type dims[2];
SLtype data_type;
png_byte **image_pointers = NULL;
png_byte *data = NULL;
SLang_Array_Type *at;
void (*fixup_array_fun) (SLang_Array_Type *);
if (NULL == (p = open_png_file (file)))
return NULL;
png = p->png;
if (setjmp (png_jmpbuf (png)))
{
free_png_type (p);
if (data != NULL) SLfree ((char *) data);
free_image_pointers (image_pointers);
SLang_verror (SL_Read_Error, "Error encountered during I/O to %s", file);
return NULL;
}
png_init_io (png, p->fp);
png_set_sig_bytes (png, 8);
info = p->info;
png_read_info(png, info);
width = png_get_image_width (png, info);
height = png_get_image_height (png, info);
interlace_type = png_get_interlace_type (png, info);
bit_depth = png_get_bit_depth (png, info);
if (bit_depth == 16)
png_set_strip_16 (png);
switch (png_get_color_type (png, info))
{
case PNG_COLOR_TYPE_GRAY:
#if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10209)
if (bit_depth < 8) png_set_expand_gray_1_2_4_to_8 (png);
#else /* deprecated */
if (bit_depth < 8) png_set_gray_1_2_4_to_8 (png);
#endif
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
/* png_set_gray_to_rgb (png); */
break;
case PNG_COLOR_TYPE_PALETTE:
png_set_palette_to_rgb (png);
break;
}
if (png_get_valid(png, info, PNG_INFO_tRNS))
png_set_tRNS_to_alpha(png);
png_read_update_info (png, info);
color_type = png_get_color_type (png, info);
switch (color_type)
{
case PNG_COLOR_TYPE_RGBA:
sizeof_type = 4;
fixup_array_fun = fixup_array_rgba;
data_type = SLang_get_int_type (32);
break;
case PNG_COLOR_TYPE_RGB:
sizeof_type = 4;
fixup_array_fun = fixup_array_rgb;
data_type = SLang_get_int_type (32);
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
sizeof_type = 2;
fixup_array_fun = fixup_array_ga;
data_type = SLang_get_int_type (16);
break;
case PNG_COLOR_TYPE_GRAY:
sizeof_type = 1;
fixup_array_fun = NULL;
data_type = SLANG_UCHAR_TYPE;
break;
default:
SLang_verror (SL_Read_Error, "Unsupported PNG color-type");
free_png_type (p);
return NULL;
//.........这里部分代码省略.........
开发者ID:parke,项目名称:slang,代码行数:101,代码来源:png-module.c
示例8: do_png_read
static void *
do_png_read(struct png_reader * reader,
void *(*alloc)(int w, int h, int bpp, void** datap))
{
png_structp read_ptr;
png_infop info_ptr;
TRACE(SYSTEM, "ready to read png stream\n");
if (reader->read_ptr == NULL) {
reader->info_ptr = NULL;
read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
NULL, png_error, png_warning);
reader->read_ptr = read_ptr;
} else {
read_ptr = reader->read_ptr;
reader->read_ptr_save = read_ptr;
}
if (read_ptr == NULL) {
ERROR(SYSTEM, "libpng: create read_ptr error\n");
THROW(EXCEPTION_CONTINUE, "libpng read error");
}
if (setjmp(png_jmpbuf(read_ptr))) {
ERROR(SYSTEM, "libpng: read error\n");
THROW(EXCEPTION_RESOURCE_LOST, "libpng read error");
}
if (reader->info_ptr == NULL) {
info_ptr = png_create_info_struct(read_ptr);
reader->info_ptr = info_ptr;
} else {
info_ptr = reader->info_ptr;
}
png_set_read_fn(read_ptr, reader->io_ptr,
reader->read_fn);
/* here: begin read */
/* code borrowed from SDL_img's IMG_png.c */
png_uint_32 width, height;
int bit_depth, color_type, interlace_type;
png_read_info(read_ptr, info_ptr);
png_get_IHDR(read_ptr, info_ptr, &width, &height, &bit_depth,
&color_type, &interlace_type, NULL, NULL);
TRACE(SYSTEM, "png bitmap: %dx%d:%d\n", width, height, bit_depth);
if (bit_depth > 8)
png_set_strip_16(read_ptr);
if (bit_depth < 8)
png_set_packing(read_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY) {
TRACE(SYSTEM, "\tcolor type: PNG_COLOR_TYPE_GRAY\n");
png_set_expand(read_ptr);
}
if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
TRACE(SYSTEM, "\tcolor type: PNG_COLOR_TYPE_GRAY_ALPHA\n");
png_set_gray_to_rgb(read_ptr);
}
if (color_type == PNG_COLOR_TYPE_PALETTE) {
TRACE(SYSTEM, "\tcolor type: PNG_COLOR_TYPE_PALETTE\n");
png_set_palette_to_rgb(read_ptr);
}
if (png_get_valid(read_ptr, info_ptr, PNG_INFO_tRNS)) {
TRACE(SYSTEM, "\tstream has PNG_INFO_tRNS\n");
png_set_tRNS_to_alpha(read_ptr);
}
png_read_update_info(read_ptr, info_ptr);
png_get_IHDR(read_ptr, info_ptr, &width, &height, &bit_depth,
&color_type, &interlace_type, NULL, NULL);
TRACE(SYSTEM, "update png bitmap: %dx%d:%d\n", width, height, bit_depth);
/* start read */
if (bit_depth != 8) {
WARNING(RESOURCE, "We don't support this png stream\n");
THROW(EXCEPTION_RESOURCE_LOST, "format error");
}
int bytes_pp;
switch (color_type) {
case PNG_COLOR_TYPE_GRAY:
TRACE(SYSTEM, "\tcolor type: PNG_COLOR_TYPE_GRAY\n");
bytes_pp = 1;
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
TRACE(SYSTEM, "\tcolor type: PNG_COLOR_TYPE_GRAY_ALPHA\n");
bytes_pp = 2;
break;
case PNG_COLOR_TYPE_RGB:
TRACE(SYSTEM, "\tcolor type: PNG_COLOR_TYPE_RGB\n");
//.........这里部分代码省略.........
开发者ID:pi3orama,项目名称:yaavg,代码行数:101,代码来源:utils_png_rw.c
示例9: Warn
ImageData PNGImageCodec::Load(InputStreamPtr& file, const ImageParams& params,
ImageCodecMetaInfo& metaInfo) {
InputStream* readr = file.GetPtr();
// check if png_ptr
if (!CheckIfPng(readr)) {
Warn(String("Image file format is not png: ") + params.name);
}
png_structp png_ptr;
png_infop info_ptr;
png_uint_32 width, height;
int bit_depth, color_type;
bool alpha;
Color32 keycolor;
int keycolor_index = -1;
bool hascolorkey = false;
ImageType imagetype;
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
if (png_ptr == NULL) {
Error("Could not create read struct");
NEX_THROW_GracefulError(EXCEPT_INVALID_CALL);
}
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) {
png_destroy_read_struct(&png_ptr, NULL, NULL);
Error("Could not create info struct");
NEX_THROW_GracefulError(EXCEPT_INVALID_CALL);
}
png_set_error_fn(png_ptr, (void *) (readr), PngWarn, PngWarn);
png_set_read_fn(png_ptr, (void *) (readr), PngReadFile);
png_set_sig_bytes(png_ptr, PNG_BYTES_TO_CHECK);
png_read_info(png_ptr, info_ptr);
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0,
NULL, NULL);
// todo Unstrip
png_set_strip_16(png_ptr);
if (bit_depth != 8 && bit_depth != 16) {
Error("Unsupported bit depth");
NEX_THROW_GracefulError(EXCEPT_INVALID_CALL);
}
switch (color_type) {
case PNG_COLOR_TYPE_GRAY:
case PNG_COLOR_TYPE_GRAY_ALPHA:
if (color_type & PNG_COLOR_MASK_ALPHA)
imagetype = GrayAlpha;
else {
imagetype = Palleted;
png_set_strip_alpha(png_ptr);
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
png_color_16p trans_values;
png_get_tRNS(png_ptr, info_ptr, 0, 0, &trans_values);
hascolorkey = true;
keycolor.red = uint8(trans_values->gray) & 0xff;
keycolor.green = uint8(trans_values->gray) & 0xff;
keycolor.blue = uint8(trans_values->gray) & 0xff;
keycolor.alpha = uint8(trans_values->gray) & 0xff;
}
}
break;
case PNG_COLOR_TYPE_PALETTE:
imagetype = Palleted;
alpha = true;
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
// tRNS chunk. Every palette entry gets its own alpha value.
png_bytep trans;
int num_trans;
png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, 0);
// see if there is a single entry w/ alpha==0 and all other 255.
// if yes use keycolor transparency.
bool only_binary_trans = true;
for (int32 i = 0; (i < num_trans) && only_binary_trans; i++) {
if (trans[i] != 0xff) {
only_binary_trans = only_binary_trans && (trans[i] == 0)
&& (keycolor_index == -1);
keycolor_index = i;
}
}
if (!only_binary_trans) {
keycolor_index = -1;
png_set_palette_to_rgb(png_ptr);
png_set_tRNS_to_alpha(png_ptr);
imagetype = RGBImage;
} else
alpha = false;
} else
alpha = false;
break;
case PNG_COLOR_TYPE_RGBA:
alpha = true;
//.........这里部分代码省略.........
开发者ID:obhi-d,项目名称:nextar,代码行数:101,代码来源:PNGImageCodec.cpp
示例10: png2vips_header
/* Read a png header.
*/
static int
png2vips_header( Read *read, VipsImage *out )
{
png_uint_32 width, height;
int bit_depth, color_type;
int interlace_type;
png_uint_32 res_x, res_y;
int unit_type;
png_charp name;
int compression_type;
/* Well thank you, libpng.
*/
#if PNG_LIBPNG_VER < 10400
png_charp profile;
#else
png_bytep profile;
#endif
png_uint_32 proflen;
int bands;
VipsInterpretation interpretation;
double Xres, Yres;
if( setjmp( png_jmpbuf( read->pPng ) ) )
return( -1 );
png_get_IHDR( read->pPng, read->pInfo,
&width, &height, &bit_depth, &color_type,
&interlace_type, NULL, NULL );
/* png_get_channels() gives us 1 band for palette images ... so look
* at colour_type for output bands.
*
* Ignore alpha, we detect that separately below.
*/
switch( color_type ) {
case PNG_COLOR_TYPE_PALETTE:
bands = 3;
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
case PNG_COLOR_TYPE_GRAY:
bands = 1;
break;
case PNG_COLOR_TYPE_RGB:
case PNG_COLOR_TYPE_RGB_ALPHA:
bands = 3;
break;
default:
vips_error( "png2vips", "%s", _( "unsupported color type" ) );
return( -1 );
}
if( bit_depth > 8 ) {
if( bands < 3 )
interpretation = VIPS_INTERPRETATION_GREY16;
else
interpretation = VIPS_INTERPRETATION_RGB16;
}
else {
if( bands < 3 )
interpretation = VIPS_INTERPRETATION_B_W;
else
interpretation = VIPS_INTERPRETATION_sRGB;
}
/* Expand palette images.
*/
if( color_type == PNG_COLOR_TYPE_PALETTE )
png_set_palette_to_rgb( read->pPng );
/* Expand transparency.
*/
if( png_get_valid( read->pPng, read->pInfo, PNG_INFO_tRNS ) ) {
png_set_tRNS_to_alpha( read->pPng );
bands += 1;
}
else if( color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
color_type == PNG_COLOR_TYPE_RGB_ALPHA ) {
/* Some images have no transparency chunk, but still set
* color_type to alpha.
*/
bands += 1;
}
/* Expand <8 bit images to full bytes.
*/
if( color_type == PNG_COLOR_TYPE_GRAY &&
bit_depth < 8 )
png_set_expand_gray_1_2_4_to_8( read->pPng );
/* If we're an INTEL byte order machine and this is 16bits, we need
//.........这里部分代码省略.........
开发者ID:homerjam,项目名称:libvips,代码行数:101,代码来源:vipspng.c
示例11: loadPngFile
bool
loadPngFile(
IMAGE_T* image,
FILE *file)
{
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
NULL,
NULL,
NULL);
if (png_ptr == NULL)
{
return false;
}
png_infop info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL)
{
png_destroy_read_struct(&png_ptr, 0, 0);
return false;
}
if (setjmp(png_jmpbuf(png_ptr)))
{
png_destroy_read_struct(&png_ptr, &info_ptr, 0);
return false;
}
//---------------------------------------------------------------------
png_init_io(png_ptr, file);
png_read_info(png_ptr, info_ptr);
//---------------------------------------------------------------------
png_byte colour_type = png_get_color_type(png_ptr, info_ptr);
png_byte bit_depth = png_get_bit_depth(png_ptr, info_ptr);
VC_IMAGE_TYPE_T type = VC_IMAGE_RGB888;
if (colour_type & PNG_COLOR_MASK_ALPHA)
{
type = VC_IMAGE_RGBA32;
}
initImage(image,
type,
png_get_image_width(png_ptr, info_ptr),
png_get_image_height(png_ptr, info_ptr),
false);
//---------------------------------------------------------------------
double gamma = 0.0;
if (png_get_gAMA(png_ptr, info_ptr, &gamma))
{
png_set_gamma(png_ptr, 2.2, gamma);
}
//---------------------------------------------------------------------
if (colour_type == PNG_COLOR_TYPE_PALETTE)
{
png_set_palette_to_rgb(png_ptr);
}
if ((colour_type == PNG_COLOR_TYPE_GRAY) && (bit_depth < 8))
{
png_set_expand_gray_1_2_4_to_8(png_ptr);
}
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
{
png_set_tRNS_to_alpha(png_ptr);
}
if (bit_depth == 16)
{
#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
png_set_scale_16(png_ptr);
#else
png_set_strip_16(png_ptr);
#endif
}
if (colour_type == PNG_COLOR_TYPE_GRAY ||
colour_type == PNG_COLOR_TYPE_GRAY_ALPHA)
{
png_set_gray_to_rgb(png_ptr);
}
//---------------------------------------------------------------------
png_read_update_info(png_ptr, info_ptr);
//---------------------------------------------------------------------
//.........这里部分代码省略.........
开发者ID:AndrewFromMelbourne,项目名称:raspidmx,代码行数:101,代码来源:loadpng.c
示例12: png_create_read_struct
Image* Image::_loadPng(hsbase& stream, int size)
{
png_structp pngPtr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
png_infop infoPtr = png_create_info_struct(pngPtr);
png_infop endInfo = png_create_info_struct(pngPtr);
setjmp(png_jmpbuf(pngPtr));
png_set_read_fn(pngPtr, &stream, &_pngZipRead);
png_read_info(pngPtr, infoPtr);
png_get_IHDR(pngPtr, infoPtr, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
png_set_interlace_handling(pngPtr);
int bpp = pngPtr->channels;
if (pngPtr->color_type == PNG_COLOR_TYPE_PALETTE)
{
png_set_palette_to_rgb(pngPtr);
bpp = 3;
}
if (pngPtr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA && bpp > 1)
{
png_set_strip_alpha(pngPtr);
bpp -= 1;
}
if (png_get_valid(pngPtr, infoPtr, PNG_INFO_tRNS))
{
png_set_tRNS_to_alpha(pngPtr);
++bpp;
}
if (pngPtr->bit_depth == 16)
{
png_set_strip_16(pngPtr);
}
png_read_update_info(pngPtr, infoPtr);
int rowBytes = png_get_rowbytes(pngPtr, infoPtr);
png_byte* imageData = new png_byte[rowBytes * pngPtr->height];
png_bytep* rowPointers = new png_bytep[pngPtr->height];
for_itert (unsigned int, i, 0, pngPtr->height)
{
rowPointers[i] = imageData + i * rowBytes;
}
png_read_image(pngPtr, rowPointers);
png_read_end(pngPtr, infoPtr);
// assign Image data
Image* image = new Image();
image->data = (unsigned char*)imageData;
image->w = pngPtr->width;
image->h = pngPtr->height;
switch (bpp)
{
case 4:
image->format = FORMAT_RGBA;
break;
case 3:
image->format = FORMAT_RGB;
break;
case 1:
image->format = FORMAT_ALPHA;
break;
default:
image->format = FORMAT_RGBA; // TODOaa - maybe palette should go here
break;
}
// clean up
png_destroy_read_struct(&pngPtr, &infoPtr, &endInfo);
delete [] rowPointers;
return image;
}
开发者ID:Ryex,项目名称:libapril,代码行数:65,代码来源:ImagePng.cpp
示例13: ConfigureDecoder
/**
Configure the decoder so that decoded pixels are compatible with a FREE_IMAGE_TYPE format.
Set conversion instructions as needed.
@param png_ptr PNG handle
@param info_ptr PNG info handle
@param flags Decoder flags
@param output_image_type Returned FreeImage converted image type
@return Returns TRUE if successful, returns FALSE otherwise
@see png_read_update_info
*/
static BOOL
ConfigureDecoder(png_structp png_ptr, png_infop info_ptr, int flags, FREE_IMAGE_TYPE *output_image_type) {
// get original image info
const int color_type = png_get_color_type(png_ptr, info_ptr);
const int bit_depth = png_get_bit_depth(png_ptr, info_ptr);
const int pixel_depth = bit_depth * png_get_channels(png_ptr, info_ptr);
FREE_IMAGE_TYPE image_type = FIT_BITMAP; // assume standard image type
// check for transparency table or single transparent color
BOOL bIsTransparent = png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) == PNG_INFO_tRNS ? TRUE : FALSE;
// check allowed combinations of colour type and bit depth
// then get converted FreeImage type
switch(color_type) {
case PNG_COLOR_TYPE_GRAY: // color type '0', bitdepth = 1, 2, 4, 8, 16
switch(bit_depth) {
case 1:
case 2:
case 4:
case 8:
// expand grayscale images to the full 8-bit from 2-bit/pixel
if (pixel_depth == 2) {
png_set_expand_gray_1_2_4_to_8(png_ptr);
}
// if a tRNS chunk is provided, we must also expand the grayscale data to 8-bits,
// this allows us to make use of the transparency table with existing FreeImage methods
if (bIsTransparent && (pixel_depth < 8)) {
png_set_expand_gray_1_2_4_to_8(png_ptr);
}
break;
case 16:
image_type = (pixel_depth == 16) ? FIT_UINT16 : FIT_UNKNOWN;
// 16-bit grayscale images can contain a transparent value (shade)
// if found, expand the transparent value to a full alpha channel
if (bIsTransparent && (image_type != FIT_UNKNOWN)) {
// expand tRNS to a full alpha channel
png_set_tRNS_to_alpha(png_ptr);
// expand new 16-bit gray + 16-bit alpha to full 64-bit RGBA
png_set_gray_to_rgb(png_ptr);
image_type = FIT_RGBA16;
}
break;
default:
image_type = FIT_UNKNOWN;
break;
}
break;
case PNG_COLOR_TYPE_RGB: // color type '2', bitdepth = 8, 16
switch(bit_depth) {
case 8:
image_type = (pixel_depth == 24) ? FIT_BITMAP : FIT_UNKNOWN;
break;
case 16:
image_type = (pixel_depth == 48) ? FIT_RGB16 : FIT_UNKNOWN;
break;
default:
image_type = FIT_UNKNOWN;
break;
}
// sometimes, 24- or 48-bit images may contain transparency information
// check for this use case and convert to an alpha-compatible format
if (bIsTransparent && (image_type != FIT_UNKNOWN)) {
// if the image is 24-bit RGB, mark it as 32-bit; if it is 48-bit, mark it as 64-bit
image_type = (pixel_depth == 24) ? FIT_BITMAP : (pixel_depth == 48) ? FIT_RGBA16 : FIT_UNKNOWN;
// expand tRNS chunk to alpha channel
png_set_tRNS_to_alpha(png_ptr);
}
break;
case PNG_COLOR_TYPE_PALETTE: // color type '3', bitdepth = 1, 2, 4, 8
switch(bit_depth) {
case 1:
case 2:
case 4:
case 8:
// expand palette images to the full 8 bits from 2 bits/pixel
if (pixel_depth == 2) {
png_set_packing(png_ptr);
}
// if a tRNS chunk is provided, we must also expand the palletized data to 8-bits,
//.........这里部分代码省略.........
开发者ID:FlyApple,项目名称:_3rdParty,代码行数:101,代码来源:PluginPNG.cpp
示例14: _tfopen_s
//.........这里部分代码省略.........
if( info_ptr == NULL ) {
png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
fclose(file);
__EEDEF_DEBUG_ERROR(__EEDEF_FUNCTION_NAME, _EESTR("unknown header info."));
return EEbuffer();
}
// フッター情報のチャンクを初期化する
png_infop end_info = png_create_info_struct(png_ptr);
if( end_info == NULL ) {
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
fclose(file);
__EEDEF_DEBUG_ERROR(__EEDEF_FUNCTION_NAME, _EESTR("unknown footer info."));
return EEbuffer();
}
// ファイルポインタをライブラリに設定する
png_init_io(png_ptr, file);
// シグネチャのチェックを行った場合は、データを読み込む前にその通知をする
png_set_sig_bytes(png_ptr, header_size);
// ヘッダ情報を読み込む
png_read_info(png_ptr, info_ptr);
png_uint_32 png_width = 0;
png_uint_32 png_height = 0;
EEint png_bit_depth = 0;
EEint png_color_type = 0;
// IHDRチャンク情報を読み込む
png_get_IHDR(
png_ptr, // PNG構造体
info_ptr, // ヘッダー情報チャンク
&png_width, // [出力] 画像の幅
&png_height, // [出力] 画像の高さ
&png_bit_depth, // [出力] ビット深度
&png_color_type, // [出力] カラータイプ
NULL, //
NULL, //
NULL //
);
if( png_bit_depth == 1 || png_bit_depth == 2 || png_bit_depth == 4 ) {
// 1,2,4bit → 8bit
png_set_packing(png_ptr);
} else if( png_bit_depth == 16 ) {
// 16bit → 8bit
png_set_strip_16(png_ptr);
}
if( png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) ) {
// tRNSチャンクがある → アルファチャンネルに変換
png_set_tRNS_to_alpha(png_ptr);
} else if ( !IS_BIT_STAND(png_color_type, PNG_COLOR_MASK_ALPHA) ) {
// アルファチャンネルがない → アルファチャンネルを追加
png_set_add_alpha(png_ptr, 255, PNG_FILLER_AFTER);
}
if ( IS_BIT_STAND(png_color_type, PNG_COLOR_MASK_PALETTE) ) {
// カラーパレットがある → RGBフルカラーへ変換
png_set_palette_to_rgb(png_ptr);
}
if ( !IS_BIT_STAND(png_color_type, PNG_COLOR_MASK_COLOR) ) {
// グレースケールである → RGBフルカラーへ変換
png_set_gray_to_rgb(png_ptr);
}
// 変換を反映する
png_read_update_info(png_ptr, info_ptr);
// 領域の確保
png_size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);
EEbuffer returnBuffer(rowbytes * png_height);
// 行配列にデータを取得する
png_bytepp image_row_pointer = new png_bytep[png_height];
for( png_uint_32 i = 0; i < png_height; i++ ) {
image_row_pointer[i] = &returnBuffer[i * rowbytes];
}
png_read_image(png_ptr, image_row_pointer);
delete[] image_row_pointer;
// 不要になったデータを破棄
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
fclose(file);
// 出力
__EEDEF_DEBUG_MESSAGE(__EEDEF_FUNCTION_NAME, _EESTR("success."));
if( outTextureWidth != EENULL ) *outTextureWidth = png_width;
if( outTextureHeight != EENULL ) *outTextureHeight = png_height;
return returnBuffer;
}
开发者ID:keykun827,项目名称:easyengine,代码行数:101,代码来源:EECFileIO.cpp
示例15: fopen
void png::load(const std::string& file_name)
{
// unfortunately, we need to break down to the C-code level here, since
// libpng is written in C itself
// we need to open the file in binary mode
FILE* fp = fopen(file_name.c_str(), "rb");
if (!fp)
{
throw std::runtime_error{"failed to open " + file_name};
}
// read in the header (max size of 8), use it to validate this as a png file
png_byte header[8];
fread(header, 1, 8, fp);
if (png_sig_cmp(header, 0, 8))
{
fclose(fp);
throw std::runtime_error{file_name + " is not a valid png file"};
}
// set up libpng structs for reading info
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr,
nullptr, nullptr);
if (!png_ptr)
{
fclose(fp);
throw std::runtime_error{"Failed to create libpng read struct"};
}
png_infop info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
png_destroy_read_struct(&png_ptr, nullptr, nullptr);
fclose(fp);
throw std::runtime_error{"Failed to create libpng info struct"};
}
// set error handling to not abort the entire program
if (setjmp(png_jmpbuf(png_ptr)))
{
png_destroy_read_struct(&png_ptr, &info_ptr, nullptr);
fclose(fp);
throw std::runtime_error{"Error reading png metadata"};
}
// initialize png reading
png_init_io(png_ptr, fp);
// let it know we've already read the first 8 bytes
png_set_sig_bytes(png_ptr, 8);
// read in the basic image info
png_read_info(png_ptr, info_ptr);
// convert to 8 bits
png_byte bit_depth = png_get_bit_depth(png_ptr, info_ptr);
if (bit_depth == 16)
png_set_strip_16(png_ptr);
// verify this is in RGBA format, and if not, convert it to RGBA
png_byte color_type = png_get_color_type(png_ptr, info_ptr);
if (color_type != PNG_COLOR_TYPE_RGBA && color_type != PNG_COLOR_TYPE_RGB)
{
if (color_type == PNG_COLOR_TYPE_GRAY || color_type
== PNG_COLOR_TYPE_GRAY_ALPHA)
{
if (bit_depth < 8)
png_set_expand(png_ptr);
png_set_gray_to_rgb(png_ptr);
}
if (color_type == PNG_COLOR_TYPE_PALETTE)
png_set_palette_to_rgb(png_ptr);
}
// convert tRNS to alpha channel
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
png_set_tRNS_to_alpha(png_ptr);
size_t width = png_get_image_width(png_ptr, info_ptr);
size_t height = png_get_image_height(png_ptr, info_ptr);
rgba_pixel* newpix = nullptr;
png_byte* row = nullptr;
|
请发表评论