Commits
David B. Evans authored e6350b0ffd1
1 + | diff --git a/configure.in b/configure.ac |
2 + | similarity index 100% |
3 + | rename from configure.in |
4 + | rename to configure.ac |
5 + | diff --git a/examples/Makefile.am b/examples/Makefile.am |
6 + | index e177746..06aa524 100644 |
7 + | --- examples/Makefile.am |
8 + | +++ examples/Makefile.am |
9 + | |
10 + | ppmflip chromatest dynarray symmatrix \ |
11 + | $(linuxprogs) $(audioprogs) $(x11progs) # ppm2avi smartpointer |
12 + | |
13 + | -INCLUDES = -I.. |
14 + | +AM_CPPFLAGS = -I.. |
15 + | |
16 + | test_libvideogfx_DEPENDENCIES = ../libvideogfx/libvideogfx.la |
17 + | test_libvideogfx_CFLAGS = $(X_CFLAGS) |
18 + | diff --git a/examples/dynarray.cc b/examples/dynarray.cc |
19 + | index 623d97a..3d0d88b 100644 |
20 + | --- examples/dynarray.cc |
21 + | +++ examples/dynarray.cc |
22 + | |
23 + | cout << endl; |
24 + | } |
25 + | |
26 + | -main() |
27 + | +int main() |
28 + | { |
29 + | DynArray<int> dynarray; |
30 + | dynarray.SetEmptyValue(-1); |
31 + | diff --git a/examples/symmatrix.cc b/examples/symmatrix.cc |
32 + | index d21ab51..0d06ea4 100644 |
33 + | --- examples/symmatrix.cc |
34 + | +++ examples/symmatrix.cc |
35 + | |
36 + | } |
37 + | } |
38 + | |
39 + | -main() |
40 + | +int main() |
41 + | { |
42 + | SymMatrix<int> m; |
43 + | m.Create(6); |
44 + | diff --git a/libvideogfx/Makefile.am b/libvideogfx/Makefile.am |
45 + | index dd37563..97dc5ce 100644 |
46 + | --- libvideogfx/Makefile.am |
47 + | +++ libvideogfx/Makefile.am |
48 + | |
49 + | |
50 + | DIST_SUBDIRS = arch audio utility graphics containers x11 |
51 + | |
52 + | -INCLUDES = \ |
53 + | +AM_CPPFLAGS = \ |
54 + | -DDATADIR=\"$(datadir)\" \ |
55 + | -DLIBDIR=\"$(libdir)\" \ |
56 + | -DSYSCONFDIR=\"$(sysconfdir)\" \ |
57 + | diff --git a/libvideogfx/arch/Makefile.am b/libvideogfx/arch/Makefile.am |
58 + | index c8df929..4244625 100644 |
59 + | --- libvideogfx/arch/Makefile.am |
60 + | +++ libvideogfx/arch/Makefile.am |
61 + | |
62 + | cpu.hh \ |
63 + | $(mmx_headers) |
64 + | |
65 + | -INCLUDES = \ |
66 + | +AM_CPPFLAGS = \ |
67 + | -I$(top_srcdir) |
68 + | diff --git a/libvideogfx/audio/fileio/Makefile.am b/libvideogfx/audio/fileio/Makefile.am |
69 + | index 815c628..f7fa586 100644 |
70 + | --- libvideogfx/audio/fileio/Makefile.am |
71 + | +++ libvideogfx/audio/fileio/Makefile.am |
72 + | |
73 + | timedsink.hh \ |
74 + | $(linux_headers) |
75 + | |
76 + | -INCLUDES = \ |
77 + | +AM_CPPFLAGS = \ |
78 + | -I$(top_srcdir) |
79 + | |
80 + | diff --git a/libvideogfx/containers/Makefile.am b/libvideogfx/containers/Makefile.am |
81 + | index 78adf30..e1282b2 100644 |
82 + | --- libvideogfx/containers/Makefile.am |
83 + | +++ libvideogfx/containers/Makefile.am |
84 + | |
85 + | |
86 + | noinst_LTLIBRARIES = libvideogfx-containers.la |
87 + | |
88 + | -libvideogfx_containers_includedir = $(includedir)/libvideogfx/containers |
89 + | +libvideogfx_containers_includedir = \ |
90 + | + $(includedir)/libvideogfx/containers |
91 + | + |
92 + | +libvideogfx_containers_la_SOURCES = \ |
93 + | + dummy.cc \ |
94 + | + heap.hh \ |
95 + | + heap.icc \ |
96 + | + dynarray.hh \ |
97 + | + array.hh \ |
98 + | + array.icc \ |
99 + | + array2.hh \ |
100 + | + array2.icc \ |
101 + | + symmatrix.hh \ |
102 + | + queue.hh \ |
103 + | + queue.icc |
104 + | |
105 + | # Header files for public installation (non-generated) |
106 + | libvideogfx_containers_include_HEADERS = \ |
107 + | |
108 + | queue.hh \ |
109 + | queue.icc |
110 + | |
111 + | -libvideogfx_containers_la_SOURCES = |
112 + | - |
113 + | -INCLUDES = \ |
114 + | +AM_CPPFLAGS = \ |
115 + | -I$(top_srcdir) |
116 + | - |
117 + | -.PHONY: files |
118 + | - |
119 + | -files: |
120 + | - @files=`ls $(DISTFILES) 2> /dev/null`; for p in $$files; do \ |
121 + | - echo $$p; \ |
122 + | - done |
123 + | diff --git a/libvideogfx/containers/dummy.cc b/libvideogfx/containers/dummy.cc |
124 + | new file mode 100644 |
125 + | index 0000000..5ca23f1 |
126 + | --- /dev/null |
127 + | +++ libvideogfx/containers/dummy.cc |
128 + | |
129 + | +/* A dummy file, to prevent empty libraries from breaking builds. |
130 + | + Copyright (C) 2004, 2007, 2009-2012 Free Software Foundation, Inc. |
131 + | + |
132 + | + Copying and distribution of this file, with or without |
133 + | + modification, are permitted in any medium without royalty |
134 + | + provided the copyright notice and this notice are preserved. */ |
135 + | + |
136 + | +/* Some systems, reportedly OpenBSD and Mac OS X, refuse to create |
137 + | + libraries without any object files. You might get an error like: |
138 + | + |
139 + | + > ar cru .libs/libgl.a |
140 + | + > ar: no archive members specified |
141 + | + |
142 + | + Compiling this file, and adding its object file to the library, will |
143 + | + prevent the library from being empty. */ |
144 + | + |
145 + | +/* Some systems, such as Solaris with cc 5.0, refuse to work with libraries |
146 + | + that don't export any symbol. You might get an error like: |
147 + | + |
148 + | + > cc ... libgnu.a |
149 + | + > ild: (bad file) garbled symbol table in archive ../gllib/libgnu.a |
150 + | + |
151 + | + Compiling this file, and adding its object file to the library, will |
152 + | + prevent the library from exporting no symbols. */ |
153 + | + |
154 + | +#ifdef __sun |
155 + | +/* This declaration ensures that the library will export at least 1 symbol. */ |
156 + | +int gl_dummy_symbol; |
157 + | +#else |
158 + | +/* This declaration is solely to ensure that after preprocessing |
159 + | + this file is never empty. */ |
160 + | +typedef int dummy; |
161 + | +#endif |
162 + | diff --git a/libvideogfx/graphics/color/Makefile.am b/libvideogfx/graphics/color/Makefile.am |
163 + | index 11c8846..bfe83a8 100644 |
164 + | --- libvideogfx/graphics/color/Makefile.am |
165 + | +++ libvideogfx/graphics/color/Makefile.am |
166 + | |
167 + | img2raw.hh \ |
168 + | colorspace.hh |
169 + | |
170 + | - |
171 + | -INCLUDES = \ |
172 + | +AM_CPPFLAGS = \ |
173 + | -I$(top_srcdir) |
174 + | diff --git a/libvideogfx/graphics/datatypes/Makefile.am b/libvideogfx/graphics/datatypes/Makefile.am |
175 + | index 7edf956..30364d5 100644 |
176 + | --- libvideogfx/graphics/datatypes/Makefile.am |
177 + | +++ libvideogfx/graphics/datatypes/Makefile.am |
178 + | |
179 + | bitmap.hh \ |
180 + | image.hh |
181 + | |
182 + | -INCLUDES = \ |
183 + | +AM_CPPFLAGS = \ |
184 + | -I$(top_srcdir) |
185 + | diff --git a/libvideogfx/graphics/draw/Makefile.am b/libvideogfx/graphics/draw/Makefile.am |
186 + | index aaa4d66..2b61035 100644 |
187 + | --- libvideogfx/graphics/draw/Makefile.am |
188 + | +++ libvideogfx/graphics/draw/Makefile.am |
189 + | |
190 + | blit.hh \ |
191 + | scale.hh |
192 + | |
193 + | -INCLUDES = \ |
194 + | +AM_CPPFLAGS = \ |
195 + | -I$(top_srcdir) |
196 + | diff --git a/libvideogfx/graphics/fileio/Makefile.am b/libvideogfx/graphics/fileio/Makefile.am |
197 + | index 78fb782..27d094e 100644 |
198 + | --- libvideogfx/graphics/fileio/Makefile.am |
199 + | +++ libvideogfx/graphics/fileio/Makefile.am |
200 + | |
201 + | $(linux_headers) \ |
202 + | $(ffmpeg_headers) |
203 + | |
204 + | -INCLUDES = \ |
205 + | +AM_CPPFLAGS = \ |
206 + | -I$(top_srcdir) |
207 + | |
208 + | diff --git a/libvideogfx/graphics/fileio/ffmpeg.cc b/libvideogfx/graphics/fileio/ffmpeg.cc |
209 + | index 6b0a76e..42034b6 100644 |
210 + | --- libvideogfx/graphics/fileio/ffmpeg.cc |
211 + | +++ libvideogfx/graphics/fileio/ffmpeg.cc |
212 + | |
213 + | if (frameRGB) { av_free(frameRGB); frameRGB=NULL; } |
214 + | if (frame) { av_free(frame); frame=NULL; } |
215 + | if (codecCtx) { avcodec_close(codecCtx); codecCtx=NULL; } |
216 + | - if (formatCtx) { av_close_input_file(formatCtx); formatCtx=NULL; } |
217 + | + if (formatCtx) { avformat_close_input(&formatCtx); formatCtx=NULL; } |
218 + | } |
219 + | |
220 + | |
221 + | diff --git a/libvideogfx/graphics/fileio/imagesink.hh b/libvideogfx/graphics/fileio/imagesink.hh |
222 + | index 915b597..bdc9e9f 100644 |
223 + | --- libvideogfx/graphics/fileio/imagesink.hh |
224 + | +++ libvideogfx/graphics/fileio/imagesink.hh |
225 + | |
226 + | ********************************************************************************/ |
227 + | |
228 + | #ifndef LIBVIDEOGFX_GRAPHICS_FILEIO_IMAGESINK_HH |
229 + | -#define LIBVIDEOGFX_GRAPHICS_FILEIO_IMGAESINK_HH |
230 + | +#define LIBVIDEOGFX_GRAPHICS_FILEIO_IMAGESINK_HH |
231 + | |
232 + | #include <libvideogfx/graphics/datatypes/image.hh> |
233 + | |
234 + | diff --git a/libvideogfx/graphics/fileio/jpeg.cc b/libvideogfx/graphics/fileio/jpeg.cc |
235 + | index 1e0e557..25d0187 100644 |
236 + | --- libvideogfx/graphics/fileio/jpeg.cc |
237 + | +++ libvideogfx/graphics/fileio/jpeg.cc |
238 + | |
239 + | // initialize decompressor |
240 + | |
241 + | jpeg_create_decompress(&cinfo); |
242 + | - |
243 + | + |
244 + | cinfo.err = jpeg_std_error(&jerr); |
245 + | jpeg_stdio_src(&cinfo, infile); |
246 + | |
247 + | |
248 + | py [cinfo.output_scanline-1][x] = *bufp++; |
249 + | pcb[(cinfo.output_scanline-1)/2][x/2] = *bufp++; |
250 + | pcr[(cinfo.output_scanline-1)/2][x/2] = *bufp++; |
251 + | - py [cinfo.output_scanline-1][x+1] = *bufp++; |
252 + | + |
253 + | + if (x+1 < cinfo.output_width) { |
254 + | + py [cinfo.output_scanline-1][x+1] = *bufp++; |
255 + | + } |
256 + | + |
257 + | bufp+=2; |
258 + | } |
259 + | |
260 + | |
261 + | - (void) jpeg_read_scanlines(&cinfo, buffer, 1); |
262 + | + if (cinfo.output_scanline < cinfo.output_height) { |
263 + | + (void) jpeg_read_scanlines(&cinfo, buffer, 1); |
264 + | |
265 + | - bufp = buffer[0]; |
266 + | + bufp = buffer[0]; |
267 + | |
268 + | - for (unsigned int x=0;x<cinfo.output_width;x++) |
269 + | - { |
270 + | - py [cinfo.output_scanline-1][x] = *bufp++; |
271 + | - bufp+=2; |
272 + | - } |
273 + | + for (unsigned int x=0;x<cinfo.output_width;x++) |
274 + | + { |
275 + | + py [cinfo.output_scanline-1][x] = *bufp++; |
276 + | + bufp+=2; |
277 + | + } |
278 + | + } |
279 + | } |
280 + | } |
281 + | |
282 + | |
283 + | // open output file |
284 + | |
285 + | FILE * outfile; |
286 + | - if ((outfile = fopen(filename, "wb")) == NULL) { |
287 + | - fprintf(stderr, "can't open %s\n", filename); |
288 + | - exit(1); |
289 + | + |
290 + | + if (filename==nullptr) { |
291 + | + outfile = stdout; |
292 + | + } |
293 + | + else { |
294 + | + if ((outfile = fopen(filename, "wb")) == NULL) { |
295 + | + fprintf(stderr, "can't open %s\n", filename); |
296 + | + exit(1); |
297 + | + } |
298 + | } |
299 + | |
300 + | |
301 + | |
302 + | } |
303 + | |
304 + | // cleanup |
305 + | - |
306 + | + |
307 + | jpeg_finish_compress(&cinfo); |
308 + | jpeg_destroy_compress(&cinfo); |
309 + | - |
310 + | - fclose(outfile); |
311 + | + |
312 + | + if (filename != nullptr) { |
313 + | + fclose(outfile); |
314 + | + } |
315 + | } |
316 + | #endif |
317 + | } |
318 + | diff --git a/libvideogfx/graphics/fileio/png.cc b/libvideogfx/graphics/fileio/png.cc |
319 + | index 417d43e..52d66c0 100644 |
320 + | --- libvideogfx/graphics/fileio/png.cc |
321 + | +++ libvideogfx/graphics/fileio/png.cc |
322 + | |
323 + | |
324 + | void ReadImage_PNG(Image<Pixel>& img, istream& is) |
325 + | { |
326 + | - assert(is != NULL); // , "Open stream first."); |
327 + | + assert(is.good()); // , "Open stream first."); |
328 + | |
329 + | png_structp png_ptr; |
330 + | png_infop info_ptr; |
331 + | |
332 + | &interlace_type, NULL, NULL); |
333 + | |
334 + | assert(bit_depth < 16); // , "cannot handle 16 bit images"); |
335 + | - |
336 + | + |
337 + | /**** Set up the data transformations you want. Note that these are all |
338 + | **** optional. Only call them if you want/need them. Many of the |
339 + | **** transformations only work on specific types of images, and many |
340 + | |
341 + | |
342 + | delete[] row_pointers; |
343 + | } |
344 + | - |
345 + | + |
346 + | void WriteImage_PNG(ostream& os, const Image<Pixel>& img) |
347 + | { |
348 + | /* Create and initialize the png_struct with the desired error handler |
349 + | |
350 + | } |
351 + | } |
352 + | } |
353 + | - |
354 + | - |
355 + | + |
356 + | + |
357 + | png_write_image(png_ptr, row_pointers); |
358 + | |
359 + | /* It is REQUIRED to call this to finish writing the rest of the file */ |
360 + | diff --git a/libvideogfx/graphics/filters/Makefile.am b/libvideogfx/graphics/filters/Makefile.am |
361 + | index 7eba05e..6bd69b6 100644 |
362 + | --- libvideogfx/graphics/filters/Makefile.am |
363 + | +++ libvideogfx/graphics/filters/Makefile.am |
364 + | |
365 + | resampler.h \ |
366 + | $(mmx_headers) |
367 + | |
368 + | -INCLUDES = \ |
369 + | +AM_CPPFLAGS = \ |
370 + | -I$(top_srcdir) |
371 + | diff --git a/libvideogfx/graphics/geometry/Makefile.am b/libvideogfx/graphics/geometry/Makefile.am |
372 + | index c555cac..b0cb546 100644 |
373 + | --- libvideogfx/graphics/geometry/Makefile.am |
374 + | +++ libvideogfx/graphics/geometry/Makefile.am |
375 + | |
376 + | matrix.hh \ |
377 + | transform.hh |
378 + | |
379 + | -INCLUDES = \ |
380 + | +AM_CPPFLAGS = \ |
381 + | -I$(top_srcdir) |
382 + | diff --git a/libvideogfx/graphics/measure/Makefile.am b/libvideogfx/graphics/measure/Makefile.am |
383 + | index c5201ff..21f72c1 100644 |
384 + | --- libvideogfx/graphics/measure/Makefile.am |
385 + | +++ libvideogfx/graphics/measure/Makefile.am |
386 + | |
387 + | noinst_LTLIBRARIES = libvideogfx-graphics-measure.la |
388 + | |
389 + | libvideogfx_graphics_measure_la_SOURCES = \ |
390 + | - snr.hh \ |
391 + | - snr.cc |
392 + | + snr.hh snr.cc \ |
393 + | + ssim.hh ssim.cc |
394 + | |
395 + | libvideogfx_graphics_measure_includedir = \ |
396 + | $(includedir)/libvideogfx/graphics/measure |
397 + | |
398 + | libvideogfx_graphics_measure_include_HEADERS = \ |
399 + | - snr.hh |
400 + | + snr.hh ssim.hh |
401 + | |
402 + | -INCLUDES = \ |
403 + | +AM_CPPFLAGS = \ |
404 + | -I$(top_srcdir) |
405 + | diff --git a/libvideogfx/graphics/measure/snr.cc b/libvideogfx/graphics/measure/snr.cc |
406 + | index 9400734..e7a5aab 100644 |
407 + | --- libvideogfx/graphics/measure/snr.cc |
408 + | +++ libvideogfx/graphics/measure/snr.cc |
409 + | |
410 + | return psnr; |
411 + | } |
412 + | |
413 + | + |
414 + | + Bitmap<Pixel> CalcErrorMap(const Bitmap<Pixel>& img1, |
415 + | + const Bitmap<Pixel>& img2, |
416 + | + enum TransferCurve transfer_curve, |
417 + | + bool inverted) |
418 + | + { |
419 + | + int w = img1.AskWidth(); |
420 + | + int h = img1.AskHeight(); |
421 + | + |
422 + | + const Pixel*const* p1 = img1.AskFrame(); |
423 + | + const Pixel*const* p2 = img2.AskFrame(); |
424 + | + |
425 + | + Bitmap<Pixel> error; |
426 + | + error.Create(w,h); |
427 + | + |
428 + | + Pixel*const* p = error.AskFrame(); |
429 + | + |
430 + | + |
431 + | + // --- prepare transfer curve --- |
432 + | + |
433 + | + Pixel transfer[255+1+255]; |
434 + | + for (int d=-255;d<=255;d++) |
435 + | + { |
436 + | + switch (transfer_curve) |
437 + | + { |
438 + | + case TransferCurve_Linear: |
439 + | + transfer[d+255] = abs(d); |
440 + | + break; |
441 + | + |
442 + | + case TransferCurve_Sqrt: |
443 + | + transfer[d+255] = sqrt(abs(d)/255.0)*255; |
444 + | + break; |
445 + | + } |
446 + | + |
447 + | + if (inverted) transfer[d+255] = 255 - transfer[d+255]; |
448 + | + } |
449 + | + |
450 + | + |
451 + | + // --- generate error map --- |
452 + | + |
453 + | + for (int y=0;y<h;y++) |
454 + | + for (int x=0;x<w;x++) |
455 + | + { |
456 + | + p[y][x] = transfer[p1[y][x] - p2[y][x] + 255]; |
457 + | + } |
458 + | + |
459 + | + return error; |
460 + | + } |
461 + | } |
462 + | diff --git a/libvideogfx/graphics/measure/snr.hh b/libvideogfx/graphics/measure/snr.hh |
463 + | index 20d26f2..6f2ffe2 100644 |
464 + | --- libvideogfx/graphics/measure/snr.hh |
465 + | +++ libvideogfx/graphics/measure/snr.hh |
466 + | |
467 + | int x0= 0,int y0=0, // rectangle to consider for the calculation |
468 + | int x1=-1,int y1=-1); |
469 + | |
470 + | + enum TransferCurve |
471 + | + { |
472 + | + TransferCurve_Linear, |
473 + | + TransferCurve_Sqrt |
474 + | + }; |
475 + | + |
476 + | + Bitmap<Pixel> CalcErrorMap(const Bitmap<Pixel>& img1, |
477 + | + const Bitmap<Pixel>& img2, |
478 + | + enum TransferCurve transfer=TransferCurve_Linear, |
479 + | + bool inverted=true); |
480 + | } |
481 + | |
482 + | |
483 + | diff --git a/libvideogfx/graphics/measure/ssim.cc b/libvideogfx/graphics/measure/ssim.cc |
484 + | new file mode 100644 |
485 + | index 0000000..45c9fcb |
486 + | --- /dev/null |
487 + | +++ libvideogfx/graphics/measure/ssim.cc |
488 + | |
489 + | +/******************************************************************************** |
490 + | + LibVideoGfx - video processing library |
491 + | + Copyright (C) 2002-2014 Dirk Farin |
492 + | + |
493 + | + This library is free software; you can redistribute it and/or |
494 + | + modify it under the terms of the GNU Lesser General Public |
495 + | + License as published by the Free Software Foundation; either |
496 + | + version 2.1 of the License, or (at your option) any later version. |
497 + | + |
498 + | + This library is distributed in the hope that it will be useful, |
499 + | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
500 + | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
501 + | + Lesser General Public License for more details. |
502 + | + |
503 + | + You should have received a copy of the GNU Lesser General Public |
504 + | + License along with this library; if not, write to the Free Software |
505 + | + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
506 + | + ********************************************************************************/ |
507 + | + |
508 + | +#include "libvideogfx/graphics/measure/ssim.hh" |
509 + | +#include "libvideogfx/graphics/filters/linear.hh" |
510 + | +#include "libvideogfx/containers/array.hh" |
511 + | + |
512 + | +#include <math.h> |
513 + | +#include <algorithm> |
514 + | +using namespace std; |
515 + | + |
516 + | + |
517 + | +namespace videogfx { |
518 + | + |
519 + | + template <class T> T SQ(T t) { return t*t; } |
520 + | + |
521 + | + |
522 + | + Bitmap<float> SSIM::calcSSIM(const Bitmap<Pixel>& img_x, |
523 + | + const Bitmap<Pixel>& img_y) |
524 + | + { |
525 + | + int w = img_x.AskWidth(); |
526 + | + int h = img_y.AskHeight(); |
527 + | + |
528 + | + Array<double> filter; |
529 + | + CreateGaussFilter(filter, sigma, 0.01); |
530 + | + |
531 + | + Bitmap<float> mean_x, mean_y; |
532 + | + ConvolveHV(mean_x,img_x, filter); |
533 + | + ConvolveHV(mean_y,img_y, filter); |
534 + | + |
535 + | + Bitmap<float> meandiff_x, meandiff_y; |
536 + | + meandiff_x.Create(w,h); |
537 + | + meandiff_y.Create(w,h); |
538 + | + |
539 + | + for (int y=0;y<h;y++) |
540 + | + for (int x=0;x<w;x++) { |
541 + | + meandiff_x[y][x] = SQ(mean_x[y][x] - img_x[y][x]); |
542 + | + meandiff_y[y][x] = SQ(mean_y[y][x] - img_y[y][x]); |
543 + | + } |
544 + | + |
545 + | + Bitmap<float> sigma_x, sigma_y; |
546 + | + ConvolveHV(sigma_x,meandiff_x, filter); |
547 + | + ConvolveHV(sigma_y,meandiff_y, filter); |
548 + | + |
549 + | + for (int y=0;y<h;y++) |
550 + | + for (int x=0;x<w;x++) { |
551 + | + sigma_x[y][x] = sqrt(sigma_x[y][x]); |
552 + | + sigma_y[y][x] = sqrt(sigma_y[y][x]); |
553 + | + } |
554 + | + |
555 + | + Bitmap<float> corr_tmp; |
556 + | + corr_tmp.Create(w,h); |
557 + | + for (int y=0;y<h;y++) |
558 + | + for (int x=0;x<w;x++) { |
559 + | + corr_tmp[y][x] = (img_x[y][x]-mean_x[y][x]) * (img_y[y][x]-mean_y[y][x]); |
560 + | + } |
561 + | + |
562 + | + Bitmap<float> corr; |
563 + | + ConvolveHV(corr, corr_tmp, filter); |
564 + | + |
565 + | + //return corr; |
566 + | + |
567 + | + Bitmap<float> ssim; |
568 + | + ssim.Create(w,h); |
569 + | + for (int y=0;y<h;y++) |
570 + | + for (int x=0;x<w;x++) { |
571 + | + float s = (2*mean_x[y][x]*mean_y[y][x] + C1) * (2*corr[y][x] + C2) / |
572 + | + ( (mean_x [y][x]*mean_x [y][x] + mean_y [y][x]*mean_y [y][x] + C1 ) * |
573 + | + (sigma_x[y][x]*sigma_x[y][x] + sigma_y[y][x]*sigma_y[y][x] + C2) ); |
574 + | + |
575 + | + if (s<0.0) s = 0.0; |
576 + | + if (s>1.0) s = 1.0; |
577 + | + |
578 + | + ssim[y][x] = s; |
579 + | + } |
580 + | + |
581 + | + return ssim; |
582 + | + } |
583 + | + |
584 + | + |
585 + | + |
586 + | + float SSIM::calcMSSIM(const Bitmap<Pixel>& img1, |
587 + | + const Bitmap<Pixel>& img2) |
588 + | + { |
589 + | + int w = img1.AskWidth(); |
590 + | + int h = img1.AskHeight(); |
591 + | + |
592 + | + Bitmap<float> ssim = calcSSIM(img1,img2); |
593 + | + |
594 + | + double ssimSum = 0.0; |
595 + | + |
596 + | + for (int y=0;y<h;y++) |
597 + | + for (int x=0;x<w;x++) |
598 + | + { |
599 + | + ssimSum += ssim[y][x]; |
600 + | + } |
601 + | + |
602 + | + ssimSum /= w*h; |
603 + | + |
604 + | + return ssimSum; |
605 + | + } |
606 + | +} |
607 + | diff --git a/libvideogfx/graphics/measure/ssim.hh b/libvideogfx/graphics/measure/ssim.hh |
608 + | new file mode 100644 |
609 + | index 0000000..04188b8 |
610 + | --- /dev/null |
611 + | +++ libvideogfx/graphics/measure/ssim.hh |
612 + | |
613 + | +/********************************************************************* |
614 + | + libvideogfx/graphics/measure/ssim.hh |
615 + | + |
616 + | + purpose: |
617 + | + |
618 + | + notes: |
619 + | + |
620 + | + to do: |
621 + | + |
622 + | + author(s): |
623 + | + - Dirk Farin, dirk.farin@gmail.com |
624 + | + |
625 + | + modifications: |
626 + | + 21/Jul/2014 - Dirk Farin - first implementation |
627 + | + ******************************************************************************** |
628 + | + LibVideoGfx - video processing library |
629 + | + Copyright (C) 2002-2014 Dirk Farin |
630 + | + |
631 + | + This library is free software; you can redistribute it and/or |
632 + | + modify it under the terms of the GNU Lesser General Public |
633 + | + License as published by the Free Software Foundation; either |
634 + | + version 2.1 of the License, or (at your option) any later version. |
635 + | + |
636 + | + This library is distributed in the hope that it will be useful, |
637 + | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
638 + | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
639 + | + Lesser General Public License for more details. |
640 + | + |
641 + | + You should have received a copy of the GNU Lesser General Public |
642 + | + License along with this library; if not, write to the Free Software |
643 + | + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
644 + | + ********************************************************************************/ |
645 + | + |
646 + | +#ifndef LIBVIDEOGFX_GRAPHICS_MEASURE_SSIM_HH |
647 + | +#define LIBVIDEOGFX_GRAPHICS_MEASURE_SSIM_HH |
648 + | + |
649 + | +#include <libvideogfx/graphics/datatypes/image.hh> |
650 + | + |
651 + | +namespace videogfx { |
652 + | + |
653 + | + class SSIM |
654 + | + { |
655 + | + public: |
656 + | + SSIM() : |
657 + | + C1(0.01 * 256), |
658 + | + C2(0.03 * 256), |
659 + | + r (5), // 11x11 patches |
660 + | + sigma(1.5) |
661 + | + { } |
662 + | + |
663 + | + float C1, C2; |
664 + | + int r; |
665 + | + float sigma; |
666 + | + |
667 + | + Bitmap<float> calcSSIM(const Bitmap<Pixel>& img1, |
668 + | + const Bitmap<Pixel>& img2); |
669 + | + |
670 + | + float calcMSSIM(const Bitmap<Pixel>& img1, |
671 + | + const Bitmap<Pixel>& img2); |
672 + | + }; |
673 + | +} |
674 + | + |
675 + | + |
676 + | +#endif |
677 + | diff --git a/libvideogfx/graphics/visualize/Makefile.am b/libvideogfx/graphics/visualize/Makefile.am |
678 + | index 02a02f0..0ed5bfc 100644 |
679 + | --- libvideogfx/graphics/visualize/Makefile.am |
680 + | +++ libvideogfx/graphics/visualize/Makefile.am |
681 + | |
682 + | # markblks.hh \ |
683 + | # motionfield.hh |
684 + | |
685 + | -INCLUDES = \ |
686 + | +AM_CPPFLAGS = \ |
687 + | -I$(top_srcdir) |
688 + | diff --git a/libvideogfx/libvideogfx.hh.in b/libvideogfx/libvideogfx.hh.in |
689 + | index 704553b..bf698ed 100644 |
690 + | --- libvideogfx/libvideogfx.hh.in |
691 + | +++ libvideogfx/libvideogfx.hh.in |
692 + | |
693 + | #include <libvideogfx/graphics/filters/binomial.hh> |
694 + | #include <libvideogfx/graphics/filters/scale.hh> |
695 + | #include <libvideogfx/graphics/measure/snr.hh> |
696 + | +#include <libvideogfx/graphics/measure/ssim.hh> |
697 + | #include <libvideogfx/graphics/visualize/regions.hh> |
698 + | #include <libvideogfx/audio/fileio/audiosink.hh> |
699 + | #include <libvideogfx/audio/fileio/timedsink.hh> |
700 + | diff --git a/libvideogfx/utility/Makefile.am b/libvideogfx/utility/Makefile.am |
701 + | index 7150ec6..4da98ba 100644 |
702 + | --- libvideogfx/utility/Makefile.am |
703 + | +++ libvideogfx/utility/Makefile.am |
704 + | |
705 + | refcntr.hh |
706 + | # smartpointer.hh |
707 + | |
708 + | -INCLUDES = \ |
709 + | +AM_CPPFLAGS = \ |
710 + | -I$(top_srcdir) |
711 + | diff --git a/libvideogfx/utility/bitstream/Makefile.am b/libvideogfx/utility/bitstream/Makefile.am |
712 + | index f6cb79d..5f45d84 100644 |
713 + | --- libvideogfx/utility/bitstream/Makefile.am |
714 + | +++ libvideogfx/utility/bitstream/Makefile.am |
715 + | |
716 + | inputstream.hh \ |
717 + | inputstream_istr.hh |
718 + | |
719 + | -INCLUDES = \ |
720 + | +AM_CPPFLAGS = \ |
721 + | -I$(top_srcdir) |
722 + | diff --git a/libvideogfx/utility/bitstream/bitbuffer.cc b/libvideogfx/utility/bitstream/bitbuffer.cc |
723 + | index 9f879ac..3b469fd 100644 |
724 + | --- libvideogfx/utility/bitstream/bitbuffer.cc |
725 + | +++ libvideogfx/utility/bitstream/bitbuffer.cc |
726 + | |
727 + | |
728 + | void BitBuffer::WriteBitsMasked(uint32 bits,int nBits) |
729 + | { |
730 + | - uint32 long mask=1; |
731 + | + uint32 mask=1; |
732 + | mask<<=nBits; |
733 + | mask--; |
734 + | |
735 + | diff --git a/libvideogfx/x11/Makefile.am b/libvideogfx/x11/Makefile.am |
736 + | index 06f8309..2eb6c0e 100644 |
737 + | --- libvideogfx/x11/Makefile.am |
738 + | +++ libvideogfx/x11/Makefile.am |
739 + | |
740 + | draw_x11.hh \ |
741 + | server.hh |
742 + | |
743 + | -INCLUDES = \ |
744 + | +AM_CPPFLAGS = \ |
745 + | -I$(top_srcdir) |