From bbdda153fee304e1ae9ef3b0e371329ec9a7b65a Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Sun, 26 Sep 2010 21:00:07 +0300 Subject: [PATCH] Resize algorithm tester Add program to test resizer results on static images. Makes much easier to debug resizers. --- streamtools/Makefile | 5 ++- streamtools/testresizer.cpp | 101 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 streamtools/testresizer.cpp diff --git a/streamtools/Makefile b/streamtools/Makefile index e125797..905fd51 100644 --- a/streamtools/Makefile +++ b/streamtools/Makefile @@ -1,4 +1,4 @@ -all: screenshot.exe dumppackets.exe picturestodump.exe audiotodump.exe demuxdump.exe muxdump.exe mknulldump.exe cutdump.exe fmtopcm.exe playdump.exe dumpconvert.exe guessresolution.exe +all: screenshot.exe dumppackets.exe picturestodump.exe audiotodump.exe demuxdump.exe muxdump.exe mknulldump.exe cutdump.exe fmtopcm.exe playdump.exe dumpconvert.exe guessresolution.exe testresizer.exe CXXFLAGS2=-g -O2 -Wall -fopenmp CXXFLAGS=$(CXXFLAGS2) @@ -58,3 +58,6 @@ dumpconvert.exe: dumpconvert.o $(OUTPUT_DRIVERS) packet-processor.o resampler.o opl.o: opl.cpp opl.h g++ $(CXXFLAGS2) -DINLINE=inline -DOPLTYPE_IS_OPL3 -DOPL_CPP -c -o $@ $< + +testresizer.exe: testresizer.o $(RESIZE_DRIVERS) + g++ $(CXXFLAGS2) -o $@ $^ -lz `sdl-config --libs` -lSDL_image $(LIBS) diff --git a/streamtools/testresizer.cpp b/streamtools/testresizer.cpp new file mode 100644 index 0000000..2e260fa --- /dev/null +++ b/streamtools/testresizer.cpp @@ -0,0 +1,101 @@ +#include "SDL_image.h" +#include "SDL.h" +#include "resize.hpp" +#include +#include +#include +#include +#include +#include +#include "newpacket.hpp" +#include + +int main(int argc, char** argv) +{ + if(argc < 5) { + std::cerr << "Syntax: testresizer.exe " << std::endl; + exit(1); + } + + char* ptr1; + char* ptr2; + unsigned twidth = strtoul(argv[3], &ptr1, 10); + unsigned theight = strtoul(argv[4], &ptr2, 10); + if(!twidth || !theight || *ptr1 || *ptr2) { + std::cerr << "Error: Bad target size." << std::endl; + exit(1); + } + + + //Load the image. + SDL_Surface* img = IMG_Load(argv[1]); + if(!img) { + std::cerr << "Can't load image '" << argv[1] << "':" << IMG_GetError() << std::endl; + exit(2); + } + + //Convert the SDL surface into raw image. + unsigned width = img->w; + unsigned height = img->h; + image_frame_rgbx src(width, height); + unsigned char* pixels = src.get_pixels(); + SDL_LockSurface(img); + for(uint32_t y = 0; y < height; y++) + for(uint32_t x = 0; x < width; x++) { + Uint8 r, g, b; + size_t addr = y * img->pitch + x * img->format->BytesPerPixel; + SDL_GetRGB(*(Uint32*)((unsigned char*)img->pixels + addr), img->format, &r, &g, &b); + pixels[4 * width * y + 4 * x + 0] = r; + pixels[4 * width * y + 4 * x + 1] = g; + pixels[4 * width * y + 4 * x + 2] = b; + pixels[4 * width * y + 4 * x + 3] = 0; + } + SDL_UnlockSurface(img); + SDL_FreeSurface(img); + + resizer& r = resizer_factory::make_by_type(argv[2]); + image_frame_rgbx& dest = src.resize(twidth, theight, r); + + //Now, display the image. + SDL_Surface* swsurf = NULL; + SDL_Surface* hwsurf = NULL; + + if(SDL_Init(SDL_INIT_VIDEO) < 0) { + std::cerr << "Can't Initialize SDL." << std::endl; + exit(2); + } + +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + uint32_t rmask = 0xFF000000; + uint32_t gmask = 0x00FF0000; + uint32_t bmask = 0x0000FF00; +#else + uint32_t rmask = 0x000000FF; + uint32_t gmask = 0x0000FF00; + uint32_t bmask = 0x00FF0000; +#endif + + hwsurf = SDL_SetVideoMode(dest.get_width(), dest.get_height(), 0, SDL_SWSURFACE | + SDL_DOUBLEBUF | SDL_ANYFORMAT); + swsurf = SDL_CreateRGBSurface(SDL_SWSURFACE, dest.get_width(), dest.get_height(), 32, + rmask, gmask, bmask, 0); + if(!swsurf || !hwsurf) { + std::cerr << "Can't Set video mode." << std::endl; + exit(2); + } + + //Copy the picture to surface. + SDL_LockSurface(swsurf); + memcpy((unsigned char*)swsurf->pixels, dest.get_pixels(), 4 * twidth * theight); + SDL_UnlockSurface(swsurf); + + //Render and wait. + SDL_BlitSurface(swsurf, NULL, hwsurf, NULL); + SDL_Flip(hwsurf); + SDL_Event e; + while(SDL_PollEvent(&e) != 1 || e.type != SDL_QUIT); + + if(&dest != &src) + delete &dest; + return 0; +} -- 2.11.4.GIT