Skip to content

Commit

Permalink
ADD: Only apply cgcompress:alpha-replace when needed #5
Browse files Browse the repository at this point in the history
  • Loading branch information
spillerrec committed May 17, 2017
1 parent b114a01 commit b10dbdb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,3 +411,19 @@ Image Image::optimize_filesize( Format format ) const{
return copy.remove_transparent();
}

bool Image::mustKeepAlpha() const{
auto img = qimg();
int width = img.width(), height = img.height();

for( int iy=0; iy<height; iy++ ){
auto out = (const QRgb*)img.constScanLine( iy );

for( int ix=0; ix<width; ix++ ){
auto pixel = out[ix];
if( (qAlpha(pixel) != 255) && (pixel != TRANS_SET) )
return true;
}
}

return false;
}
2 changes: 2 additions & 0 deletions src/Image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ class Image {
bool operator==( const Image& other ) const{
return pos == other.pos && img == other.img;
}

bool mustKeepAlpha() const;
};

#endif
Expand Down
14 changes: 12 additions & 2 deletions src/OraSaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,19 @@ void OraSaver::save( QString path, Format format ) const{
stack += "<stack>";

for( auto layer : boost::adaptors::reverse(frame.layers) ){
//Detect composition mode
//TODO: Decide this earlier and change encoding type
QString composition = "composite-op=\"cgcompress:alpha-replace\"";
if( !primitives[layer].mustKeepAlpha() )
composition = "";

QString name = QString( "data/%1.%2" ).arg( layer ).arg( format.ext() );
stack += QString( "<layer composite-op=\"cgcompress:alpha-replace\" name=\"%1\" src=\"%1\" x=\"%2\" y=\"%3\" />" )
.arg( name ).arg( primitives[layer].get_pos().x() ).arg( primitives[layer].get_pos().y() );
stack += QString( "<layer %1 name=\"%2\" src=\"%2\" x=\"%3\" y=\"%4\" />" )
.arg( composition )
.arg( name )
.arg( primitives[layer].get_pos().x() )
.arg( primitives[layer].get_pos().y() )
;
}

stack += "</stack>";
Expand Down

0 comments on commit b10dbdb

Please sign in to comment.