X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fsynfig%2Fsurfacenew.cpp;h=92a268af996d3573ccd996031f90fe6fbb9cdd19;hb=cc54c38609ee9745ad678e5e9b9d7d2912be9c95;hp=be02b63f4332370dd08dea8b2fe8df9b07448118;hpb=28f28705612902c15cd0702cc891fba35bf2d2df;p=synfig.git diff --git a/synfig-core/trunk/src/synfig/surfacenew.cpp b/synfig-core/trunk/src/synfig/surfacenew.cpp index be02b63..92a268a 100644 --- a/synfig-core/trunk/src/synfig/surfacenew.cpp +++ b/synfig-core/trunk/src/synfig/surfacenew.cpp @@ -2,19 +2,20 @@ /*! \file surfacenew.cpp ** \brief Template File ** -** $Id: surfacenew.cpp,v 1.1 2005/01/21 19:29:10 darco Exp $ +** $Id$ ** ** \legal -** Copyright (c) 2002 Robert B. Quattlebaum Jr. +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley ** -** This software and associated documentation -** are CONFIDENTIAL and PROPRIETARY property of -** the above-mentioned copyright holder. +** This package 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 2 of +** the License, or (at your option) any later version. ** -** You may not copy, print, publish, or in any -** other way distribute this software without -** a prior written agreement with -** the copyright holder. +** This package 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. ** \endlegal */ /* ========================================================================= */ @@ -55,9 +56,9 @@ private: float* data_; float* origin_; - + int w_,h_,stride_; - + public: RWLock rw_lock; @@ -70,40 +71,40 @@ public: h_(0) { } - + ~ChannelData() { if(ref_count_.unique()) delete [] data_; } - + void set_wh(int w, int h) { w_=w; h_=h; stride_=w; - + if(data_&&ref_count_.is_unique()) delete [] data_; - + ref_count.make_unique(); data_=new float [w_*h_]; origin_=data_; clear(); } - + void crop(int x, int y, int w, int h) { origin_=origin+y*stride_+x; w_=w; h_=h; } - + int get_stride()const { return stride_; } - + void clear() { for(int i=0;i::iterator iter; for(iter=ret.channel_map_.begin();iter!=ret.channel_map_.end();++iter) iter->crop(x,y,w,h); - + return ret; } @@ -212,13 +213,13 @@ SurfaceNew::get_w()const { return w_; } - + int SurfaceNew::get_h()const { return h_; } - + void SurfaceNew::set_wh(int w, int h) { @@ -247,40 +248,40 @@ SurfaceNew::get_color(int x, int y)const { // This operation is rather expensive, as it should be. // I want to discurage people from using it all over the place. - + Color ret( lock_channel_const(CHAN_R).get_value(x,y), lock_channel_const(CHAN_G).get_value(x,y), lock_channel_const(CHAN_B).get_value(x,y), lock_channel_const(CHAN_A).get_value(x,y) ); - + if(get_premult()) { ret=ret.demult_alpha(); } - + return ret; } - + void SurfaceNew::lock() { mutex_.lock(); } - + void SurfaceNew::unlock() { mutex_.unlock(); } - + bool SurfaceNew::trylock() { return mutex_.trylock(); } - + SurfaceNew::ChannelLock SurfaceNew::lock_channel(SurfaceNew::Channel chan) { @@ -290,12 +291,12 @@ SurfaceNew::lock_channel(SurfaceNew::Channel chan) channel_map_[chan].make_unique(); ChannelLockConst channel_lock; - + channel_lock.surface_=this; channel_lock.channel_=chan; channel_map_[chan].rw_lock.writer_lock(); - + return channel_lock; } @@ -306,12 +307,12 @@ SurfaceNew::lock_channel_const(SurfaceNew::Channel chan)const channel_map_[chan].set_wh(get_w(),get_h()); ChannelLockConst channel_lock; - + channel_lock.surface_=this; channel_lock.channel_=chan; channel_map_[chan].rw_lock.reader_lock(); - + return channel_lock; } @@ -348,9 +349,9 @@ SurfaceNew::set_premult(bool x) { if(x==premult_flag_) return; - + premult_flag_=x; - + for(int i=0;i<3;i++) { Channel chan; @@ -367,23 +368,23 @@ SurfaceNew::set_premult(bool x) case 1: chan=CHAN_U; case 2: chan=CHAN_V; } - + // If this channel isn't defined, then // skip it and move on to the next one if(!is_channel_defined(chan)) continue; - + ChannelLock color_channel(lock_channel(chan)); ChannelLockConst alpha_channel(lock_channel_alpha_const(chan)); const int w(get_w()); const int h(get_h()); - + float* color_ptr(color_channel.get_data_ptr()); const float* alpha_ptr(alpha_channel.get_data_ptr()); - + const int color_pitch(color_channel.get_data_ptr_stride()-w); const int alpha_pitch(alpha_channel.get_data_ptr_stride()-w); - + if(premult_flag_) { for(int y=0;yget_w()), h(src->get_h); - + // Clip { int x(0), y(0); - + if(x_dest+w>dest.get_w()) w=dest.get_w()-x_dest; if(y_dest+h>dest.get_h()) @@ -451,7 +452,7 @@ SurfaceNew::blit( } src=crop(src,x,y,w,h); } - + dest=crop(dest,x_dest,y_dest,w,h); if(bm==Color::BLEND_STRAIGHT) @@ -460,10 +461,10 @@ SurfaceNew::blit( chan_add(dest,src); chan_mlt(dest,(1.0-amount)/amount); } - + if(bm==Color::BLEND_COMPOSITE) { - + } } @@ -480,7 +481,7 @@ SurfaceChannelLockConst::~SurfaceChannelLockConst() { if(data_ptr_checked_out_) release_data_ptr(); - + if(surface_ && ref_count_.is_unique()) return surface->channel_map_[channel_].rw_lock.reader_unlock(); surface=0; @@ -497,13 +498,13 @@ SurfaceChannelLockConst::get_w()const { return surface_->get_w(); } - + int SurfaceChannelLockConst::get_h()const { return surface_->get_h(); } - + float SurfaceChannelLockConst::get_value(int x, int y) { @@ -516,7 +517,7 @@ const float* SurfaceChannelLockConst::get_data_ptr()const { data_ptr_checked_out_=true; - + // WOW! CRAZY SLOW! return surface_->channel_map_[channel_].get_data(); } @@ -596,7 +597,7 @@ SurfaceNew::chan_mlt(ChannelLock& dest, float x) const int w(dest.get_w()); const int h(dest.get_h()); const int pitch(dest.get_data_pitch()-w); - + int(y=0;y