diff --git a/cgCompress.pro b/cgCompress.pro index 0daf472..4c861eb 100644 --- a/cgCompress.pro +++ b/cgCompress.pro @@ -4,11 +4,11 @@ INCLUDEPATH += . CONFIG += console QT += concurrent -LIBS += -lz +LIBS += -lz -llz4 # Input -HEADERS += src/Image.hpp src/Frame.hpp src/ImageSimilarities.hpp src/MultiImage.hpp src/Converter.hpp src/OraSaver.hpp src/FileUtils.hpp src/Format.hpp src/ProgressBar.hpp -SOURCES += src/Image.cpp src/Frame.cpp src/ImageSimilarities.cpp src/MultiImage.cpp src/Converter.cpp src/OraSaver.cpp src/FileUtils.cpp src/Format.cpp src/main.cpp +HEADERS += src/Image.hpp src/Frame.hpp src/ImageSimilarities.hpp src/MultiImage.hpp src/Converter.hpp src/OraSaver.hpp src/FileUtils.hpp src/Format.hpp src/FileSizeEval.hpp src/ProgressBar.hpp +SOURCES += src/Image.cpp src/Frame.cpp src/ImageSimilarities.cpp src/MultiImage.cpp src/Converter.cpp src/OraSaver.cpp src/FileUtils.cpp src/Format.cpp src/FileSizeEval.cpp src/main.cpp # minizip SOURCES += src/minizip/ioapi.cpp src/minizip/zip.cpp diff --git a/src/FileSizeEval.cpp b/src/FileSizeEval.cpp new file mode 100644 index 0000000..82bbaaa --- /dev/null +++ b/src/FileSizeEval.cpp @@ -0,0 +1,112 @@ +/* + This file is part of cgCompress. + + cgCompress 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 3 of the License, or + (at your option) any later version. + + cgCompress 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 cgCompress. If not, see . +*/ + +#include "FileSizeEval.hpp" +#include "SubQImage.hpp" + +#include +#include + + +static int compressed_lz4_size( const std::vector& data ){ + auto max_size = LZ4_compressBound( data.size() ); + std::vector buffer( max_size ); + + return LZ4_compress_HC( + (const char*)data.data(), (char*)buffer.data() + , data.size(), buffer.size() + , LZ4HC_DEFAULT_CLEVEL //TODO: Higher? + ); +} + + +int FileSize::simple_alpha( QImage mask, int transparent ){ + //TODO: + return 0; +} + +/** Calculates the sum of the absolute difference between touching pixels + * + * \param [in] img Image to calculate for + * \return The computed value + */ +int FileSize::image_gradient_sum( QImage img ){ + int diffs = 0; + + auto w = img.width(); + for( int iy=0; iy 0 ) && ( qAlpha(right) > 0 ) ){ + diffs += abs( qRed(left) - qRed(right) ); + diffs += abs( qGreen(left) - qGreen(right) ); + diffs += abs( qBlue(left) - qBlue(right) ); + } + } + } + + return diffs; +} + +int FileSize::image_gradient_sum( const SubQImage& img, QImage mask, int pixel_different ){ + int diffs = 0; + + auto w = img.width(); + for( int iy=0; iy data; + data.resize( img.width() * img.height() * 4 ); + + //Encode data + for( int iy=0; iy. +*/ + +#ifndef FILE_SIZE_EVAL_HPP +#define FILE_SIZE_EVAL_HPP + +#include + +/** + Several methods to guess how much space a image will take to store compressed. + However they are not compariable with final filesize or another metric +*/ + +class SubQImage; + +namespace FileSize{ + +int simple_alpha( QImage mask, int transparent ); +int image_gradient_sum( QImage img ); +int image_gradient_sum( const SubQImage& img, QImage mask, int pixel_different ); +int lz4compress_size( QImage img ); + +} + +#endif + diff --git a/src/Format.cpp b/src/Format.cpp index 204e81c..e8a859f 100644 --- a/src/Format.cpp +++ b/src/Format.cpp @@ -16,34 +16,10 @@ */ #include "Format.hpp" +#include "FileSizeEval.hpp" #include -/** Calculates the sum of the absolute difference between touching pixels - * - * \param [in] img Image to calculate for - * \return The computed value - */ -int image_gradient_sum( QImage img ){ - int diffs = 0; - - auto w = img.width(); - for( int iy=0; iy 0 ) && ( qAlpha(right) > 0 ) ){ - diffs += abs( qRed(left) - qRed(right) ); - diffs += abs( qGreen(left) - qGreen(right) ); - diffs += abs( qBlue(left) - qBlue(right) ); - } - } - } - - return diffs; -} /** Compress image to a memory buffer * @@ -66,7 +42,7 @@ QByteArray Format::to_byte_array( QImage img ) const{ */ int Format::file_size( QImage img, Precision p ) const{ if( precision_level > 0 && p != HIGH ) - return image_gradient_sum( img ); + return FileSize::image_gradient_sum( img ); return to_byte_array( img ).size(); } diff --git a/src/Image.cpp b/src/Image.cpp index 3d63e2a..f25341a 100644 --- a/src/Image.cpp +++ b/src/Image.cpp @@ -16,6 +16,7 @@ */ #include "Image.hpp" +#include "FileSizeEval.hpp" #include @@ -408,28 +409,9 @@ int Image::compressed_size( Format format, Format::Precision p ) const{ int Image::estimate_compressed_size( Format format ) const{ if( mask.isNull() ) return format.file_size( remove_transparent(), Format::LOW ); - int diffs = 0; - auto w = img.width(); - for( int iy=0; iy