Index: head/graphics/pfstools/Makefile =================================================================== --- head/graphics/pfstools/Makefile (revision 445721) +++ head/graphics/pfstools/Makefile (revision 445722) @@ -1,85 +1,85 @@ # Created by: Daniel O'Connor # $FreeBSD$ PORTNAME= pfstools PORTVERSION= 1.8.5 -PORTREVISION= 4 +PORTREVISION= 5 CATEGORIES= graphics MASTER_SITES= SF MAINTAINER= fbsd@any.com.ru COMMENT= Tools for manipulating HDR images and video frames LICENSE= LGPL21 RUN_DEPENDS+= bash:shells/bash PFS_BUILD= ${MACHINE_ARCH}-portbld-freebsd${OSREL} PLIST_SUB+= PFS_BASE=${PREFIX} USES= gmake libtool pathfix pkgconfig GNU_CONFIGURE= yes CONFIGURE_TARGET= ${PFS_BUILD} CONFIGURE_ARGS+= --disable-jpeghdr --disable-matlab \ --with-bash=${LOCALBASE}/bin/bash CPPFLAGS+= -I${LOCALBASE}/include LDFLAGS+= -L${LOCALBASE}/lib USE_LDCONFIG= yes OPTIONS_DEFINE= NETPBM OPENEXR TIFF QT IMAGEMAGICK GDAL OCTAVE OPENGL QT_DESC= Compile programs that use QT library GDAL_DESC= Compile programs that use GDAL library OCTAVE_DESC= Compile octave interface functions OPTIONS_DEFAULT= TIFF OPTIONS_SUB= yes NETPBM_CONFIGURE_ENABLE= netpbm NETPBM_LIB_DEPENDS= libnetpbm.so:graphics/netpbm OPENEXR_CONFIGURE_ENABLE= openexr OPENEXR_CONFIGURE_ON= --with-exrdir=${LOCALBASE}/include/OpenEXR OPENEXR_LIB_DEPENDS= libIlmImf.so:graphics/OpenEXR TIFF_CONFIGURE_ENABLE= tiff TIFF_LIB_DEPENDS= libtiff.so:graphics/tiff QT_CONFIGURE_ENABLE= qt QT_USE= QT4=moc_build,corelib,gui IMAGEMAGICK_CONFIGURE_ENABLE= imagemagick IMAGEMAGICK_LIB_DEPENDS= libMagick++-6.so:graphics/ImageMagick GDAL_CONFIGURE_ENABLE= gdal GDAL_LIB_DEPENDS= libgdal.so:graphics/gdal OPENGL_CONFIGURE_ENABLE= opengl OPENGL_USE= GL=glut OCTAVE_CONFIGURE_ENABLE= octave OCTAVE_PATCH_DEPENDS= octave-config:math/octave OCTAVE_BUILD_DEPENDS= mkoctfile:math/octave OCTAVE_RUN_DEPENDS= octave:math/octave +OCTAVE_USES= shebangfix .include .if ${PORT_OPTIONS:MOCTAVE} OCTAVE_BASE?= ${LOCALBASE} OCTAVE_VERSION!=${OCTAVE_BASE}/bin/octave-config -v 2>&1 || ${ECHO} "0" OCTAVE_SITE_OCT!=${OCTAVE_BASE}/bin/octave-config --oct-site-dir 2>&1 || ${ECHO} "" OCTAVE_SITE_M!= ${OCTAVE_BASE}/bin/octave-config --m-site-dir 2>&1 || ${ECHO} "" PLIST_SUB+= \ OCTAVE_BASE=${OCTAVE_BASE} \ OCTAVE_SITE_M=${OCTAVE_SITE_M:S|^${OCTAVE_BASE}/||} \ OCTAVE_SITE_OCT=${OCTAVE_SITE_OCT:S|^${OCTAVE_BASE}/||} -USES+= shebangfix SHEBANG_FILES= src/octave/* SHEBANG_LANG+= octave octave_OLD_CMD?=/usr/bin/octave octave_CMD?= ${OCTAVE_BASE}/bin/octave .endif post-install: ${STRIP_CMD} ${STAGEDIR}${PREFIX}/lib//libpfs-1.2.so.0.0.0 .include Index: head/graphics/pfstools/files/patch-src-filter-pfswb.cpp =================================================================== --- head/graphics/pfstools/files/patch-src-filter-pfswb.cpp (revision 445721) +++ head/graphics/pfstools/files/patch-src-filter-pfswb.cpp (revision 445722) @@ -1,300 +1,302 @@ ---- src/filter/pfswb.cpp.orig 2016-02-12 17:10:27 UTC +--- src/filter/pfswb.cpp.orig 2016-08-12 19:10:44 UTC +++ src/filter/pfswb.cpp -@@ -0,0 +1,297 @@ +@@ -0,0 +1,299 @@ +/** + * @file pfswb.cpp + * @brief Adjust white balance in RGB color space + * + * This file is a part of PFSTOOLS package. + * ---------------------------------------------------------------------- + * Copyright (C) 2008 Iouri V. Ivliev + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * ---------------------------------------------------------------------- + * + * @author Iouri V. Ivliev + * + * $Id: $ + */ + +#include + +#include +#include +#include +#include +#include + +#include + +#define PROG_NAME "pfswb" + +class QuietException +{ +}; + +static void printHelp() +{ + std::cerr << PROG_NAME " (" PACKAGE_STRING ") :\n" + "\t[--red ] [--green ] [--blue ]\n" + "\t[--auto] [--x ] [--y ] [--width ] [--height ]\n" + "\t[--keep-lum]\n" + "\t[--verbose] [--help]\n" + "See man page for more information.\n"; +} + +// verbose mode +static bool verbose = false; + +// auto WB +static bool autowb = false; +// default gray box bounds +static int x = 0; +static int y = 0; +static int width = INT_MAX/2; +static int height = INT_MAX/2; + +// keep original luminance +static bool keep = false; + +// default WB multipliers +static float red = 1.f; +static float green = 1.f; +static float blue = 1.f; + +static void multipliers( + const pfs::Array2D &R, const pfs::Array2D &G, const pfs::Array2D &B, + float &r, float &g, float &b) +{ + r = red; + g = green; + b = blue; + if (!autowb) return; + // auto WB gray box + int w = R.getCols(); + int h = R.getRows(); + if (x>=w || y>=h) + throw pfs::Exception("gray box is out of frame bounds"); + int x1 = width+x; + if (x1>w) x1 = w; + int y1 = height+y; + if (y1>h) y1 = h; + VERBOSE_STR + << "auto WB gray box: " + << (x1-x) << "x" << (y1-y) << "+" << x << "+" << y << std::endl; + // auto WB multipliers + double ar = 0.; + double ag = 0.; + double ab = 0.; + for (int y0=y; y0getXYZChannels(X, Y, Z); + if (!(Y && X && Z)) + { + throw pfs::Exception( "Missing X, Y, Z channels in the PFS stream" ); + } + int w = Y->getCols(); + int h = Y->getRows(); + int s = w*h; + float min = 1e20, max = -1e20; + for (int i=s; i--; ) + { + float const &l = (*Y)(i); + if (min > l) min = l; + if (max < l) max = l; + } + VERBOSE_STR << "luminance range of original frame: " << min << ":" << max << std::endl; + // Convert from XYZ to RGB + pfs::transformColorSpace(pfs::CS_XYZ, X, Y, Z, pfs::CS_RGB, X, Y, Z); + // WB adjustment + float r, g, b; + multipliers(*X,*Y,*Z,r,g,b); + VERBOSE_STR << "red multiplier value: " << r << std::endl; + VERBOSE_STR << "green multiplier value: " << g << std::endl; + VERBOSE_STR << "blue multiplier value: " << b << std::endl; + for (int i=s; i--; ) + { + (*X)(i) *= r; + (*Y)(i) *= g; + (*Z)(i) *= b; + } + // Convert back to XYZ + pfs::transformColorSpace(pfs::CS_RGB, X, Y, Z, pfs::CS_XYZ, X, Y, Z); + float amin = 1e20, amax = -1e20; + for (int i=s; i--; ) + { + float const &l = (*Y)(i); + if (amin > l) amin = l; + if (amax < l) amax = l; + } + VERBOSE_STR << "luminance range of adjusted frame: " << amin << ":" << amax << std::endl; + if (keep) + { + float k = (max-min)/(amax-amin); + float nmin = 1e20, nmax = -1e20; + for (int i=s; i--; ) + { -+ float const &l = ((*Y)(i)-amin)*k+min; ++ float const l = ((*Y)(i)-amin)*k+min; + if (nmin > l) nmin = l; + if (nmax < l) nmax = l; + (*Y)(i) = l; ++ (*X)(i) *= k; ++ (*Z)(i) *= k; + } + VERBOSE_STR << "restored luminance range: " << nmin << ":" << nmax << std::endl; + } + // Write frame + pfsio.writeFrame(frame, stdout); + pfsio.freeFrame(frame); + } +} + +int main(int argc, char *const argv[]) +{ + static const struct option cmdLineOptions[] = { + { "help", no_argument, NULL, 'h' }, + { "verbose", no_argument, NULL, 'v' }, + { "auto", no_argument, NULL, 'A' }, + { "x", required_argument, NULL, 'X' }, + { "y", required_argument, NULL, 'Y' }, + { "width", required_argument, NULL, 'W' }, + { "height", required_argument, NULL, 'H' }, + { "keep-lum", no_argument, NULL, 'k' }, + { "red", required_argument, NULL, 'r' }, + { "green", required_argument, NULL, 'g' }, + { "blue", required_argument, NULL, 'b' }, + { NULL, 0, NULL, 0 } + }; + + try + { + int optionIndex = 0; + while (true) + { + int c = getopt_long(argc, argv, "hvAX:Y:W:H:kr:g:b:", cmdLineOptions, &optionIndex); + if (c == -1) + { + break; + } + switch (c) + { + case 'h': + printHelp(); + throw QuietException(); + case 'v': + verbose = true; + break; + case 'A': + autowb = true; + break; + case 'X': + x = (int)strtol(optarg, NULL, 10); + if (x<=0) + throw pfs::Exception("gray box x value out of range, should be >0"); + break; + case 'Y': + y = (int)strtol(optarg, NULL, 10); + if (y<=0) + throw pfs::Exception("gray box y value out of range, should be >0"); + break; + case 'W': + width = (int)strtol(optarg, NULL, 10); + if (width<=0) + throw pfs::Exception("gray box width value out of range, should be >0"); + break; + case 'H': + height = (int)strtol(optarg, NULL, 10); + if (height<=0) + throw pfs::Exception("gray box height value out of range, should be >0"); + break; + case 'k': + keep = true; + break; + case 'r': + red = strtof(optarg, NULL); + if (red<=0.0f) + throw pfs::Exception("red multiplier value out of range, should be >0"); + break; + case 'g': + green = strtof(optarg, NULL); + if (green<=0.0f) + throw pfs::Exception("green multiplier value out of range, should be >0"); + break; + case 'b': + blue = strtof(optarg, NULL); + if (blue<=0.0f) + throw pfs::Exception("blue multiplier value out of range, should be >0"); + break; + case '?': + throw QuietException(); + case ':': + throw QuietException(); + } + } + + pfswb(); + } + catch (std::exception ex) + { + std::cerr << PROG_NAME" std error: " << ex.what() << std::endl; + return EXIT_FAILURE; + } + catch (pfs::Exception ex) + { + std::cerr << PROG_NAME" error: " << ex.getMessage() << std::endl; + return EXIT_FAILURE; + } + catch (QuietException ex) + { + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} Index: head/graphics/pfstools/files/patch-src-pfs-pfs.h =================================================================== --- head/graphics/pfstools/files/patch-src-pfs-pfs.h (revision 445721) +++ head/graphics/pfstools/files/patch-src-pfs-pfs.h (revision 445722) @@ -1,45 +1,54 @@ --- src/pfs/pfs.h.orig 2006-03-01 17:21:16 UTC +++ src/pfs/pfs.h @@ -115,6 +115,7 @@ namespace pfs class TagIterator { public: + virtual ~TagIterator() {}; /** * Get next item on the list. * @@ -135,6 +136,7 @@ namespace pfs class TagContainer { public: + virtual ~TagContainer() {}; /** * Get a string tag of the name tagName from the TagContainer. * @param tagName name of the tag to retrieve @@ -181,6 +183,7 @@ namespace pfs */ class Channel : public Array2D { public: + virtual ~Channel() {}; /** * Gets width of the channel (in pixels). * This is a synonym for Array2D::getCols(). @@ -226,6 +229,7 @@ namespace pfs class ChannelIterator { public: + virtual ~ChannelIterator() {}; /** * Get next item on the list. */ @@ -580,7 +584,9 @@ namespace pfs */ Exception( const char* const message ) { - strcpy( msg, message ); + const size_t s = sizeof(msg)/sizeof(msg[0]) - 1; + strncpy( msg, message, s ); + msg[s] = '\0'; } ~Exception() {}; +@@ -590,7 +596,7 @@ namespace pfs + * + * @return text description of the cause for the exception + */ +- const char* getMessage() ++ const char* getMessage() const + { + return msg; + }