Add gnome thumbnailer by Frank Richter. Fixes issue 82.
This commit is contained in:
parent
69c74d7a5e
commit
9d5242594b
@ -88,6 +88,19 @@ TARGET_LINK_LIBRARIES(nvzoom nvcore nvmath nvimage)
|
||||
|
||||
INSTALL(TARGETS nvcompress nvdecompress nvddsinfo nvimgdiff nvassemble nvzoom nvtestsuite DESTINATION bin)
|
||||
|
||||
ADD_EXECUTABLE(nv-gnome-thumbnailer tools/thumbnailer.cpp tools/cmdline.h)
|
||||
TARGET_LINK_LIBRARIES(nv-gnome-thumbnailer nvcore nvmath nvimage)
|
||||
|
||||
INSTALL(TARGETS nvcompress nvdecompress nvddsinfo nvimgdiff nvassemble nvzoom nvtestsuite nv-gnome-thumbnailer DESTINATION bin)
|
||||
|
||||
IF(GCONFTOOL2)
|
||||
INSTALL(CODE "MESSAGE(STATUS \"Installing thumbnailer schema\")")
|
||||
#gconftool-2 --get-default-source
|
||||
INSTALL(CODE "EXECUTE_PROCESS(COMMAND ${GCONFTOOL2} --get-default-source OUTPUT_VARIABLE GCONF_CONFIG_SOURCE OUTPUT_STRIP_TRAILING_WHITESPACE)")
|
||||
INSTALL(CODE "set(ENV{GCONF_CONFIG_SOURCE} \"\${GCONF_CONFIG_SOURCE}\")")
|
||||
INSTALL(CODE "EXECUTE_PROCESS(COMMAND ${GCONFTOOL2} --makefile-install-rule ${CMAKE_CURRENT_BINARY_DIR}/tools/nvtt-thumbnailer.schema)")
|
||||
ENDIF(GCONFTOOL2)
|
||||
|
||||
#include_directories("/usr/include/ffmpeg/")
|
||||
#ADD_EXECUTABLE(nvmpegenc tools/mpegenc.cpp tools/cmdline.h)
|
||||
#TARGET_LINK_LIBRARIES(nvmpegenc nvcore nvmath nvimage avcodec z)
|
||||
|
26
src/nvtt/tools/nvtt-thumbnailer.schema.in
Normal file
26
src/nvtt/tools/nvtt-thumbnailer.schema.in
Normal file
@ -0,0 +1,26 @@
|
||||
<gconfschemafile>
|
||||
<schemalist>
|
||||
<schema>
|
||||
<key>/schemas/desktop/gnome/thumbnailers/image@x-dds/enable</key>
|
||||
<applyto>/desktop/gnome/thumbnailers/image@x-dds/enable</applyto>
|
||||
<owner>nvtt-thumbnailer</owner>
|
||||
<type>bool</type>
|
||||
<default>true</default>
|
||||
<locale name="C">
|
||||
<short></short>
|
||||
<long></long>
|
||||
</locale>
|
||||
</schema>
|
||||
<schema>
|
||||
<key>/schemas/desktop/gnome/thumbnailers/image@x-dds/command</key>
|
||||
<applyto>/desktop/gnome/thumbnailers/image@x-dds/command</applyto>
|
||||
<owner>nvtt-thumbnailer</owner>
|
||||
<type>string</type>
|
||||
<default>@CMAKE_INSTALL_PREFIX@/bin/nv-gnome-thumbnailer -s %s %i %o</default>
|
||||
<locale name="C">
|
||||
<short></short>
|
||||
<long></long>
|
||||
</locale>
|
||||
</schema>
|
||||
</schemalist>
|
||||
</gconfschemafile>
|
158
src/nvtt/tools/thumbnailer.cpp
Normal file
158
src/nvtt/tools/thumbnailer.cpp
Normal file
@ -0,0 +1,158 @@
|
||||
// Copyright NVIDIA Corporation 2007 -- Ignacio Castano <icastano@nvidia.com>
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
#include <nvcore/Ptr.h>
|
||||
#include <nvcore/StrLib.h>
|
||||
#include <nvcore/StdStream.h>
|
||||
#include <nvcore/Containers.h>
|
||||
|
||||
#include <nvimage/Image.h>
|
||||
#include <nvimage/ImageIO.h>
|
||||
#include <nvimage/FloatImage.h>
|
||||
#include <nvimage/Filter.h>
|
||||
#include <nvimage/DirectDrawSurface.h>
|
||||
|
||||
#include <nvmath/Color.h>
|
||||
#include <nvmath/Vector.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "cmdline.h"
|
||||
|
||||
static bool loadImage(nv::Image & image, const char * fileName)
|
||||
{
|
||||
if (nv::strCaseCmp(nv::Path::extension(fileName), ".dds") == 0)
|
||||
{
|
||||
nv::DirectDrawSurface dds(fileName);
|
||||
if (!dds.isValid())
|
||||
{
|
||||
fprintf(stderr, "The file '%s' is not a valid DDS file.\n", fileName);
|
||||
return false;
|
||||
}
|
||||
|
||||
dds.mipmap(&image, 0, 0); // get first image
|
||||
}
|
||||
else
|
||||
{
|
||||
// Regular image.
|
||||
if (!image.load(fileName))
|
||||
{
|
||||
fprintf(stderr, "The file '%s' is not a supported image type.\n", fileName);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
//MyAssertHandler assertHandler;
|
||||
MyMessageHandler messageHandler;
|
||||
|
||||
float gamma = 2.2f;
|
||||
nv::Path input;
|
||||
nv::Path output;
|
||||
int size = 128;
|
||||
|
||||
// Parse arguments.
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
// Input options.
|
||||
if (strcmp("-s", argv[i]) == 0)
|
||||
{
|
||||
if (i+1 < argc && argv[i+1][0] != '-') {
|
||||
size = (int)atoi(argv[i+1]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else if (argv[i][0] != '-')
|
||||
{
|
||||
input = argv[i];
|
||||
|
||||
if (i+1 < argc && argv[i+1][0] != '-') {
|
||||
output = argv[i+1];
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "No output filename.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (input.isNull() || output.isNull())
|
||||
{
|
||||
printf("NVIDIA Texture Tools - Copyright NVIDIA Corporation 2007\n\n");
|
||||
|
||||
printf("usage: nv-gnome-thumbnailer [options] input output\n\n");
|
||||
|
||||
printf("Options:\n");
|
||||
printf(" -s size\tThumbnail size (default = 128)\n");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
nv::Image image;
|
||||
if (!loadImage(image, input)) return 1;
|
||||
|
||||
nv::ImageIO::PngCommentsMap pngComments;
|
||||
pngComments.add("Thumb::Image::Width", nv::StringBuilder().number (image.width()));
|
||||
pngComments.add("Thumb::Image::Height", nv::StringBuilder().number (image.height()));
|
||||
|
||||
if ((image.width() > size) || (image.height() > size))
|
||||
{
|
||||
nv::FloatImage fimage(&image);
|
||||
fimage.toLinear(0, 3, gamma);
|
||||
|
||||
uint thumbW, thumbH;
|
||||
if (image.width() > image.height())
|
||||
{
|
||||
thumbW = size;
|
||||
thumbH = uint ((float (image.height()) / float (image.width())) * size);
|
||||
}
|
||||
else
|
||||
{
|
||||
thumbW = uint ((float (image.width()) / float (image.height())) * size);
|
||||
thumbH = size;
|
||||
}
|
||||
nv::AutoPtr<nv::FloatImage> fresult(fimage.resize(nv::BoxFilter(), thumbW, thumbH, nv::FloatImage::WrapMode_Clamp));
|
||||
|
||||
nv::AutoPtr<nv::Image> result(fresult->createImageGammaCorrect(gamma));
|
||||
result->setFormat(nv::Image::Format_ARGB);
|
||||
|
||||
nv::StdOutputStream stream(output);
|
||||
nv::ImageIO::savePNG(stream, result.ptr(), pngComments);
|
||||
}
|
||||
else
|
||||
{
|
||||
nv::StdOutputStream stream(output);
|
||||
nv::ImageIO::savePNG(stream, &image, pngComments);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user