View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0002480 | DarkRadiant | Shader System | public | 12.12.2010 02:33 | 31.07.2011 04:43 |
Reporter | dersaidin | Assigned To | greebo | ||
Priority | normal | Severity | feature | Reproducibility | N/A |
Status | closed | Resolution | fixed | ||
Product Version | 1.5.0 | ||||
Target Version | 1.5.0 | Fixed in Version | 1.5.0 | ||
Summary | 0002480: Xreal: PNG Support | ||||
Description | Hello, Xreal supports PNGs. Please add PNG support to support Xreal. This patch is from xrealradiant. Forking xrealradiant to add this and a few other minor things is a waste of time and effort! This, and other xreal support I hope to add, shouldn't impact DarkMod support in any way. I hope to provide patches for the remaining things incrementally. | ||||
Additional Information | In png.cpp:114 png_set_gray_1_2_4_to_8(png_ptr); //This works with the libpng in win32deps //png_set_expand_gray_1_2_4_to_8(png_ptr); //This requires a newer version Documented at: http://libpng.sourceforge.net/ANNOUNCE-1.4.0.txt Section 2 m Your choice which libpng you want to go with. I didn't add the appropriate library to the linux Makefiles either. | ||||
Tags | No tags attached. | ||||
Attached Files | darkradiant6239_png.patch (17,308 bytes)
Index: plugins/image/image.cpp =================================================================== --- plugins/image/image.cpp (revision 6239) +++ plugins/image/image.cpp (working copy) @@ -25,6 +25,7 @@ #include "jpeg.h" #include "tga.h" +#include "png.h" #include "bmp.h" #include "pcx.h" #include "dds.h" @@ -33,6 +34,7 @@ typedef boost::shared_ptr<TGALoader> TGALoaderPtr; typedef boost::shared_ptr<JPGLoader> JPGLoaderPtr; +typedef boost::shared_ptr<PNGLoader> PNGLoaderPtr; typedef boost::shared_ptr<PCXLoader> PCXLoaderPtr; typedef boost::shared_ptr<BMPLoader> BMPLoaderPtr; typedef boost::shared_ptr<DDSLoader> DDSLoaderPtr; @@ -41,6 +43,7 @@ extern "C" void DARKRADIANT_DLLEXPORT RegisterModule(IModuleRegistry& registry) { registry.registerModule(TGALoaderPtr(new TGALoader)); registry.registerModule(JPGLoaderPtr(new JPGLoader)); + registry.registerModule(PNGLoaderPtr(new PNGLoader)); registry.registerModule(PCXLoaderPtr(new PCXLoader)); registry.registerModule(BMPLoaderPtr(new BMPLoader)); registry.registerModule(DDSLoaderPtr(new DDSLoader)); Index: plugins/image/Makefile.am =================================================================== --- plugins/image/Makefile.am (revision 6239) +++ plugins/image/Makefile.am (working copy) @@ -13,5 +13,7 @@ DDSImage.cpp \ ImageGDK.cpp \ pcx.cpp \ - tga.cpp + tga.cpp \ + png.cpp + Index: plugins/image/Makefile.in =================================================================== --- plugins/image/Makefile.in (revision 6239) +++ plugins/image/Makefile.in (working copy) @@ -305,7 +305,8 @@ DDSImage.cpp \ ImageGDK.cpp \ pcx.cpp \ - tga.cpp + tga.cpp \ + png.cpp all: all-am Index: plugins/image/png.cpp =================================================================== --- plugins/image/png.cpp (revision 0) +++ plugins/image/png.cpp (revision 0) @@ -0,0 +1,172 @@ +/* +Copyright (C) 1999-2006 Id Software, Inc. and contributors. +For a list of contributors, see the accompanying CONTRIBUTORS file. + +This file is part of GtkRadiant. + +GtkRadiant is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +GtkRadiant is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GtkRadiant; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#define png_infopp_NULL (png_infopp)NULL +#define int_p_NULL (int*)NULL + +#include "png.h" + +#include <png.h> +//#include <setjmp.h> +//#include <stdlib.h> +//#include <stdio.h> +//#include <string.h> + +#include "ifilesystem.h" + +#include "imagelib.h" + +typedef unsigned char byte; + +void user_warning_fn(png_structp png_ptr, png_const_charp warning_msg) +{ + globalErrorStream() << "libpng warning: " << warning_msg << "\n"; +} + +void user_error_fn(png_structp png_ptr, png_const_charp error_msg) +{ + globalErrorStream() << "libpng error: " << error_msg << "\n"; + longjmp(png_ptr->jmpbuf, 0); +} + +void user_read_data(png_structp png_ptr, png_bytep data, png_uint_32 length) +{ + png_bytep *p_p_fbuffer = (png_bytep*)png_get_io_ptr(png_ptr); + memcpy(data, *p_p_fbuffer, length); + *p_p_fbuffer += length; +} + +static RGBAImagePtr LoadPNGBuff (unsigned char* fbuffer) +{ + png_byte** row_pointers; + png_bytep p_fbuffer; + + p_fbuffer = fbuffer; + + // the reading glue + // http://www.libpng.org/pub/png/libpng-manual.html + + png_structp png_ptr = png_create_read_struct + (PNG_LIBPNG_VER_STRING, (png_voidp)NULL, + user_error_fn, user_warning_fn); + if (!png_ptr) + { + globalErrorStream() << "libpng error: png_create_read_struct\n"; + RGBAImagePtr(); + } + + png_infop info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) { + png_destroy_read_struct(&png_ptr, + (png_infopp)NULL, (png_infopp)NULL); + globalErrorStream() << "libpng error: png_create_info_struct (info_ptr)\n"; + RGBAImagePtr(); + } + + png_infop end_info = png_create_info_struct(png_ptr); + if (!end_info) { + png_destroy_read_struct(&png_ptr, &info_ptr, + (png_infopp)NULL); + globalErrorStream() << "libpng error: png_create_info_struct (end_info)\n"; + RGBAImagePtr(); + } + + // configure the read function + png_set_read_fn(png_ptr, (voidp)&p_fbuffer, (png_rw_ptr)&user_read_data); + + if (setjmp(png_ptr->jmpbuf)) { + png_destroy_read_struct(&png_ptr, &info_ptr, + &end_info); + RGBAImagePtr(); + } + + png_read_info(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); + + // we want to treat all images the same way + // The following code transforms grayscale images of less than 8 to 8 bits, + // changes paletted images to RGB, and adds a full alpha channel if there is + // transparency information in a tRNS chunk. + if (color_type == PNG_COLOR_TYPE_PALETTE) + png_set_palette_to_rgb(png_ptr); + + if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) + png_set_gray_1_2_4_to_8(png_ptr); + //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 ( ! ( color_type & PNG_COLOR_MASK_ALPHA ) ) { + // Set the background color to draw transparent and alpha images over. + png_color_16 my_background, *image_background; + + if (png_get_bKGD(png_ptr, info_ptr, &image_background)) + png_set_background(png_ptr, image_background, + PNG_BACKGROUND_GAMMA_FILE, 1, 1.0); + else + png_set_background(png_ptr, &my_background, + PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0); + + // Add alpha byte after each RGB triplet + png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER); + } + + // read the sucker in one chunk + png_read_update_info(png_ptr, info_ptr); + + color_type = png_get_color_type(png_ptr, info_ptr); + bit_depth = png_get_bit_depth(png_ptr, info_ptr); + + int width = png_get_image_width(png_ptr, info_ptr); + int height = png_get_image_height(png_ptr, info_ptr); + + // allocate the pixel buffer, and the row pointers + RGBAImagePtr image(new RGBAImage(width, height)); + + row_pointers = (png_byte**) malloc((height) * sizeof(png_byte*)); + + int i; + for(i = 0; i < (height); i++) + row_pointers[i] = (png_byte*)(image->getMipMapPixels(0)) + i * 4 * (width); + + // actual read + png_read_image(png_ptr, row_pointers); + + /* read rest of file, and get additional chunks in info_ptr - REQUIRED */ + png_read_end(png_ptr, info_ptr); + + /* free up the memory structure */ + png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL); + + free(row_pointers); + + return image; +} + +ImagePtr LoadPNG(ArchiveFile& file) +{ + ScopedArchiveBuffer buffer(file); + return LoadPNGBuff(buffer.buffer);//, static_cast<int>(buffer.length)); +} + Index: plugins/image/png.h =================================================================== --- plugins/image/png.h (revision 0) +++ plugins/image/png.h (revision 0) @@ -0,0 +1,77 @@ +/* +Copyright (C) 1999-2006 Id Software, Inc. and contributors. +For a list of contributors, see the accompanying CONTRIBUTORS file. + +This file is part of GtkRadiant. + +GtkRadiant is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +GtkRadiant is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GtkRadiant; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#if !defined (INCLUDED_PNG_H) +#define INCLUDED_PNG_H + +#include "ifilesystem.h" +#include "iimage.h" +#include "imagelib.h" // for RGBAImagePtr +#include <iostream> + +ImagePtr LoadPNG(ArchiveFile& file); + +/* Tr3B: A PNGLoader is capable of loading Portable Network Graphic (PNG) files. + * + * Use load() to actually retrieve an Image* object with the loaded image. + * + * Shouldn't be used to load textures directly, use the + * GlobalShaderSystem() module instead. + * + * Complies with the ImageLoader interface defined in "iimage.h" + */ +class PNGLoader : + public ImageLoader +{ +public: + /* greebo: This loads the file and returns the pointer to + * the allocated Image object (or NULL, if the load failed). + */ + ImagePtr load(ArchiveFile& file) const { + // Pass the call to the according load function + return LoadPNG(file); + } + + /* greebo: Gets the file extension of the supported image file type (e.g. "jpg") + */ + std::string getExtension() const { + return "png"; + } + + // RegisterableModule implementation + virtual const std::string& getName() const { + static std::string _name("ImageLoaderPNG"); + return _name; + } + + virtual const StringSet& getDependencies() const { + static StringSet _dependencies; // no dependencies + return _dependencies; + } + + virtual void initialiseModule(const ApplicationContext& ctx) { + globalOutputStream() << "ImageLoaderPNG::initialiseModule called.\n"; + } +}; + +#endif + + Index: tools/vcprojects/image.vcproj =================================================================== --- tools/vcprojects/image.vcproj (revision 6239) +++ tools/vcprojects/image.vcproj (working copy) @@ -48,7 +48,7 @@ Name="VCCLCompilerTool" AdditionalOptions="/EHs /MP" Optimization="0" - AdditionalIncludeDirectories=""$(SolutionDir)/../../include";"$(SolutionDir)/../../libs";"$(SolutionDir)/../../w32deps/boost/include";"$(SolutionDir)/../../w32deps/libxml2/include";"$(SolutionDir)/../../w32deps/gtk2/include/gtk-2.0";"$(SolutionDir)/../../w32deps/gtk2/include/atk-1.0";"$(SolutionDir)/../../w32deps/gtk2/include/glib-2.0";"$(SolutionDir)/../../w32deps/gtk2/include/cairo";"$(SolutionDir)/../../w32deps/gtk2/include/pango-1.0";"$(SolutionDir)/../../w32deps/gtk2/lib/glib-2.0/include";"$(SolutionDir)/../../w32deps/gtk2/lib/gtk-2.0/include";"$(SolutionDir)/../../w32deps/glew/include"" + AdditionalIncludeDirectories=""$(SolutionDir)/../../include";"$(SolutionDir)/../../libs";"$(SolutionDir)/../../w32deps/boost/include";"$(SolutionDir)/../../w32deps/libxml2/include";"$(SolutionDir)/../../w32deps/gtk2/include/gtk-2.0";"$(SolutionDir)/../../w32deps/gtk2/include/atk-1.0";"$(SolutionDir)/../../w32deps/gtk2/include/glib-2.0";"$(SolutionDir)/../../w32deps/gtk2/include/cairo";"$(SolutionDir)/../../w32deps/gtk2/include/pango-1.0";"$(SolutionDir)/../../w32deps/gtk2/lib/glib-2.0/include";"$(SolutionDir)/../../w32deps/gtk2/lib/gtk-2.0/include";"$(SolutionDir)/../../w32deps/glew/include";"$(SolutionDir)/../../w32deps/libpng/include";"$(SolutionDir)/../../w32deps/zlib/include"" PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;WIN32;" StringPooling="true" MinimalRebuild="false" @@ -77,11 +77,11 @@ <Tool Name="VCLinkerTool" AdditionalOptions="/NODEFAULTLIB:LIBCMT" - AdditionalDependencies="ddslib.lib jpeglib.lib xmlutillib.lib libxml2.lib glib-2.0.lib gtk-win32-2.0.lib gdk-win32-2.0.lib gobject-2.0.lib gdk_pixbuf-2.0.lib glu32.lib glew32.lib opengl32.lib " + AdditionalDependencies="ddslib.lib jpeglib.lib xmlutillib.lib libxml2.lib glib-2.0.lib gtk-win32-2.0.lib gdk-win32-2.0.lib gobject-2.0.lib gdk_pixbuf-2.0.lib glu32.lib glew32.lib opengl32.lib libpng.lib" OutputFile="$(OutDir)/$(ProjectName).dll" LinkIncremental="1" SuppressStartupBanner="true" - AdditionalLibraryDirectories=""$(SolutionDir)\..\..\build\libs\$(PlatformName)\$(ConfigurationName)";"$(SolutionDir)\..\..\build\libs\$(PlatformName)";"$(SolutionDir)\..\..\w32deps/gtk2\lib";"$(SolutionDir)\..\..\w32deps/glew\lib";"$(SolutionDir)\..\..\w32deps\libxml2\lib"" + AdditionalLibraryDirectories=""$(SolutionDir)\..\..\build\libs\$(PlatformName)\$(ConfigurationName)";"$(SolutionDir)\..\..\build\libs\$(PlatformName)";"$(SolutionDir)\..\..\w32deps/gtk2\lib";"$(SolutionDir)\..\..\w32deps/glew\lib";"$(SolutionDir)\..\..\w32deps\libxml2\lib";"$(SolutionDir)\..\..\w32deps\libpng\lib\pkgconfig"" IgnoreDefaultLibraryNames="" ModuleDefinitionFile="$(SolutionDir)/../../plugins/$(ProjectName)/$(ProjectName).def" GenerateDebugInformation="true" @@ -243,7 +243,7 @@ InlineFunctionExpansion="2" EnableIntrinsicFunctions="true" FavorSizeOrSpeed="1" - AdditionalIncludeDirectories=""$(SolutionDir)/../../include";"$(SolutionDir)/../../libs";"$(SolutionDir)/../../w32deps/boost/include";"$(SolutionDir)/../../w32deps/libxml2/include";"$(SolutionDir)/../../w32deps/gtk2/include/gtk-2.0";"$(SolutionDir)/../../w32deps/gtk2/include/atk-1.0";"$(SolutionDir)/../../w32deps/gtk2/include/glib-2.0";"$(SolutionDir)/../../w32deps/gtk2/include/cairo";"$(SolutionDir)/../../w32deps/gtk2/include/pango-1.0";"$(SolutionDir)/../../w32deps/gtk2/lib/glib-2.0/include";"$(SolutionDir)/../../w32deps/gtk2/lib/gtk-2.0/include";"$(SolutionDir)/../../w32deps/glew/include"" + AdditionalIncludeDirectories=""$(SolutionDir)/../../include";"$(SolutionDir)/../../libs";"$(SolutionDir)/../../w32deps/boost/include";"$(SolutionDir)/../../w32deps/libxml2/include";"$(SolutionDir)/../../w32deps/gtk2/include/gtk-2.0";"$(SolutionDir)/../../w32deps/gtk2/include/atk-1.0";"$(SolutionDir)/../../w32deps/gtk2/include/glib-2.0";"$(SolutionDir)/../../w32deps/gtk2/include/cairo";"$(SolutionDir)/../../w32deps/gtk2/include/pango-1.0";"$(SolutionDir)/../../w32deps/gtk2/lib/glib-2.0/include";"$(SolutionDir)/../../w32deps/gtk2/lib/gtk-2.0/include";"$(SolutionDir)/../../w32deps/glew/include";"$(SolutionDir)/../../w32deps/libpng/include";"$(SolutionDir)/../../w32deps/zlib/include"" PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;WIN32;NDEBUG" StringPooling="true" ExceptionHandling="0" @@ -267,11 +267,11 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="ddslib.lib jpeglib.lib xmlutillib.lib libxml2.lib glib-2.0.lib gtk-win32-2.0.lib gdk-win32-2.0.lib gobject-2.0.lib gdk_pixbuf-2.0.lib glu32.lib glew32.lib opengl32.lib " + AdditionalDependencies="ddslib.lib jpeglib.lib xmlutillib.lib libxml2.lib glib-2.0.lib gtk-win32-2.0.lib gdk-win32-2.0.lib gobject-2.0.lib gdk_pixbuf-2.0.lib glu32.lib glew32.lib opengl32.lib libpng.lib" OutputFile="$(OutDir)/$(ProjectName).dll" LinkIncremental="1" SuppressStartupBanner="true" - AdditionalLibraryDirectories=""$(SolutionDir)\..\..\build\libs\$(PlatformName)\$(ConfigurationName)";"$(SolutionDir)\..\..\build\libs\$(PlatformName)";"$(SolutionDir)\..\..\w32deps/gtk2\lib";"$(SolutionDir)\..\..\w32deps/glew\lib";"$(SolutionDir)\..\..\w32deps\libxml2\lib"" + AdditionalLibraryDirectories=""$(SolutionDir)\..\..\build\libs\$(PlatformName)\$(ConfigurationName)";"$(SolutionDir)\..\..\build\libs\$(PlatformName)";"$(SolutionDir)\..\..\w32deps/gtk2\lib";"$(SolutionDir)\..\..\w32deps/glew\lib";"$(SolutionDir)\..\..\w32deps\libxml2\lib";"$(SolutionDir)/../../w32deps/libpng/lib/pkgconfig"" IgnoreDefaultLibraryNames="" ModuleDefinitionFile="$(SolutionDir)/../../plugins/$(ProjectName)/$(ProjectName).def" GenerateDebugInformation="true" @@ -472,6 +472,14 @@ > </File> <File + RelativePath="..\..\plugins\image\png.cpp" + > + </File> + <File + RelativePath="..\..\plugins\image\png.h" + > + </File> + <File RelativePath="..\..\plugins\image\tga.cpp" > </File> | ||||
Resolved. Does this work for you? | |
Works for me :) | |
A friend just ran into lib versioning problems with libpng. Suggest something along the lines of: #ifndef png_set_gray_1_2_4_to_8 #define png_set_gray_1_2_4_to_8(png_ptr) png_set_expand_gray_1_2_4_to_8(png_ptr) #endif |
|
I found this in KDE bugzilla: #if PNG_LIBPNG_VER < 10400 png_set_gray_1_2_4_to_8(png_ptr); #else png_set_expand_gray_1_2_4_to_8(png_ptr); #endif |
|
Sounds like a good fix, I'll commit that. edit: done with rev. 6271. |
|
Date Modified | Username | Field | Change |
---|---|---|---|
12.12.2010 02:33 | dersaidin | New Issue | |
12.12.2010 02:33 | dersaidin | File Added: darkradiant6239_png.patch | |
18.12.2010 04:11 | greebo | Status | new => acknowledged |
18.12.2010 12:36 | greebo | Assigned To | => greebo |
18.12.2010 12:36 | greebo | Priority | high => normal |
18.12.2010 12:36 | greebo | Status | acknowledged => assigned |
18.12.2010 13:40 | greebo | Note Added: 0003392 | |
18.12.2010 13:40 | greebo | Status | assigned => resolved |
18.12.2010 13:40 | greebo | Fixed in Version | => 1.5.0 |
18.12.2010 13:40 | greebo | Resolution | open => fixed |
18.12.2010 13:40 | greebo | Product Version | => 1.5.0 |
18.12.2010 13:40 | greebo | Target Version | => 1.5.0 |
19.12.2010 13:08 | dersaidin | Note Added: 0003393 | |
24.12.2010 12:18 | dersaidin | Note Added: 0003403 | |
23.01.2011 03:45 | radon | Note Added: 0003475 | |
23.01.2011 04:30 | greebo | Note Added: 0003476 | |
31.07.2011 04:43 | greebo | Status | resolved => closed |