From da1020876351d3d8f86440aafc685e8432307a80 Mon Sep 17 00:00:00 2001 From: CasualPokePlayer <50538166+CasualPokePlayer@users.noreply.github.com> Date: Mon, 20 Sep 2021 20:25:12 -0700 Subject: [PATCH] update sgb; update core --- common/adaptivesleep.cpp | 52 - common/adaptivesleep.h | 35 - common/array.h | 53 - common/defined_ptr.h | 16 - common/rateest.cpp | 91 - common/rateest.h | 61 - common/resample/resampler.h | 84 - common/resample/resamplerinfo.h | 59 - common/resample/src/blackmansinc.h | 93 - common/resample/src/chainresampler.cpp | 220 -- common/resample/src/chainresampler.h | 110 - common/resample/src/cic2.h | 170 - common/resample/src/cic3.h | 139 - common/resample/src/cic4.h | 194 -- common/resample/src/hammingsinc.h | 92 - common/resample/src/i0.cpp | 35 - common/resample/src/i0.h | 24 - common/resample/src/kaiser50sinc.cpp | 32 - common/resample/src/kaiser50sinc.h | 89 - common/resample/src/kaiser70sinc.cpp | 32 - common/resample/src/kaiser70sinc.h | 89 - common/resample/src/linint.h | 144 - common/resample/src/makesinckernel.cpp | 130 - common/resample/src/makesinckernel.h | 25 - common/resample/src/polyphasefir.h | 176 - common/resample/src/rectsinc.h | 89 - common/resample/src/resamplerinfo.cpp | 42 - common/resample/src/rshift16_round.h | 33 - common/resample/src/subresampler.h | 33 - common/resample/src/u48div.cpp | 57 - common/resample/src/u48div.h | 24 - common/resample/src/upsampler.h | 53 - common/ringbuffer.h | 109 - common/scoped_ptr.h | 29 - common/skipsched.cpp | 35 - common/skipsched.h | 32 - common/transfer_ptr.h | 27 - common/uncopyable.h | 30 - common/usec.h | 27 - common/videolink/rgb32conv.cpp | 199 -- common/videolink/rgb32conv.h | 30 - common/videolink/vfilterinfo.cpp | 48 - common/videolink/vfilterinfo.h | 39 - common/videolink/vfilters/catrom2x.cpp | 179 - common/videolink/vfilters/catrom2x.h | 41 - common/videolink/vfilters/catrom3x.cpp | 345 -- common/videolink/vfilters/catrom3x.h | 41 - common/videolink/vfilters/kreed2xsai.cpp | 233 -- common/videolink/vfilters/kreed2xsai.h | 41 - common/videolink/vfilters/maxsthq2x.cpp | 2858 ---------------- common/videolink/vfilters/maxsthq2x.h | 41 - common/videolink/vfilters/maxsthq3x.cpp | 3824 ---------------------- common/videolink/vfilters/maxsthq3x.h | 41 - common/videolink/videolink.h | 32 - gambatte_core | 2 +- gambatte_qt/src/gambattesource.cpp | 166 +- gambatte_qt/src/gambattesource.h | 16 +- gambatte_qt/src/src.pro | 18 +- 58 files changed, 155 insertions(+), 10904 deletions(-) delete mode 100644 common/adaptivesleep.cpp delete mode 100644 common/adaptivesleep.h delete mode 100644 common/array.h delete mode 100644 common/defined_ptr.h delete mode 100644 common/rateest.cpp delete mode 100644 common/rateest.h delete mode 100644 common/resample/resampler.h delete mode 100644 common/resample/resamplerinfo.h delete mode 100644 common/resample/src/blackmansinc.h delete mode 100644 common/resample/src/chainresampler.cpp delete mode 100644 common/resample/src/chainresampler.h delete mode 100644 common/resample/src/cic2.h delete mode 100644 common/resample/src/cic3.h delete mode 100644 common/resample/src/cic4.h delete mode 100644 common/resample/src/hammingsinc.h delete mode 100644 common/resample/src/i0.cpp delete mode 100644 common/resample/src/i0.h delete mode 100644 common/resample/src/kaiser50sinc.cpp delete mode 100644 common/resample/src/kaiser50sinc.h delete mode 100644 common/resample/src/kaiser70sinc.cpp delete mode 100644 common/resample/src/kaiser70sinc.h delete mode 100644 common/resample/src/linint.h delete mode 100644 common/resample/src/makesinckernel.cpp delete mode 100644 common/resample/src/makesinckernel.h delete mode 100644 common/resample/src/polyphasefir.h delete mode 100644 common/resample/src/rectsinc.h delete mode 100644 common/resample/src/resamplerinfo.cpp delete mode 100644 common/resample/src/rshift16_round.h delete mode 100644 common/resample/src/subresampler.h delete mode 100644 common/resample/src/u48div.cpp delete mode 100644 common/resample/src/u48div.h delete mode 100644 common/resample/src/upsampler.h delete mode 100644 common/ringbuffer.h delete mode 100644 common/scoped_ptr.h delete mode 100644 common/skipsched.cpp delete mode 100644 common/skipsched.h delete mode 100644 common/transfer_ptr.h delete mode 100644 common/uncopyable.h delete mode 100644 common/usec.h delete mode 100644 common/videolink/rgb32conv.cpp delete mode 100644 common/videolink/rgb32conv.h delete mode 100644 common/videolink/vfilterinfo.cpp delete mode 100644 common/videolink/vfilterinfo.h delete mode 100644 common/videolink/vfilters/catrom2x.cpp delete mode 100644 common/videolink/vfilters/catrom2x.h delete mode 100644 common/videolink/vfilters/catrom3x.cpp delete mode 100644 common/videolink/vfilters/catrom3x.h delete mode 100644 common/videolink/vfilters/kreed2xsai.cpp delete mode 100644 common/videolink/vfilters/kreed2xsai.h delete mode 100644 common/videolink/vfilters/maxsthq2x.cpp delete mode 100644 common/videolink/vfilters/maxsthq2x.h delete mode 100644 common/videolink/vfilters/maxsthq3x.cpp delete mode 100644 common/videolink/vfilters/maxsthq3x.h delete mode 100644 common/videolink/videolink.h diff --git a/common/adaptivesleep.cpp b/common/adaptivesleep.cpp deleted file mode 100644 index 407b2406..00000000 --- a/common/adaptivesleep.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#include "adaptivesleep.h" - -static usec_t absdiff(usec_t a, usec_t b) { return a < b ? b - a : a - b; } - -usec_t AdaptiveSleep::sleepUntil(usec_t base, usec_t inc) { - usec_t now = getusecs(); - usec_t diff = now - base; - if (diff >= inc) - return diff - inc; - - diff = inc - diff; - if (diff > oversleep_ + oversleepVar_) { - diff -= oversleep_ + oversleepVar_; - usecsleep(diff); - usec_t const sleepTarget = now + diff; - now = getusecs(); - - usec_t curOversleep = now - sleepTarget; - if (curOversleep > usec_t(-1) / 2) - curOversleep = 0; - - oversleepVar_ = (oversleepVar_ * 15 + absdiff(curOversleep, oversleep_) + 8) >> 4; - oversleep_ = (oversleep_ * 15 + curOversleep + 8) >> 4; - noSleep_ = 60; - } else if (--noSleep_ == 0) { - noSleep_ = 60; - oversleep_ = oversleepVar_ = 0; - } - - while (now - base < inc) - now = getusecs(); - - return 0; -} diff --git a/common/adaptivesleep.h b/common/adaptivesleep.h deleted file mode 100644 index da1aa3fa..00000000 --- a/common/adaptivesleep.h +++ /dev/null @@ -1,35 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef ADAPTIVE_SLEEP_H -#define ADAPTIVE_SLEEP_H - -#include "usec.h" - -class AdaptiveSleep { -public: - AdaptiveSleep() : oversleep_(0), oversleepVar_(0), noSleep_(60) {} - usec_t sleepUntil(usec_t base, usec_t inc); - -private: - usec_t oversleep_; - usec_t oversleepVar_; - unsigned noSleep_; -}; - -#endif diff --git a/common/array.h b/common/array.h deleted file mode 100644 index cd015cd0..00000000 --- a/common/array.h +++ /dev/null @@ -1,53 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef ARRAY_H -#define ARRAY_H - -#include "defined_ptr.h" -#include "uncopyable.h" -#include - -template -class SimpleArray : Uncopyable { -public: - explicit SimpleArray(std::size_t size = 0) : a_(size ? new T[size] : 0) {} - ~SimpleArray() { delete[] defined_ptr(a_); } - void reset(std::size_t size = 0) { delete[] defined_ptr(a_); a_ = size ? new T[size] : 0; } - T * get() const { return a_; } - operator T *() const { return a_; } - -private: - T *a_; -}; - -template -class Array { -public: - explicit Array(std::size_t size = 0) : a_(size), size_(size) {} - void reset(std::size_t size = 0) { a_.reset(size); size_ = size; } - std::size_t size() const { return size_; } - T * get() const { return a_; } - operator T *() const { return a_; } - -private: - SimpleArray a_; - std::size_t size_; -}; - -#endif diff --git a/common/defined_ptr.h b/common/defined_ptr.h deleted file mode 100644 index 9590c1c8..00000000 --- a/common/defined_ptr.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef DEFINED_PTR_H -#define DEFINED_PTR_H - -template -inline T * defined_ptr(T *t) { - typedef char type_is_defined[sizeof *t ? 1 : -1]; - (void) sizeof(type_is_defined); - return t; -} - -template -inline void defined_delete(T *t) { delete defined_ptr(t); } - -struct defined_deleter { template static void del(T *p) { defined_delete(p); } }; - -#endif diff --git a/common/rateest.cpp b/common/rateest.cpp deleted file mode 100644 index 11fca151..00000000 --- a/common/rateest.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#include "rateest.h" -#include - -void RateEst::SumQueue::push(std::ptrdiff_t const samples, usec_t const usecs) { - q_.push_back(std::make_pair(samples, usecs)); - samples_ += samples; - usecs_ += usecs; -} - -void RateEst::SumQueue::pop() { - std::pair const &f = q_.front(); - samples_ -= f.first; - usecs_ -= f.second; - q_.pop_front(); -} - -static usec_t sampleUsecs(std::ptrdiff_t samples, long rate) { - return usec_t((samples * 1000000.0f) / (rate ? rate : 1) + 0.5f); -} - -static long limit(long est, long const reference) { - if (est > reference + (reference >> 6)) - est = reference + (reference >> 6); - else if (est < reference - (reference >> 6)) - est = reference - (reference >> 6); - - return est; -} - -RateEst::RateEst(long const nominalSampleRate, std::size_t const maxValidFeedPeriodSamples) -: srate_(nominalSampleRate * est_scale) -, reference_(srate_) -, maxPeriod_(sampleUsecs(maxValidFeedPeriodSamples, nominalSampleRate)) -, last_(0) -, t_(6000) -, s_(nominalSampleRate * 6) -, st_(s_ * t_) -, t2_(t_ * t_) -{ -} - -void RateEst::feed(std::ptrdiff_t samplesIn, usec_t const now) { - usec_t usecsIn = now - last_; - - if (last_ && usecsIn < maxPeriod_) { - sumq_.push(samplesIn, usecsIn); - - while ((usecsIn = sumq_.usecs()) > 100000) { - samplesIn = sumq_.samples(); - sumq_.pop(); - - long const srateIn = long(samplesIn * (1000000.0f * est_scale) / usecsIn); - if (std::abs(srateIn - reference_) < reference_ >> 1) { - s_ += samplesIn - sumq_.samples() ; - t_ += ( usecsIn - sumq_.usecs() ) * 0.001; - st_ += s_ * t_; - t2_ += t_ * t_; - - long est = long(st_ * (1000.0 * est_scale) / t2_ + 0.5); - srate_ = limit((srate_ * 31 + est + 16) >> 5, reference_); - - if (t_ > 8000) { - s_ *= 3.0 / 4; - t_ *= 3.0 / 4; - st_ *= 9.0 / 16; - t2_ *= 9.0 / 16; - } - } - } - } - - last_ = now; -} diff --git a/common/rateest.h b/common/rateest.h deleted file mode 100644 index 91c8dfd5..00000000 --- a/common/rateest.h +++ /dev/null @@ -1,61 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef RATEEST_H -#define RATEEST_H - -#include "usec.h" -#include -#include -#include - -class RateEst { -public: - RateEst() { *this = RateEst(0, 0); } - RateEst(long nominalSampleRate, std::size_t maxValidFeedPeriodSamples); - void resetLastFeedTimeStamp() { last_ = 0; } - void feed(std::ptrdiff_t samples, usec_t usecsNow = getusecs()); - long result() const { return (srate_ + est_scale / 2) >> est_lshift; } - -private: - class SumQueue { - public: - SumQueue() : samples_(0), usecs_(0) {} - std::ptrdiff_t samples() const { return samples_; } - usec_t usecs() const { return usecs_; } - void push(std::ptrdiff_t samples, usec_t usecs); - void pop(); - - private: - std::deque< std::pair > q_; - std::ptrdiff_t samples_; - usec_t usecs_; - }; - - enum { est_lshift = 5 }; - enum { est_scale = 1 << est_lshift }; - - SumQueue sumq_; - long srate_; - long reference_; - usec_t maxPeriod_; - usec_t last_; - double t_, s_, st_, t2_; -}; - -#endif diff --git a/common/resample/resampler.h b/common/resample/resampler.h deleted file mode 100644 index e60b5bda..00000000 --- a/common/resample/resampler.h +++ /dev/null @@ -1,84 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef RESAMPLER_H -#define RESAMPLER_H - -#include - -class Resampler { -public: - /** Returns the sampling rate of the input that this resampler expects. */ - long inRate() const { return inRate_; } - - /** Returns the approximate sampling rate of the output. */ - long outRate() const { return outRate_; } - - /** - * Can be used to adjust the input and output sampling rates slightly with minimal - * disturbance in the output. - * - * Should only be used for slight changes or the quality could detoriate. It can for - * instance be useful to tweak the output rate slightly to synchronize production speed - * to playback speed when synchronizing video frame rate to refresh rate while playing - * back audio from the same source. This can reduce skipped or duplicated video frames - * (or avoid audio underruns if no frame skipping is done). - * - * @param inRate New input sampling rate. - * @param outRate Desired new output sampling rate. - */ - virtual void adjustRate(long inRate, long outRate) = 0; - - /** - * Returns the exact ratio that this resampler is configured to use, such that the actual - * output sampling rate is input_rate * mul / div. - * - * outRate() and inRate() are not necessarily equal to mul and div. - * - * Many resamplers are intended for real-time purposes where it does not matter much - * whether the output sampling rate is 100% exact. - */ - virtual void exactRatio(unsigned long &mul, unsigned long &div) const = 0; - - /** - * Returns an upper bound on how many samples are produced for 'inlen' input samples. - * Can be used to calculate buffer sizes. - */ - virtual std::size_t maxOut(std::size_t inlen) const = 0; - - /** - * Resamples the samples in 'in' and puts the resulting samples in 'out'. - * - * @param inlen The number of samples in 'in' to be resampled/consumed. - * @return The number of samples produced in 'out'. - */ - virtual std::size_t resample(short *out, short const *in, std::size_t inlen) = 0; - - virtual ~Resampler() {} - -protected: - Resampler() : inRate_(0), outRate_(0) {} - Resampler(long inRate, long outRate) : inRate_(inRate), outRate_(outRate) {} - void setRate(long inRate, long outRate) { inRate_ = inRate; outRate_ = outRate; } - -private: - long inRate_; - long outRate_; -}; - -#endif diff --git a/common/resample/resamplerinfo.h b/common/resample/resamplerinfo.h deleted file mode 100644 index 0d319e18..00000000 --- a/common/resample/resamplerinfo.h +++ /dev/null @@ -1,59 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef RESAMPLER_INFO_H -#define RESAMPLER_INFO_H - -#include - -class Resampler; - -/** - * Used for creating instances of resamplers, and getting information on - * available resamplers. - */ -struct ResamplerInfo { - /** Number of interleaved channels per audio sample (frame) */ - enum { channels = 2 }; - - /** Short character string description of the resampler. */ - char const *desc; - - /** - * Points to a function that can be used to create an instance of the resampler. - * - * @param inRate The input sampling rate. - * @param outRate The desired output sampling rate. - * @param periodSize The maximum number of input samples to resample at a time/The - * maximal inlen passed to Resampler::resample. - * @return Pointer to the created instance on the free store. - */ - Resampler * (*create)(long inRate, long outRate, std::size_t periodSize); - - /** Returns the number of ResamplerInfos that can be gotten with get(). */ - static std::size_t num() { return num_; } - - /** Returns ResamplerInfo number n. Where n is less than num(). */ - static ResamplerInfo const & get(std::size_t n) { return resamplers_[n]; } - -private: - static ResamplerInfo const resamplers_[]; - static std::size_t const num_; -}; - -#endif diff --git a/common/resample/src/blackmansinc.h b/common/resample/src/blackmansinc.h deleted file mode 100644 index bcf2a42b..00000000 --- a/common/resample/src/blackmansinc.h +++ /dev/null @@ -1,93 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef BLACKMANSINC_H -#define BLACKMANSINC_H - -#include "array.h" -#include "cic4.h" -#include "makesinckernel.h" -#include "polyphasefir.h" -#include "subresampler.h" -#include -#include -#include - -template -class BlackmanSinc : public SubResampler { -public: - enum { MUL = phases }; - typedef Cic4 Cic; - static float cicLimit() { return 4.7f; } - - class RollOff { - public: - unsigned const taps; - float const fc; - - RollOff(float rollOffStart, float rollOffWidth) - : taps(toTaps(rollOffWidth)), fc(toFc(rollOffStart, taps)) - { - } - - private: - static unsigned toTaps(float rollOffWidth) { - float widthTimesTaps = 4.5f; - return std::max(unsigned(std::ceil(widthTimesTaps / rollOffWidth)), 4u); - } - - static float toFc(float rollOffStart, int taps) { - float startToFcDeltaTimesTaps = 1.69f; - return startToFcDeltaTimesTaps / taps + rollOffStart; - } - }; - - BlackmanSinc(unsigned div, unsigned phaseLen, double fc) - : kernel_(phaseLen * phases) - , polyfir_(kernel_, phaseLen, div) - { - makeSincKernel(kernel_, phases, phaseLen, fc, blackmanWin, 1.0); - } - - BlackmanSinc(unsigned div, RollOff ro, double gain) - : kernel_(ro.taps * phases) - , polyfir_(kernel_, ro.taps, div) - { - makeSincKernel(kernel_, phases, ro.taps, ro.fc, blackmanWin, gain); - } - - virtual std::size_t resample(short *out, short const *in, std::size_t inlen) { - return polyfir_.filter(out, in, inlen); - } - - virtual void adjustDiv(unsigned div) { polyfir_.adjustDiv(div); } - virtual unsigned mul() const { return MUL; } - virtual unsigned div() const { return polyfir_.div(); } - -private: - Array const kernel_; - PolyphaseFir polyfir_; - - static double blackmanWin(long i, long M) { - double pi = 3.14159265358979323846; - return 0.42 - 0.5 * std::cos(2 * pi * i / M) - + 0.08 * std::cos(4 * pi * i / M); - } -}; - -#endif diff --git a/common/resample/src/chainresampler.cpp b/common/resample/src/chainresampler.cpp deleted file mode 100644 index 57764e39..00000000 --- a/common/resample/src/chainresampler.cpp +++ /dev/null @@ -1,220 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#include "chainresampler.h" -#include "upsampler.h" -#include -#include - -static float get1ChainCost(float ratio, float finalRollOffLen) { - return ratio / finalRollOffLen; -} - -static float get2ChainMidRatio(float ratio, float finalRollOffLen, float midRollOffStartPlusEnd) { - return 0.5f * ( std::sqrt(ratio * midRollOffStartPlusEnd * finalRollOffLen) - + midRollOffStartPlusEnd); -} - -static float get2ChainCost(float ratio, float finalRollOffLen, float midRatio, - float midRollOffStartPlusEnd) -{ - float midRollOffLen = midRatio * 2 - midRollOffStartPlusEnd; - return midRatio * ratio / midRollOffLen - + get1ChainCost(midRatio, finalRollOffLen); -} - -static float get3ChainRatio2(float ratio1, - float finalRollOffLen, - float midRollOffStartPlusEnd) { - return get2ChainMidRatio(ratio1, finalRollOffLen, midRollOffStartPlusEnd); -} - -static float get3ChainRatio1(float ratio1, float const finalRollOffLen, float const ratio, - float const midRollOffStartPlusEnd) -{ - for (int n = 8; n--;) { - float ratio2 = get3ChainRatio2(ratio1, finalRollOffLen, midRollOffStartPlusEnd); - ratio1 = ( std::sqrt(ratio * midRollOffStartPlusEnd * (2 - midRollOffStartPlusEnd / ratio2)) - + midRollOffStartPlusEnd) * 0.5f; - } - - return ratio1; -} - -static float get3ChainCost(float ratio, float finalRollOffLen, - float ratio1, float ratio2, float midRollOffStartPlusEnd) -{ - float firstRollOffLen = ratio1 * 2 - midRollOffStartPlusEnd; - return ratio1 * ratio / firstRollOffLen - + get2ChainCost(ratio1, finalRollOffLen, ratio2, midRollOffStartPlusEnd); -} - -ChainResampler::ChainResampler(long inRate, long outRate, std::size_t periodSize) -: Resampler(inRate, outRate) -, bigSinc_(0) -, buffer2_(0) -, periodSize_(periodSize) -, maxOut_(0) -{ -} - -void ChainResampler::downinitAddSincResamplers(double ratio, - float const outRate, - CreateSinc const createBigSinc, - CreateSinc const createSmallSinc, - double gain) -{ - // For high outRate: Start roll-off at 36 kHz continue until outRate Hz, - // then wrap around back down to 40 kHz. - float const outPeriod = 1.0f / outRate; - float const finalRollOffLen = - std::max((outRate - 36000.0f + outRate - 40000.0f) * outPeriod, - 0.2f); - { - float const midRollOffStart = std::min(36000.0f * outPeriod, 1.0f); - float const midRollOffEnd = std::min(40000.0f * outPeriod, 1.0f); // after wrap at folding freq. - float const midRollOffStartPlusEnd = midRollOffStart + midRollOffEnd; - float const ideal2ChainMidRatio = get2ChainMidRatio(ratio, finalRollOffLen, - midRollOffStartPlusEnd); - int div_2c = int(ratio * small_sinc_mul / ideal2ChainMidRatio + 0.5f); - double ratio_2c = ratio * small_sinc_mul / div_2c; - float cost_2c = get2ChainCost(ratio, finalRollOffLen, ratio_2c, midRollOffStartPlusEnd); - if (cost_2c < get1ChainCost(ratio, finalRollOffLen)) { - float const ideal3ChainRatio1 = get3ChainRatio1(ratio_2c, finalRollOffLen, - ratio, midRollOffStartPlusEnd); - int const div1_3c = int(ratio * small_sinc_mul / ideal3ChainRatio1 + 0.5f); - double const ratio1_3c = ratio * small_sinc_mul / div1_3c; - float const ideal3ChainRatio2 = get3ChainRatio2(ratio1_3c, finalRollOffLen, - midRollOffStartPlusEnd); - int const div2_3c = int(ratio1_3c * small_sinc_mul / ideal3ChainRatio2 + 0.5f); - double const ratio2_3c = ratio1_3c * small_sinc_mul / div2_3c; - if (get3ChainCost(ratio, finalRollOffLen, ratio1_3c, - ratio2_3c, midRollOffStartPlusEnd) < cost_2c) { - list_.push_back(createSmallSinc(div1_3c, - 0.5f * midRollOffStart / ratio, - (ratio1_3c - 0.5f * midRollOffStartPlusEnd) / ratio, - gain)); - ratio = ratio1_3c; - div_2c = div2_3c; - ratio_2c = ratio2_3c; - gain = 1.0; - } - - list_.push_back(createSmallSinc(div_2c, - 0.5f * midRollOffStart / ratio, - (ratio_2c - 0.5f * midRollOffStartPlusEnd) / ratio, - gain)); - ratio = ratio_2c; - gain = 1.0; - } - } - - float rollOffStart = 0.5f * (1.0f - + std::max((outRate - 40000.0f) * outPeriod, 0.0f) - - finalRollOffLen) / ratio; - bigSinc_ = createBigSinc(static_cast(big_sinc_mul * ratio + 0.5), - rollOffStart, - 0.5f * finalRollOffLen / ratio, - gain); - list_.push_back(bigSinc_); -} - -void ChainResampler::upinit(long const inRate, - long const outRate, - CreateSinc const createSinc) { - double ratio = static_cast(outRate) / inRate; - // Spectral images above 20 kHz assumed inaudible - // this post-polyphase zero stuffing causes some power loss though. - { - int const div = outRate / std::max(inRate, 40000l); - if (div >= 2) { - list_.push_front(new Upsampler(div)); - ratio /= div; - } - } - - float const rollOffLen = std::max((inRate - 36000.0f) / inRate, 0.2f); - bigSinc_ = createSinc(static_cast(big_sinc_mul / ratio + 0.5), - 0.5f * (1 - rollOffLen), - 0.5f * rollOffLen, - 1.0); - list_.push_front(bigSinc_); // note: inserted at the front - reallocateBuffer(); -} - -void ChainResampler::reallocateBuffer() { - std::size_t bufSize[2] = { 0, 0 }; - std::size_t inSize = periodSize_; - int i = -1; - for (List::iterator it = list_.begin(); it != list_.end(); ++it) { - inSize = (inSize * (*it)->mul() - 1) / (*it)->div() + 1; - ++i; - if (inSize > bufSize[i & 1]) - bufSize[i & 1] = inSize; - } - - if (inSize >= bufSize[i & 1]) - bufSize[i & 1] = 0; - - if (buffer_.size() < (bufSize[0] + bufSize[1]) * channels) - buffer_.reset((bufSize[0] + bufSize[1]) * channels); - - buffer2_ = bufSize[1] ? buffer_ + bufSize[0] * channels : 0; - maxOut_ = inSize; -} - -void ChainResampler::adjustRate(long const inRate, long const outRate) { - unsigned long mul, div; - exactRatio(mul, div); - - double newDiv = double( inRate) * mul - / (double(outRate) * (div / bigSinc_->div())); - bigSinc_->adjustDiv(int(newDiv + 0.5)); - reallocateBuffer(); - setRate(inRate, outRate); -} - -void ChainResampler::exactRatio(unsigned long &mul, unsigned long &div) const { - mul = 1; - div = 1; - for (List::const_iterator it = list_.begin(); it != list_.end(); ++it) { - mul *= (*it)->mul(); - div *= (*it)->div(); - } -} - -std::size_t ChainResampler::resample(short *const out, short const *const in, std::size_t inlen) { - assert(inlen <= periodSize_); - short *const buf = buffer_ != buffer2_ ? buffer_ : out; - short *const buf2 = buffer2_ ? buffer2_ : out; - short const *inbuf = in; - short *outbuf = 0; - for (List::iterator it = list_.begin(); it != list_.end(); ++it) { - outbuf = ++List::iterator(it) == list_.end() - ? out - : (inbuf == buf ? buf2 : buf); - inlen = (*it)->resample(outbuf, inbuf, inlen); - inbuf = outbuf; - } - - return inlen; -} - -ChainResampler::~ChainResampler() { - std::for_each(list_.begin(), list_.end(), defined_delete); -} diff --git a/common/resample/src/chainresampler.h b/common/resample/src/chainresampler.h deleted file mode 100644 index 72076c89..00000000 --- a/common/resample/src/chainresampler.h +++ /dev/null @@ -1,110 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef CHAINRESAMPLER_H -#define CHAINRESAMPLER_H - -#include "../resampler.h" -#include "../resamplerinfo.h" -#include "array.h" -#include "transfer_ptr.h" -#include -#include - -class SubResampler; - -class ChainResampler : public Resampler { -public: - enum { channels = ResamplerInfo::channels }; - - template class Sinc> - static Resampler * create(long inRate, long outRate, std::size_t periodSize); - - virtual ~ChainResampler(); - virtual void adjustRate(long inRate, long outRate); - virtual void exactRatio(unsigned long &mul, unsigned long &div) const; - virtual std::size_t maxOut(std::size_t /*inlen*/) const { return maxOut_; } - virtual std::size_t resample(short *out, short const *in, std::size_t inlen); - -private: - typedef std::list List; - typedef SubResampler * (*CreateSinc)(unsigned div, float rollOffStart, - float rollOffWidth, double gain); - enum { big_sinc_mul = 2048 }; - enum { small_sinc_mul = 32 }; - - List list_; - SubResampler *bigSinc_; - Array buffer_; - short *buffer2_; - std::size_t const periodSize_; - std::size_t maxOut_; - - ChainResampler(long inRate, long outRate, std::size_t periodSize); - void downinitAddSincResamplers(double ratio, float outRate, - CreateSinc createBigSinc, - CreateSinc createSmallSinc, - double gain); - void upinit(long inRate, long outRate, CreateSinc); - void reallocateBuffer(); - - template - static SubResampler * createSinc(unsigned div, - float rollOffStart, float rollOffWidth, double gain) { - return new Sinc(div, typename Sinc::RollOff(rollOffStart, rollOffWidth), gain); - } - - template class Sinc> - void downinit(long inRate, long outRate); -}; - -template class Sinc> -Resampler * ChainResampler::create(long inRate, long outRate, std::size_t periodSize) { - transfer_ptr r(new ChainResampler(inRate, outRate, periodSize)); - if (outRate > inRate) { - r->upinit(inRate, outRate, - createSinc< Sinc >); - } else - r->downinit(inRate, outRate); - - return r.release(); -} - -template class Sinc> -void ChainResampler::downinit(long const inRate, - long const outRate) { - typedef Sinc BigSinc; - typedef Sinc SmallSinc; - - double ratio = static_cast(inRate) / outRate; - double gain = 1.0; - while (ratio >= BigSinc::cicLimit() * 2) { - int const div = std::min(int(ratio / BigSinc::cicLimit()), - BigSinc::Cic::MAX_DIV); - list_.push_back(new typename BigSinc::Cic(div)); - ratio /= div; - gain *= 1.0 / BigSinc::Cic::gain(div); - } - - downinitAddSincResamplers(ratio, outRate, - createSinc, createSinc, - gain); - reallocateBuffer(); -} - -#endif diff --git a/common/resample/src/cic2.h b/common/resample/src/cic2.h deleted file mode 100644 index 6f1fbc7f..00000000 --- a/common/resample/src/cic2.h +++ /dev/null @@ -1,170 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef CIC2_H -#define CIC2_H - -#include "rshift16_round.h" -#include "subresampler.h" - -template -class Cic2Core { -public: - explicit Cic2Core(unsigned div = 2) { reset(div); } - unsigned div() const { return div_; } - std::size_t filter(short *out, short const *in, std::size_t inlen); - void reset(unsigned div); - - static double gain(unsigned div) { - return rshift16_round(-32768l * (div * div) * mulForDiv(div)) / -32768.0; - } - -private: - unsigned long sum1_; - unsigned long sum2_; - unsigned long prev1_; - unsigned div_; - unsigned nextdivn_; - - // trouble if div is too large, may be better to only support power of 2 div - static long mulForDiv(unsigned div) { return 0x10000 / (div * div); } -}; - -template -void Cic2Core::reset(unsigned div) { - sum2_ = sum1_ = 0; - prev1_ = 0; - div_ = div; - nextdivn_ = div; -} - -template -std::size_t Cic2Core::filter(short *out, short const *const in, std::size_t inlen) { - std::size_t const produced = (inlen + div_ - nextdivn_) / div_; - long const mul = mulForDiv(div_); - short const *s = in; - unsigned long sm1 = sum1_; - unsigned long sm2 = sum2_; - - if (inlen >= nextdivn_) { - { - unsigned divn = nextdivn_; - do { - sm1 += static_cast(*s); - s += channels; - sm2 += sm1; - } while (--divn); - - unsigned long const out2 = sm2; - sm2 = 0; - - *out = rshift16_round(static_cast(out2 - prev1_) * mul); - prev1_ = out2; - out += channels; - } - - if (div_ & 1) { - for (std::size_t n = produced; --n;) { - unsigned divn = div_ >> 1; - do { - sm1 += static_cast(*s); - s += channels; - sm2 += sm1; - sm1 += static_cast(*s); - s += channels; - sm2 += sm1; - } while (--divn); - - sm1 += static_cast(*s); - s += channels; - sm2 += sm1; - - *out = rshift16_round(static_cast(sm2 - prev1_) * mul); - out += channels; - prev1_ = sm2; - sm2 = 0; - } - } else { - for (std::size_t n = produced; --n;) { - unsigned divn = div_ >> 1; - do { - sm1 += static_cast(*s); - s += channels; - sm2 += sm1; - sm1 += static_cast(*s); - s += channels; - sm2 += sm1; - } while (--divn); - - *out = rshift16_round(static_cast(sm2 - prev1_) * mul); - out += channels; - prev1_ = sm2; - sm2 = 0; - } - } - - nextdivn_ = div_; - } - - { - unsigned divn = (in + inlen * channels - s) / channels; - nextdivn_ -= divn; - - while (divn--) { - sm1 += static_cast(*s); - s += channels; - sm2 += sm1; - } - } - - sum1_ = sm1; - sum2_ = sm2; - - return produced; -} - -template -class Cic2 : public SubResampler { -public: - enum { MAX_DIV = 64 }; - explicit Cic2(unsigned div); - virtual std::size_t resample(short *out, short const *in, std::size_t inlen); - virtual unsigned mul() const { return 1; } - virtual unsigned div() const { return cics_[0].div(); } - static double gain(unsigned div) { return Cic2Core::gain(div); } - -private: - Cic2Core cics_[channels]; -}; - -template -Cic2::Cic2(unsigned div) { - for (unsigned i = 0; i < channels; ++i) - cics_[i].reset(div); -} - -template -std::size_t Cic2::resample(short *out, short const *in, std::size_t inlen) { - std::size_t samplesOut; - for (unsigned i = 0; i < channels; ++i) - samplesOut = cics_[i].filter(out + i, in + i, inlen); - - return samplesOut; -} - -#endif diff --git a/common/resample/src/cic3.h b/common/resample/src/cic3.h deleted file mode 100644 index 2e1a727a..00000000 --- a/common/resample/src/cic3.h +++ /dev/null @@ -1,139 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef CIC3_H -#define CIC3_H - -#include "rshift16_round.h" -#include "subresampler.h" - -template -class Cic3Core { -public: - explicit Cic3Core(unsigned div = 1) { reset(div); } - unsigned div() const { return div_; } - std::size_t filter(short *out, short const *in, std::size_t inlen); - void reset(unsigned div); - - static double gain(unsigned div) { - return rshift16_round(-32768l * (div * div * div) * mulForDiv(div)) / -32768.0; - } - -private: - unsigned long sum1_; - unsigned long sum2_; - unsigned long sum3_; - unsigned long prev1_; - unsigned long prev2_; - unsigned div_; - unsigned nextdivn_; - - // trouble if div is too large, may be better to only support power of 2 div - static long mulForDiv(unsigned div) { return 0x10000 / (div * div * div); } -}; - -template -void Cic3Core::reset(unsigned div) { - sum3_ = sum2_ = sum1_ = 0; - prev2_ = prev1_ = 0; - div_ = div; - nextdivn_ = div; -} - -template -std::size_t Cic3Core::filter(short *out, short const *const in, std::size_t inlen) { - std::size_t const produced = (inlen + div_ - nextdivn_) / div_; - short const *s = in; - unsigned long sm1 = sum1_; - unsigned long sm2 = sum2_; - unsigned long sm3 = sum3_; - - if (inlen >= nextdivn_) { - long const mul = mulForDiv(div_); - unsigned divn = nextdivn_; - std::size_t n = produced; - - do { - do { - sm1 += static_cast(*s); - sm2 += sm1; - sm3 += sm2; - s += channels; - } while (--divn); - - unsigned long const out2 = sm3 - prev2_; - prev2_ = sm3; - *out = rshift16_round(static_cast(out2 - prev1_) * mul); - prev1_ = out2; - out += channels; - divn = div_; - sm3 = 0; - } while (--n); - - nextdivn_ = div_; - } - - { - unsigned divn = (in + inlen * channels - s) / channels; - nextdivn_ -= divn; - - while (divn--) { - sm1 += static_cast(*s); - sm2 += sm1; - sm3 += sm2; - s += channels; - } - } - - sum1_ = sm1; - sum2_ = sm2; - sum3_ = sm3; - - return produced; -} - -template -class Cic3 : public SubResampler { -public: - enum { MAX_DIV = 23 }; - explicit Cic3(unsigned div); - virtual std::size_t resample(short *out, short const *in, std::size_t inlen); - virtual unsigned mul() const { return 1; } - virtual unsigned div() const { return cics_[0].div(); } - static double gain(unsigned div) { return Cic3Core::gain(div); } - -private: - Cic3Core cics_[channels]; -}; - -template -Cic3::Cic3(unsigned div) { - for (unsigned i = 0; i < channels; ++i) - cics_[i].reset(div); -} - -template -std::size_t Cic3::resample(short *out, short const *in, std::size_t inlen) { - std::size_t samplesOut; - for (unsigned i = 0; i < channels; ++i) - samplesOut = cics_[i].filter(out + i, in + i, inlen); - - return samplesOut; -} - -#endif diff --git a/common/resample/src/cic4.h b/common/resample/src/cic4.h deleted file mode 100644 index 0f0559f2..00000000 --- a/common/resample/src/cic4.h +++ /dev/null @@ -1,194 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef CIC4_H -#define CIC4_H - -#include "rshift16_round.h" -#include "subresampler.h" - -template -class Cic4Core { -public: - explicit Cic4Core(unsigned div = 1) { reset(div); } - unsigned div() const { return div_; } - std::size_t filter(short *out, short const *in, std::size_t inlen); - void reset(unsigned div); - - static double gain(unsigned div) { - return rshift16_round(-32768l * (div * div * div * div) * mulForDiv(div)) / -32768.0; - } - -private: - enum { buf_len = 64 }; - unsigned long buf_[buf_len]; - unsigned long sum1_; - unsigned long sum2_; - unsigned long sum3_; - unsigned long sum4_; - unsigned long prev1_; - unsigned long prev2_; - unsigned long prev3_; - unsigned long prev4_; - unsigned div_; - unsigned bufpos_; - - // trouble if div is too large, may be better to only support power of 2 div - static long mulForDiv(unsigned div) { return 0x10000 / (div * div * div * div); } -}; - -template -void Cic4Core::reset(unsigned div) { - sum4_ = sum3_ = sum2_ = sum1_ = 0; - prev4_ = prev3_ = prev2_ = prev1_ = 0; - div_ = div; - bufpos_ = div - 1; -} - -template -std::size_t Cic4Core::filter(short *out, short const *const in, std::size_t inlen) { - std::size_t const produced = (inlen + div_ - (bufpos_ + 1)) / div_; - long const mul = mulForDiv(div_); - short const *s = in; - - unsigned long sm1 = sum1_; - unsigned long sm2 = sum2_; - unsigned long sm3 = sum3_; - unsigned long sm4 = sum4_; - unsigned long prv1 = prev1_; - unsigned long prv2 = prev2_; - unsigned long prv3 = prev3_; - unsigned long prv4 = prev4_; - - while (inlen >> 2) { - unsigned const end = inlen < buf_len ? inlen & ~3 : buf_len & ~3; - unsigned long *b = buf_; - unsigned n = end; - - do { - unsigned long s1 = sm1 += static_cast(s[0 * channels]); - sm1 += static_cast(s[1 * channels]); - unsigned long s2 = sm2 += s1; - sm2 += sm1; - unsigned long s3 = sm3 += s2; - sm3 += sm2; - b[0] = sm4 += s3; - b[1] = sm4 += sm3; - s1 = sm1 += static_cast(s[2 * channels]); - sm1 += static_cast(s[3 * channels]); - s2 = sm2 += s1; - sm2 += sm1; - s3 = sm3 += s2; - sm3 += sm2; - b[2] = sm4 += s3; - b[3] = sm4 += sm3; - s += 4 * channels; - b += 4; - } while (n -= 4); - - while (bufpos_ < end) { - unsigned long const out4 = buf_[bufpos_] - prv4; - prv4 = buf_[bufpos_]; - bufpos_ += div_; - - unsigned long const out3 = out4 - prv3; - prv3 = out4; - unsigned long const out2 = out3 - prv2; - prv2 = out3; - - *out = rshift16_round(static_cast(out2 - prv1) * mul); - prv1 = out2; - out += channels; - } - - bufpos_ -= end; - inlen -= end; - } - - if (inlen) { - unsigned n = inlen; - unsigned i = 0; - - do { - sm1 += static_cast(*s); - s += channels; - sm2 += sm1; - sm3 += sm2; - buf_[i++] = sm4 += sm3; - } while (--n); - - while (bufpos_ < inlen) { - unsigned long const out4 = buf_[bufpos_] - prv4; - prv4 = buf_[bufpos_]; - bufpos_ += div_; - - unsigned long const out3 = out4 - prv3; - prv3 = out4; - unsigned long const out2 = out3 - prv2; - prv2 = out3; - - *out = rshift16_round(static_cast(out2 - prv1) * mul); - prv1 = out2; - out += channels; - } - - bufpos_ -= inlen; - } - - sum1_ = sm1; - sum2_ = sm2; - sum3_ = sm3; - sum4_ = sm4; - prev1_ = prv1; - prev2_ = prv2; - prev3_ = prv3; - prev4_ = prv4; - - return produced; -} - -template -class Cic4 : public SubResampler { -public: - enum { MAX_DIV = 13 }; - explicit Cic4(unsigned div); - virtual std::size_t resample(short *out, short const *in, std::size_t inlen); - virtual unsigned mul() const { return 1; } - virtual unsigned div() const { return cics_[0].div(); } - static double gain(unsigned div) { return Cic4Core::gain(div); } - -private: - Cic4Core cics_[channels]; -}; - -template -Cic4::Cic4(unsigned div) { - for (unsigned i = 0; i < channels; ++i) - cics_[i].reset(div); -} - -template -std::size_t Cic4::resample(short *out, short const *in, std::size_t inlen) { - std::size_t samplesOut; - for (unsigned i = 0; i < channels; ++i) - samplesOut = cics_[i].filter(out + i, in + i, inlen); - - return samplesOut; -} - -#endif diff --git a/common/resample/src/hammingsinc.h b/common/resample/src/hammingsinc.h deleted file mode 100644 index 64216d16..00000000 --- a/common/resample/src/hammingsinc.h +++ /dev/null @@ -1,92 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef HAMMINGSINC_H -#define HAMMINGSINC_H - -#include "array.h" -#include "cic3.h" -#include "makesinckernel.h" -#include "polyphasefir.h" -#include "subresampler.h" -#include -#include -#include - -template -class HammingSinc : public SubResampler { -public: - enum { MUL = phases }; - typedef Cic3 Cic; - static float cicLimit() { return 4.2f; } - - class RollOff { - public: - unsigned const taps; - float const fc; - - RollOff(float rollOffStart, float rollOffWidth) - : taps(toTaps(rollOffWidth)), fc(toFc(rollOffStart, taps)) - { - } - - private: - static unsigned toTaps(float rollOffWidth) { - float widthTimesTaps = 3.0f; - return std::max(unsigned(std::ceil(widthTimesTaps / rollOffWidth)), 4u); - } - - static float toFc(float rollOffStart, int taps) { - float startToFcDeltaTimesTaps = 1.27f; - return startToFcDeltaTimesTaps / taps + rollOffStart; - } - }; - - HammingSinc(unsigned div, unsigned phaseLen, double fc) - : kernel_(phaseLen * phases) - , polyfir_(kernel_, phaseLen, div) - { - makeSincKernel(kernel_, phases, phaseLen, fc, hammingWin, 1.0); - } - - HammingSinc(unsigned div, RollOff ro, double gain) - : kernel_(ro.taps * phases) - , polyfir_(kernel_, ro.taps, div) - { - makeSincKernel(kernel_, phases, ro.taps, ro.fc, hammingWin, gain); - } - - virtual std::size_t resample(short *out, short const *in, std::size_t inlen) { - return polyfir_.filter(out, in, inlen); - } - - virtual void adjustDiv(unsigned div) { polyfir_.adjustDiv(div); } - virtual unsigned mul() const { return MUL; } - virtual unsigned div() const { return polyfir_.div(); } - -private: - Array const kernel_; - PolyphaseFir polyfir_; - - static double hammingWin(long i, long M) { - double pi = 3.14159265358979323846; - return 0.53836 - 0.46164 * std::cos(2 * pi * i / M); - } -}; - -#endif diff --git a/common/resample/src/i0.cpp b/common/resample/src/i0.cpp deleted file mode 100644 index d70f1f10..00000000 --- a/common/resample/src/i0.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#include "i0.h" - -double i0(double x) { - double sum = 1.0; - double xpm_dmfac = 1.0; - double m = 1.0; - - x = 0.25 * x * x; - - for (int n = 16; n--;) { - xpm_dmfac *= x / (m * m); - sum += xpm_dmfac; - m += 1.0; - } - - return sum; -} diff --git a/common/resample/src/i0.h b/common/resample/src/i0.h deleted file mode 100644 index a5a03fd7..00000000 --- a/common/resample/src/i0.h +++ /dev/null @@ -1,24 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef I0_H -#define I0_H - -double i0(double x); - -#endif diff --git a/common/resample/src/kaiser50sinc.cpp b/common/resample/src/kaiser50sinc.cpp deleted file mode 100644 index 28fc8eab..00000000 --- a/common/resample/src/kaiser50sinc.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008-2009 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#include "kaiser50sinc.h" -#include "i0.h" -#include - -double kaiser50SincWin(long const n, long const M) { - double const beta = 4.62; - static double const i0beta_rec = 1.0 / i0(beta); - - double x = static_cast(n * 2) / M - 1.0; - x = x * x; - x = beta * std::sqrt(1.0 - x); - - return i0(x) * i0beta_rec; -} diff --git a/common/resample/src/kaiser50sinc.h b/common/resample/src/kaiser50sinc.h deleted file mode 100644 index dd5138f2..00000000 --- a/common/resample/src/kaiser50sinc.h +++ /dev/null @@ -1,89 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008-2009 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef KAISER50SINC_H -#define KAISER50SINC_H - -#include "array.h" -#include "cic3.h" -#include "makesinckernel.h" -#include "polyphasefir.h" -#include "subresampler.h" -#include -#include -#include - -double kaiser50SincWin(long n, long M); - -template -class Kaiser50Sinc : public SubResampler { -public: - enum { MUL = phases }; - typedef Cic3 Cic; - static float cicLimit() { return 4.2f; } - - class RollOff { - public: - unsigned const taps; - float const fc; - - RollOff(float rollOffStart, float rollOffWidth) - : taps(toTaps(rollOffWidth)), fc(toFc(rollOffStart, taps)) - { - } - - private: - static unsigned toTaps(float rollOffWidth) { - float widthTimesTaps = 2.715f; - return std::max(unsigned(std::ceil(widthTimesTaps / rollOffWidth)), 4u); - } - - static float toFc(float rollOffStart, int taps) { - float startToFcDeltaTimesTaps = 1.2f; - return startToFcDeltaTimesTaps / taps + rollOffStart; - } - }; - - Kaiser50Sinc(unsigned div, unsigned phaseLen, double fc) - : kernel_(phaseLen * phases) - , polyfir_(kernel_, phaseLen, div) - { - makeSincKernel(kernel_, phases, phaseLen, fc, kaiser50SincWin, 1.0); - } - - Kaiser50Sinc(unsigned div, RollOff ro, double gain) - : kernel_(ro.taps * phases) - , polyfir_(kernel_, ro.taps, div) - { - makeSincKernel(kernel_, phases, ro.taps, ro.fc, kaiser50SincWin, gain); - } - - virtual std::size_t resample(short *out, short const *in, std::size_t inlen) { - return polyfir_.filter(out, in, inlen); - } - - virtual void adjustDiv(unsigned div) { polyfir_.adjustDiv(div); } - virtual unsigned mul() const { return MUL; } - virtual unsigned div() const { return polyfir_.div(); } - -private: - Array const kernel_; - PolyphaseFir polyfir_; -}; - -#endif diff --git a/common/resample/src/kaiser70sinc.cpp b/common/resample/src/kaiser70sinc.cpp deleted file mode 100644 index 639b318d..00000000 --- a/common/resample/src/kaiser70sinc.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008-2009 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#include "kaiser70sinc.h" -#include "i0.h" -#include - -double kaiser70SincWin(long const n, long const M) { - double const beta = 6.9; - static double const i0beta_rec = 1.0 / i0(beta); - - double x = static_cast(n * 2) / M - 1.0; - x = x * x; - x = beta * std::sqrt(1.0 - x); - - return i0(x) * i0beta_rec; -} diff --git a/common/resample/src/kaiser70sinc.h b/common/resample/src/kaiser70sinc.h deleted file mode 100644 index 2af3f707..00000000 --- a/common/resample/src/kaiser70sinc.h +++ /dev/null @@ -1,89 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008-2009 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef KAISER70SINC_H -#define KAISER70SINC_H - -#include "array.h" -#include "cic4.h" -#include "makesinckernel.h" -#include "polyphasefir.h" -#include "subresampler.h" -#include -#include -#include - -double kaiser70SincWin(long n, long M); - -template -class Kaiser70Sinc : public SubResampler { -public: - enum { MUL = phases }; - typedef Cic4 Cic; - static float cicLimit() { return 4.7f; } - - class RollOff { - public: - unsigned const taps; - float const fc; - - RollOff(float rollOffStart, float rollOffWidth) - : taps(toTaps(rollOffWidth)), fc(toFc(rollOffStart, taps)) - { - } - - private: - static unsigned toTaps(float rollOffWidth) { - float widthTimesTaps = 3.75f; - return std::max(unsigned(std::ceil(widthTimesTaps / rollOffWidth)), 4u); - } - - static float toFc(float rollOffStart, int taps) { - float startToFcDeltaTimesTaps = 1.5f; - return startToFcDeltaTimesTaps / taps + rollOffStart; - } - }; - - Kaiser70Sinc(unsigned div, unsigned phaseLen, double fc) - : kernel_(phaseLen * phases) - , polyfir_(kernel_, phaseLen, div) - { - makeSincKernel(kernel_, phases, phaseLen, fc, kaiser70SincWin, 1.0); - } - - Kaiser70Sinc(unsigned div, RollOff ro, double gain) - : kernel_(ro.taps * phases) - , polyfir_(kernel_, ro.taps, div) - { - makeSincKernel(kernel_, phases, ro.taps, ro.fc, kaiser70SincWin, gain); - } - - virtual std::size_t resample(short *out, short const *in, std::size_t inlen) { - return polyfir_.filter(out, in, inlen); - } - - virtual void adjustDiv(unsigned div) { polyfir_.adjustDiv(div); } - virtual unsigned mul() const { return MUL; } - virtual unsigned div() const { return polyfir_.div(); } - -private: - Array const kernel_; - PolyphaseFir polyfir_; -}; - -#endif diff --git a/common/resample/src/linint.h b/common/resample/src/linint.h deleted file mode 100644 index 744e7f48..00000000 --- a/common/resample/src/linint.h +++ /dev/null @@ -1,144 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef LININT_H -#define LININT_H - -#include "../resampler.h" -#include "rshift16_round.h" -#include "u48div.h" -#include - -template -class LinintCore { -public: - LinintCore() { *this = LinintCore(1, 1); } - LinintCore(long inRate, long outRate); - void adjustRate(long inRate, long outRate) { ratio_ = calcRatio(inRate, outRate); } - void exactRatio(unsigned long &mul, unsigned long &div) const { mul = 0x10000; div = ratio_; } - - std::size_t maxOut(std::size_t inlen) const { - return inlen ? u48div(inlen - 1, 0xffff, ratio_) + 1 : 0; - } - - std::size_t resample(short *out, short const *in, std::size_t inlen); - -private: - unsigned long ratio_; - std::size_t pos_; - unsigned fracPos_; - int prevSample_; - - static unsigned long calcRatio(long inRate, long outRate) { - return static_cast((double(inRate) / outRate) * 0x10000 + 0.5); - } -}; - -template -LinintCore::LinintCore(long inRate, long outRate) -: ratio_(calcRatio(inRate, outRate)) -, pos_((ratio_ >> 16) + 1) -, fracPos_(ratio_ & 0xffff) -, prevSample_(0) -{ -} - -template -std::size_t LinintCore::resample( - short *const out, short const *const in, std::size_t const inlen) { - if (pos_ < inlen) { - unsigned long const ratio = ratio_; - unsigned fracPos = fracPos_; - short *o = out; - std::ptrdiff_t pos = pos_; - while (pos == 0) { - long const lhs = prevSample_; - long const rhs = in[0]; - *o = lhs + rshift16_round((rhs - lhs) * static_cast(fracPos)); - o += channels; - - unsigned long const nfrac = fracPos + ratio; - fracPos = nfrac & 0xffff; - pos += nfrac >> 16; - } - - short const *const inend = in + inlen * channels; - pos -= static_cast(inlen); - while (pos < 0) { - long const lhs = inend[(pos-1) * channels]; - long const rhs = inend[ pos * channels]; - *o = lhs + rshift16_round((rhs - lhs) * static_cast(fracPos)); - o += channels; - - unsigned long const nfrac = fracPos + ratio; - fracPos = nfrac & 0xffff; - pos += nfrac >> 16; - } - - prevSample_ = inend[-channels]; - pos_ = pos; - fracPos_ = fracPos; - - return (o - out) / channels; - } - - return 0; -} - -template -class Linint : public Resampler { -public: - Linint(long inRate, long outRate); - virtual void adjustRate(long inRate, long outRate); - - virtual void exactRatio(unsigned long &mul, unsigned long &div) const { - cores_[0].exactRatio(mul, div); - } - - virtual std::size_t maxOut(std::size_t inlen) const { return cores_[0].maxOut(inlen); } - virtual std::size_t resample(short *out, short const *in, std::size_t inlen); - -private: - LinintCore cores_[channels]; -}; - -template -Linint::Linint(long inRate, long outRate) -: Resampler(inRate, outRate) -{ - for (int i = 0; i < channels; ++i) - cores_[i] = LinintCore(inRate, outRate); -} - -template -void Linint::adjustRate(long inRate, long outRate) { - setRate(inRate, outRate); - for (int i = 0; i < channels; ++i) - cores_[i].adjustRate(inRate, outRate); -} - -template -std::size_t Linint::resample(short *out, short const *in, std::size_t inlen) { - std::size_t outlen = 0; - for (int i = 0; i < channels; ++i) - outlen = cores_[i].resample(out + i, in + i, inlen); - - return outlen; -} - -#endif diff --git a/common/resample/src/makesinckernel.cpp b/common/resample/src/makesinckernel.cpp deleted file mode 100644 index 5a00eac5..00000000 --- a/common/resample/src/makesinckernel.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#include "makesinckernel.h" -#include "array.h" -#include - -void makeSincKernel(short *const kernel, int const phases, int const phaseLen, double fc, - double (*const win)(long m, long M), double const maxAllowedGain) -{ - double const PI = 3.14159265358979323846; - fc /= phases; - - /*{ - Array const dkernel(phaseLen * phases); - long const M = long(phaseLen) * phases - 1; - for (long i = 0; i < M + 1; ++i) { - double sinc = i * 2 == M - ? PI * fc - : std::sin(PI * fc * (i * 2 - M)) / (i * 2 - M); - std::size_t pos = std::size_t((phases - (i % phases)) % phases) * phaseLen - + i / phases; - dkernel[pos] = win(i, M) * sinc; - } - - double maxabsgain = 0; - for (int ph = 0; ph < phases; ++ph) { - double gain = 0; - double absgain = 0; - for (int i = 0; i < phaseLen; ++i) { - gain += dkernel[std::size_t(ph) * phaseLen + i]; - absgain += std::abs(dkernel[std::size_t(ph) * phaseLen + i]); - } - - gain = 1.0 / gain; - // Per phase normalization to avoid DC fluctuations. - for (int i = 0; i < phaseLen; ++i) - dkernel[std::size_t(ph) * phaseLen + i] *= gain; - - absgain *= gain; - if (absgain > maxabsgain) - maxabsgain = absgain; - } - - double gain = (0x10000 - 0.5 * phaseLen) * maxAllowedGain / maxabsgain; - for (long i = 0; i < M + 1; ++i) - kernel[i] = std::floor(dkernel[i] * gain + 0.5); - }*/ - - // The following should be equivalent to the more concise version above - // Some polyphase FIRs used are huge enough that this seemed worthwile. - long const M = long(phaseLen) * phases - 1; - Array const dkernel(M / 2 + 1); - - { - double *dk = dkernel; - for (int ph = 0; ph < phases; ++ph) { - for (long i = ph; i < M / 2 + 1; i += phases) { - double sinc = i * 2 == M - ? PI * fc - : std::sin(PI * fc * (i * 2 - M)) / (i * 2 - M); - *dk++ = win(i, M) * sinc; - } - } - } - - double maxabsgain = 0.0; - - { - double *dkp1 = dkernel; - double *dkp2 = dkernel + M / 2; - for (int ph = 0; ph < (phases + 1) / 2; ++ph) { - double gain = 0.0; - double absgain = 0.0; - - { - double const *kp1 = dkp1; - double const *kp2 = dkp2; - long i = ph; - for (; i < M / 2 + 1; i += phases) { - gain += *kp1; - absgain += std::abs(*kp1++); - } - for (; i < M + 1; i += phases) { - gain += *kp2; - absgain += std::abs(*kp2--); - } - } - - gain = 1.0 / gain; - - long i = ph; - for (; i < M / 2 + 1; i += phases) - *dkp1++ *= gain; - - if (dkp1 < dkp2) { - for (; i < M + 1; i += phases) - *dkp2-- *= gain; - } - - absgain *= gain; - if (absgain > maxabsgain) - maxabsgain = absgain; - } - } - - double const gain = (0x10000 - 0.5 * phaseLen) * maxAllowedGain / maxabsgain; - double const *dk = dkernel; - for (int ph = 0; ph < phases; ++ph) { - short *k = kernel + std::size_t((phases - ph) % phases) * phaseLen; - short *km = kernel + phaseLen - 1 + std::size_t((ph + 1) % phases) * phaseLen; - for (long i = ph; i < M / 2 + 1; i += phases) - *km-- = *k++ = static_cast(std::floor(*dk++ * gain + 0.5)); - } -} diff --git a/common/resample/src/makesinckernel.h b/common/resample/src/makesinckernel.h deleted file mode 100644 index 079132d4..00000000 --- a/common/resample/src/makesinckernel.h +++ /dev/null @@ -1,25 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef MAKE_SINC_KERNEL_H -#define MAKE_SINC_KERNEL_H - -void makeSincKernel(short *kernel, int phases, int phaseLen, - double fc, double (*win)(long m, long M), double gain); - -#endif diff --git a/common/resample/src/polyphasefir.h b/common/resample/src/polyphasefir.h deleted file mode 100644 index 38e4ec65..00000000 --- a/common/resample/src/polyphasefir.h +++ /dev/null @@ -1,176 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef POLYPHASEFIR_H -#define POLYPHASEFIR_H - -#include "array.h" -#include "rshift16_round.h" -#include -#include - -template -class PolyphaseFir { -public: - PolyphaseFir(short const *kernel, std::size_t phaseLen, unsigned div); - std::size_t filter(short *out, short const *in, std::size_t inlen); - void adjustDiv(unsigned div) { div_ = div; } - unsigned div() const { return div_; } - -private: - short const *const kernel_; - Array const prevbuf_; - unsigned div_; - std::size_t x_; -}; - -template -PolyphaseFir::PolyphaseFir(short const *kernel, - std::size_t phaseLen, - unsigned div) -: kernel_(kernel) -, prevbuf_(phaseLen * channels) -, div_(div) -, x_(0) -{ - std::fill(prevbuf_.get(), prevbuf_.get() + prevbuf_.size(), 0); -} - -template -std::size_t PolyphaseFir::filter(short *out, - short const *const in, - std::size_t inlen) -{ - if (!kernel_ || !inlen) - return 0; - - // The gist of what happens here is given by the commented pseudo-code below. - // Note that the order of the kernel elements has been changed for efficiency in - // the real implementation. - /*for (std::size_t x = 0; x < inlen + M; ++x) { - int const end = x < inlen ? M + 1 : inlen + M - x; - int j = x < M ? M - x : 0; - // adjust j so we do not start on a virtual 0 sample - j += (phases - (x - M + j) % phases) % phases; - - for (; j < end; j += phases) { - buffer[x] += kernel_[j] * start[(x - M + j) / phases]; - } - }*/ - - // Slightly more optimized version. - /*for (std::size_t x = 0; x < inlen + M; ++x) { - int const end = x < inlen ? M + 1 : inlen + M - x; - int j = x < M ? M - x : 0; - // adjust j so we do not start on a virtual 0 sample - j += (phases - (x - M + j) % phases) % phases; - short const *k = kernel_ + (j % phases) * phaseLen + j / phases; - short const *s = start + (x - M + j) / phases; - int n = ((end - j) + phases - 1) / phases; - - do { - buffer[x] += *k++ * *s++; - } while (--n); - }*/ - - std::size_t const phaseLen = prevbuf_.size() / channels; - std::size_t const M = phaseLen * phases - 1; - inlen *= phases; - std::size_t x = x_; - - for (; x < (M < inlen ? M : inlen); x += div_) { - for (int c = 0; c < channels; ++c) { - // adjust phase so we do not start on a virtual 0 sample - short const *k = kernel_ + ((x + 1) % phases) * phaseLen; - short const *s = prevbuf_ + phaseLen * channels + c; - long acc = 0; - std::size_t n = phaseLen * channels - (x / phases + 1) * channels; - - for (; n; n -= channels) - acc += *k++ * *(s-n); - - n = (x / phases + 1) * channels; - s = in + n + c; - - do { - acc += *k++ * *(s-n); - } while (n -= channels); - - *out++ = rshift16_round(acc); - } - } - - // We could easily get rid of the division and modulus here by updating the - // k and s pointers incrementally. However, we currently only use powers of 2 - // and we would end up referencing more variables which often compiles to bad - // code on x86, which is why I'm also hesitant to get rid of the template arguments. - for (; x < inlen; x += div_) { - for (int c = 0; c < channels-1; c += 2) { - // adjust phase so we do not start on a virtual 0 sample - short const *k = kernel_ + ((x + 1) % phases) * phaseLen; - short const *const s = in + (x / phases + 1) * channels + c; - long accl = 0, accr = 0; - std::ptrdiff_t i = -static_cast(phaseLen * channels); - do { - accl += *k * s[i ]; - accr += *k * s[i+1]; - ++k; - } while (i += channels); - - out[0] = rshift16_round(accl); - out[1] = rshift16_round(accr); - out += 2; - } - - if (channels & 1) { - // adjust phase so we do not start on a virtual 0 sample - short const *k = kernel_ + ((x + 1) % phases) * phaseLen; - short const *const s = in + (x / phases + 1) * channels + channels-1; - long acc = 0; - std::ptrdiff_t i = -static_cast(phaseLen * channels); - do { - acc += *k++ * s[i]; - } while (i += channels); - - *out++ = rshift16_round(acc); - } - } - - std::size_t const produced = (x - x_) / div_; - x_ = x - inlen; - inlen /= phases; - - { - short *p = prevbuf_; - short const *s = in + (inlen - phaseLen) * channels; - std::size_t n = phaseLen; - if (inlen < phaseLen) { - std::size_t const i = phaseLen - inlen; - std::memmove(p, p + inlen * channels, i * channels * sizeof *p); - p += i * channels; - n -= i; - s = in; - } - - std::memcpy(p, s, n * channels * sizeof *p); - } - - return produced; -} - -#endif diff --git a/common/resample/src/rectsinc.h b/common/resample/src/rectsinc.h deleted file mode 100644 index 3286558b..00000000 --- a/common/resample/src/rectsinc.h +++ /dev/null @@ -1,89 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef RECTSINC_H -#define RECTSINC_H - -#include "array.h" -#include "cic2.h" -#include "makesinckernel.h" -#include "polyphasefir.h" -#include "subresampler.h" -#include -#include -#include - -template -class RectSinc : public SubResampler { -public: - enum { MUL = phases }; - typedef Cic2 Cic; - static float cicLimit() { return 2.0f; } - - class RollOff { - public: - unsigned const taps; - float const fc; - - RollOff(float rollOffStart, float rollOffWidth) - : taps(toTaps(rollOffWidth)), fc(toFc(rollOffStart, taps)) - { - } - - private: - static unsigned toTaps(float rollOffWidth) { - float widthTimesTaps = 0.9f; - return std::max(unsigned(std::ceil(widthTimesTaps / rollOffWidth)), 4u); - } - - static float toFc(float rollOffStart, int taps) { - float startToFcDeltaTimesTaps = 0.43f; - return startToFcDeltaTimesTaps / taps + rollOffStart; - } - }; - - RectSinc(unsigned div, unsigned phaseLen, double fc) - : kernel_(phaseLen * phases) - , polyfir_(kernel_, phaseLen, div) - { - makeSincKernel(kernel_, phases, phaseLen, fc, rectWin, 1.0); - } - - RectSinc(unsigned div, RollOff ro, double gain) - : kernel_(ro.taps * phases) - , polyfir_(kernel_, ro.taps, div) - { - makeSincKernel(kernel_, phases, ro.taps, ro.fc, rectWin, gain); - } - - virtual std::size_t resample(short *out, short const *in, std::size_t inlen) { - return polyfir_.filter(out, in, inlen); - } - - virtual void adjustDiv(unsigned div) { polyfir_.adjustDiv(div); } - virtual unsigned mul() const { return MUL; } - virtual unsigned div() const { return polyfir_.div(); } - -private: - Array const kernel_; - PolyphaseFir polyfir_; - - static double rectWin(long /*i*/, long /*M*/) { return 1; } -}; - -#endif diff --git a/common/resample/src/resamplerinfo.cpp b/common/resample/src/resamplerinfo.cpp deleted file mode 100644 index 375fb139..00000000 --- a/common/resample/src/resamplerinfo.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#include "../resamplerinfo.h" -#include "chainresampler.h" -#include "kaiser50sinc.h" -#include "kaiser70sinc.h" -// #include "hammingsinc.h" -// #include "blackmansinc.h" -#include "rectsinc.h" -#include "linint.h" - -static Resampler * createLinint(long inRate, long outRate, std::size_t ) { - return new Linint(inRate, outRate); -} - -ResamplerInfo const ResamplerInfo::resamplers_[] = { - { "Fast", createLinint }, - { "High quality (polyphase FIR)", ChainResampler::create }, -// { "Hamming windowed sinc (~50 dB SNR)", ChainResampler::create }, -// { "Blackman windowed sinc (~70 dB SNR)", ChainResampler::create }, - { "Very high quality (polyphase FIR)", ChainResampler::create }, - { "Highest quality (polyphase FIR)", ChainResampler::create }, -}; - -std::size_t const ResamplerInfo::num_ = - sizeof ResamplerInfo::resamplers_ / sizeof *ResamplerInfo::resamplers_; diff --git a/common/resample/src/rshift16_round.h b/common/resample/src/rshift16_round.h deleted file mode 100644 index 9065b9bd..00000000 --- a/common/resample/src/rshift16_round.h +++ /dev/null @@ -1,33 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef RSHIFT16_ROUND_H -#define RSHIFT16_ROUND_H - -// negative shift is not defined in c++98 -#ifdef NO_NEGATIVE_SHIFT -inline long rshift16_round(long const l) { - return l < 0 ? -((-l + 0x8000) >> 16) : (l + 0x8000) >> 16; -} -#else -inline long rshift16_round(long l) { - return (l + 0x8000) >> 16; -} -#endif - -#endif diff --git a/common/resample/src/subresampler.h b/common/resample/src/subresampler.h deleted file mode 100644 index 2d77388b..00000000 --- a/common/resample/src/subresampler.h +++ /dev/null @@ -1,33 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef SUBRESAMPLER_H -#define SUBRESAMPLER_H - -#include - -class SubResampler { -public: - virtual ~SubResampler() {} - virtual std::size_t resample(short *out, short const *in, std::size_t inlen) = 0; - virtual unsigned mul() const = 0; - virtual unsigned div() const = 0; - virtual void adjustDiv(unsigned /*div*/) {} -}; - -#endif diff --git a/common/resample/src/u48div.cpp b/common/resample/src/u48div.cpp deleted file mode 100644 index ac9d2e37..00000000 --- a/common/resample/src/u48div.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#include "u48div.h" -#include - -unsigned long u48div(unsigned long num1, unsigned num2, unsigned long const den) { - unsigned long res = 0; - unsigned s = 16; - - do { - if (num1 < 0x10000) { - num1 <<= s; - num1 |= num2 & ((1 << s) - 1); - s = 0; - } else { - if (num1 < 0x1000000) { - unsigned const maxs = std::min(s, 8u); - num1 <<= maxs; - num1 |= (num2 >> (s - maxs)) & ((1 << maxs) - 1); - s -= maxs; - } - if (num1 < 0x10000000) { - unsigned const maxs = std::min(s, 4u); - num1 <<= maxs; - num1 |= (num2 >> (s - maxs)) & ((1 << maxs) - 1); - s -= maxs; - } - - while (num1 < den && s) { - num1 <<= 1; // if this overflows we're screwed - num1 |= num2 >> (s - 1) & 1; - s -= 1; - } - } - - res += (num1 / den) << s; - num1 = (num1 % den); - } while (s); - - return res; -} diff --git a/common/resample/src/u48div.h b/common/resample/src/u48div.h deleted file mode 100644 index b27c8894..00000000 --- a/common/resample/src/u48div.h +++ /dev/null @@ -1,24 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef U48DIV_H -#define U48DIV_H - -unsigned long u48div(unsigned long numeratorLow, unsigned numeratorHigh, unsigned long denominator); - -#endif diff --git a/common/resample/src/upsampler.h b/common/resample/src/upsampler.h deleted file mode 100644 index 312ebbce..00000000 --- a/common/resample/src/upsampler.h +++ /dev/null @@ -1,53 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef UPSAMPLER_H -#define UPSAMPLER_H - -#include "subresampler.h" -#include - -template -class Upsampler : public SubResampler { -public: - explicit Upsampler(unsigned mul) : mul_(mul) {} - virtual std::size_t resample(short *out, short const *in, std::size_t inlen); - virtual unsigned mul() const { return mul_; } - virtual unsigned div() const { return 1; } - -private: - unsigned mul_; -}; - -template -std::size_t Upsampler::resample(short *out, short const *in, std::size_t const inlen) { - unsigned const mul = mul_; - if (std::size_t n = inlen) { - std::memset(out, 0, inlen * mul * channels * sizeof *out); - - do { - std::memcpy(out, in, channels * sizeof *out); - in += channels; - out += mul * channels; - } while (--n); - } - - return inlen * mul; -} - -#endif diff --git a/common/ringbuffer.h b/common/ringbuffer.h deleted file mode 100644 index 0ed77206..00000000 --- a/common/ringbuffer.h +++ /dev/null @@ -1,109 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef RINGBUFFER_H -#define RINGBUFFER_H - -#include "array.h" -#include -#include -#include - -template -class RingBuffer { -public: - explicit RingBuffer(std::size_t size = 0) - : endpos_(0), rpos_(0), wpos_(0) - { - reset(size); - } - - void reset(std::size_t size); - - void clear() { - wpos_ = rpos_ = 0; - } - - void fill(T value); - void read(T *out, std::size_t num); - void write(T const *in, std::size_t num); - - std::size_t avail() const { - return (wpos_ < rpos_ ? 0 : endpos_) + rpos_ - wpos_ - 1; - } - - std::size_t used() const { - return (wpos_ < rpos_ ? endpos_ : 0) + wpos_ - rpos_; - } - - std::size_t size() const { - return endpos_ - 1; - } - -private: - Array buf_; - std::size_t endpos_; - std::size_t rpos_; - std::size_t wpos_; -}; - -template -void RingBuffer::reset(std::size_t size) { - endpos_ = size + 1; - rpos_ = wpos_ = 0; - buf_.reset(size ? endpos_ : 0); -} - -template -void RingBuffer::fill(T value) { - std::fill(buf_.get(), buf_.get() + buf_.size(), value); - rpos_ = 0; - wpos_ = endpos_ - 1; -} - -template -void RingBuffer::read(T *out, std::size_t num) { - if (rpos_ + num > endpos_) { - std::size_t const n = endpos_ - rpos_; - std::memcpy(out, buf_ + rpos_, n * sizeof *out); - rpos_ = 0; - num -= n; - out += n; - } - - std::memcpy(out, buf_ + rpos_, num * sizeof *out); - if ((rpos_ += num) == endpos_) - rpos_ = 0; -} - -template -void RingBuffer::write(T const *in, std::size_t num) { - if (wpos_ + num > endpos_) { - std::size_t const n = endpos_ - wpos_; - std::memcpy(buf_ + wpos_, in, n * sizeof *buf_); - wpos_ = 0; - num -= n; - in += n; - } - - std::memcpy(buf_ + wpos_, in, num * sizeof *buf_); - if ((wpos_ += num) == endpos_) - wpos_ = 0; -} - -#endif diff --git a/common/scoped_ptr.h b/common/scoped_ptr.h deleted file mode 100644 index 0b3b585f..00000000 --- a/common/scoped_ptr.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef SCOPED_PTR_H -#define SCOPED_PTR_H - -#include "transfer_ptr.h" -#include "uncopyable.h" - -template -class scoped_ptr : Uncopyable { -public: - explicit scoped_ptr(T *p = 0) : p_(p) {} - template explicit scoped_ptr(transfer_ptr p) : p_(p.release()) {} - ~scoped_ptr() { Deleter::del(p_); } - T * get() const { return p_; } - void reset(T *p = 0) { Deleter::del(p_); p_ = p; } - T & operator*() const { return *p_; } - T * operator->() const { return p_; } - operator bool() const { return p_; } - - template - scoped_ptr & operator=(transfer_ptr p) { - reset(p.release()); - return *this; - } - -private: - T *p_; -}; - -#endif diff --git a/common/skipsched.cpp b/common/skipsched.cpp deleted file mode 100644 index 0f7268c8..00000000 --- a/common/skipsched.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#include "skipsched.h" - -bool SkipSched::skipNext(bool skip) { - if (skipped_) { - if (skipped_ < skippedmax_ / 2) - skip = true; - else - skipped_ = skip = 0; - } else if (skip) { - skippedmax_ += skippedmax_ / 2 < 8; - } else if (skippedmax_ / 2) - --skippedmax_; - - skipped_ += skip; - - return skip; -} diff --git a/common/skipsched.h b/common/skipsched.h deleted file mode 100644 index 1a117594..00000000 --- a/common/skipsched.h +++ /dev/null @@ -1,32 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef SKIPSCHED_H -#define SKIPSCHED_H - -class SkipSched { -public: - SkipSched() : skipped_(0), skippedmax_(2 - 1) {} - bool skipNext(bool wantskip); - -private: - unsigned skipped_; - unsigned skippedmax_; -}; - -#endif diff --git a/common/transfer_ptr.h b/common/transfer_ptr.h deleted file mode 100644 index 111d9d80..00000000 --- a/common/transfer_ptr.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef TRANSFER_PTR_H -#define TRANSFER_PTR_H - -#include "defined_ptr.h" - -template -class transfer_ptr { -private: - struct released { T *p; explicit released(T *p) : p(p) {} }; -public: - explicit transfer_ptr(T *p = 0) : p_(p) {} - transfer_ptr(transfer_ptr &p) : p_(p.release()) {} - transfer_ptr(released r) : p_(r.p) {} - ~transfer_ptr() { Deleter::del(p_); } - T * get() const { return p_; } - T * release() { T *p = p_; p_ = 0; return p; } - operator released const () { return released(release()); } - T & operator*() const { return *p_; } - T * operator->() const { return p_; } - operator bool() const { return p_; } - -private: - T *p_; - transfer_ptr & operator=(transfer_ptr const &); -}; - -#endif diff --git a/common/uncopyable.h b/common/uncopyable.h deleted file mode 100644 index 259c5655..00000000 --- a/common/uncopyable.h +++ /dev/null @@ -1,30 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef UNCOPYABLE_H -#define UNCOPYABLE_H - -class Uncopyable { -protected: - Uncopyable() {} -private: - Uncopyable(Uncopyable const &); - Uncopyable& operator=(Uncopyable const &); -}; - -#endif diff --git a/common/usec.h b/common/usec.h deleted file mode 100644 index d0b59358..00000000 --- a/common/usec.h +++ /dev/null @@ -1,27 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef USEC_H -#define USEC_H - -typedef unsigned long usec_t; - -usec_t getusecs(); -void usecsleep(usec_t usecs); - -#endif diff --git a/common/videolink/rgb32conv.cpp b/common/videolink/rgb32conv.cpp deleted file mode 100644 index 2fa248e7..00000000 --- a/common/videolink/rgb32conv.cpp +++ /dev/null @@ -1,199 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#include "rgb32conv.h" -#include "array.h" -#include "gbint.h" -#include "videolink.h" -#include - -namespace { - -static bool isBigEndian() { - union { - gambatte::uint_least32_t ul32; - unsigned char uc[sizeof(gambatte::uint_least32_t)]; - } u; - u.ul32 = -0x10000; - return u.uc[0]; -} - -class Rgb32ToUyvy { -public: - Rgb32ToUyvy(); - void operator()(gambatte::uint_least32_t *d, std::ptrdiff_t dstPitch, - gambatte::uint_least32_t const *s, std::ptrdiff_t srcPitch, - unsigned w, unsigned h); - -private: - struct CacheUnit { - gambatte::uint_least32_t rgb32; - gambatte::uint_least32_t uyvy; - }; - - enum { cache_size = 0x100 }; - enum { cache_mask = cache_size - 1 }; - CacheUnit cache_[cache_size]; -}; - -Rgb32ToUyvy::Rgb32ToUyvy() { - if (isBigEndian()) { - CacheUnit c = { 0, 128ul << 24 | 16ul << 16 | 128u << 8 | 16 }; - std::fill(cache_, cache_ + cache_size, c); - } else { - CacheUnit c = { 0, 16ul << 24 | 128ul << 16 | 16 << 8 | 128 }; - std::fill(cache_, cache_ + cache_size, c); - } -} - -void Rgb32ToUyvy::operator()(gambatte::uint_least32_t *dst, - std::ptrdiff_t const dstPitch, - gambatte::uint_least32_t const *src, - std::ptrdiff_t const srcPitch, - unsigned const w, - unsigned h) -{ - while (h--) { - gambatte::uint_least32_t *d = dst; - gambatte::uint_least32_t const *s = src; - gambatte::uint_least32_t const *const sEnd = s + w - 1; - while (s < sEnd) { - if ((cache_[s[0] & cache_mask].rgb32 - s[0]) | (cache_[s[1] & cache_mask].rgb32 - s[1])) { - cache_[s[0] & cache_mask].rgb32 = s[0]; - cache_[s[1] & cache_mask].rgb32 = s[1]; - - unsigned long const r = (s[0] >> 16 & 0x000000FF) | (s[1] & 0x00FF0000); - unsigned long const g = (s[0] >> 8 & 0x000000FF) | (s[1] << 8 & 0x00FF0000); - unsigned long const b = (s[0] & 0x000000FF) | (s[1] << 16 & 0x00FF0000); - unsigned long const y = r * 66 + g * 129 + b * 25 + ( 16 * 256u + 128) * 0x00010001ul; - unsigned long const u = b * 112 - r * 38 - g * 74 + (128 * 256u + 128) * 0x00010001ul; - unsigned long const v = r * 112 - g * 94 - b * 18 + (128 * 256u + 128) * 0x00010001ul; - if (isBigEndian()) { - d[0] = cache_[s[0] & cache_mask].uyvy = (u << 16 & 0xFF000000) - | (y << 8 & 0x00FF0000) - | (v & 0x0000FF00) - | (y >> 8 & 0x000000FF); - d[1] = cache_[s[1] & cache_mask].uyvy = (u & 0xFF000000) - | (y >> 8 & 0x00FF0000) - | (v >> 16 & 0x0000FF00) - | y >> 24 ; - } else { - d[0] = cache_[s[0] & cache_mask].uyvy = (y << 16 & 0xFF000000) - | (v << 8 & 0x00FF0000) - | (y & 0x0000FF00) - | (u >> 8 & 0x000000FF); - d[1] = cache_[s[1] & cache_mask].uyvy = (y & 0xFF000000) - | (v >> 8 & 0x00FF0000) - | (y >> 16 & 0x0000FF00) - | u >> 24 ; - } - } else { - gambatte::uint_least32_t const s0 = s[0], s1 = s[1]; - d[0] = cache_[s0 & cache_mask].uyvy; - d[1] = cache_[s1 & cache_mask].uyvy; - } - - s += 2; - d += 2; - } - - src += srcPitch; - dst += dstPitch; - } -} - -static void rgb32ToRgb16(gambatte::uint_least16_t *d, - std::ptrdiff_t const dstPitch, - gambatte::uint_least32_t const *s, - std::ptrdiff_t const srcPitch, - unsigned const w, - unsigned h) -{ - do { - std::ptrdiff_t i = -static_cast(w); - s += w; - d += w; - - do { - d[i] = (s[i] >> 8 & 0xF800) | (s[i] & 0xFC00) >> 5 | (s[i] & 0xFF) >> 3; - } while (++i); - - s += srcPitch - static_cast(w); - d += dstPitch - static_cast(w); - } while (--h); -} - -class Rgb32ToUyvyLink : public VideoLink { -public: - Rgb32ToUyvyLink(unsigned width, unsigned height) - : inbuf_(static_cast(width) * height) - , width_(width) - , height_(height) - { - } - - virtual void * inBuf() const { return inbuf_; } - virtual std::ptrdiff_t inPitch() const { return width_; } - - virtual void draw(void *dst, std::ptrdiff_t dstPitch) { - rgb32ToUyvy_(static_cast(dst), dstPitch, - inbuf_, width_, width_, height_); - } - -private: - SimpleArray const inbuf_; - Rgb32ToUyvy rgb32ToUyvy_; - unsigned const width_; - unsigned const height_; -}; - -class Rgb32ToRgb16Link : public VideoLink { -public: - Rgb32ToRgb16Link(unsigned width, unsigned height) - : inbuf_(static_cast(width) * height) - , width_(width) - , height_(height) - { - } - - virtual void * inBuf() const { return inbuf_; } - virtual std::ptrdiff_t inPitch() const { return width_; } - - virtual void draw(void *dst, std::ptrdiff_t dstPitch) { - if (!inbuf_) - return; - - rgb32ToRgb16(static_cast(dst), dstPitch, - inbuf_, width_, width_, height_); - } - -private: - SimpleArray const inbuf_; - unsigned const width_; - unsigned const height_; -}; - -} // anon namespace - -VideoLink * Rgb32Conv::create(PixelFormat pf, unsigned width, unsigned height) { - switch (pf) { - case RGB16: return new Rgb32ToRgb16Link(width, height); - case UYVY: return new Rgb32ToUyvyLink(width, height); - default: return 0; - } -} diff --git a/common/videolink/rgb32conv.h b/common/videolink/rgb32conv.h deleted file mode 100644 index 36c4e199..00000000 --- a/common/videolink/rgb32conv.h +++ /dev/null @@ -1,30 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef RGB32CONV_H -#define RGB32CONV_H - -class VideoLink; - -class Rgb32Conv { -public: - enum PixelFormat { RGB32, RGB16, UYVY }; - static VideoLink * create(PixelFormat pf, unsigned width, unsigned height); -}; - -#endif diff --git a/common/videolink/vfilterinfo.cpp b/common/videolink/vfilterinfo.cpp deleted file mode 100644 index c848145d..00000000 --- a/common/videolink/vfilterinfo.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#include "vfilterinfo.h" -#include "vfilters/catrom2x.h" -#include "vfilters/catrom3x.h" -#include "vfilters/kreed2xsai.h" -#include "vfilters/maxsthq2x.h" -#include "vfilters/maxsthq3x.h" - -static VideoLink * createNone() { return 0; } - -template -static VideoLink * createT() { return new T; } - -#define VFINFO(handle, Type) { handle, Type::out_width, Type::out_height, createT } - -static VfilterInfo const vfinfos[] = { - { "None", VfilterInfo::in_width, VfilterInfo::in_height, createNone }, - VFINFO("Bicubic Catmull-Rom spline 2x", Catrom2x), - VFINFO("Bicubic Catmull-Rom spline 3x", Catrom3x), - VFINFO("Kreed's 2xSaI", Kreed2xSaI), - VFINFO("MaxSt's hq2x", MaxStHq2x), - VFINFO("MaxSt's hq3x", MaxStHq3x), -}; - -std::size_t VfilterInfo::numVfilters() { - return sizeof vfinfos / sizeof vfinfos[0]; -} - -VfilterInfo const & VfilterInfo::get(std::size_t n) { - return vfinfos[n]; -} diff --git a/common/videolink/vfilterinfo.h b/common/videolink/vfilterinfo.h deleted file mode 100644 index 6303b136..00000000 --- a/common/videolink/vfilterinfo.h +++ /dev/null @@ -1,39 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef VFILTERINFO_H -#define VFILTERINFO_H - -#include - -class VideoLink; - -struct VfilterInfo { - enum { in_width = 160 }; - enum { in_height = 144 }; - - char const *handle; - unsigned outWidth; - unsigned outHeight; - VideoLink * (*create)(); - - static VfilterInfo const & get(std::size_t n); - static std::size_t numVfilters(); -}; - -#endif diff --git a/common/videolink/vfilters/catrom2x.cpp b/common/videolink/vfilters/catrom2x.cpp deleted file mode 100644 index 97ebf046..00000000 --- a/common/videolink/vfilters/catrom2x.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#include "catrom2x.h" -#include - -namespace { - -enum { in_width = VfilterInfo::in_width }; -enum { in_height = VfilterInfo::in_height }; -enum { in_pitch = in_width + 3 }; - -struct Colorsum { - gambatte::uint_least32_t r, g, b; -}; - -static void mergeColumns(gambatte::uint_least32_t *dest, Colorsum const *sums) { - for (unsigned w = in_width; w--;) { - { - gambatte::uint_least32_t rsum = sums[1].r; - gambatte::uint_least32_t gsum = sums[1].g; - gambatte::uint_least32_t bsum = sums[1].b; - - if (rsum >= 0x80000000) rsum = 0; - if (gsum >= 0x80000000) gsum = 0; - if (bsum >= 0x80000000) bsum = 0; - - rsum <<= 12; - rsum += 0x008000; - gsum >>= 4; - gsum += 0x0080; - bsum += 0x0008; - bsum >>= 4; - - if (rsum > 0xFF0000) rsum = 0xFF0000; - if (gsum > 0x00FF00) gsum = 0x00FF00; - if (bsum > 0x0000FF) bsum = 0x0000FF; - - *dest++ = (rsum & 0xFF0000) | (gsum & 0x00FF00) | bsum; - } - - { - gambatte::uint_least32_t rsum = sums[1].r * 9; - gambatte::uint_least32_t gsum = sums[1].g * 9; - gambatte::uint_least32_t bsum = sums[1].b * 9; - - rsum -= sums[0].r; - gsum -= sums[0].g; - bsum -= sums[0].b; - - rsum += sums[2].r * 9; - gsum += sums[2].g * 9; - bsum += sums[2].b * 9; - - rsum -= sums[3].r; - gsum -= sums[3].g; - bsum -= sums[3].b; - - if (rsum >= 0x80000000) rsum = 0; - if (gsum >= 0x80000000) gsum = 0; - if (bsum >= 0x80000000) bsum = 0; - - rsum <<= 8; - rsum += 0x008000; - gsum >>= 8; - gsum += 0x000080; - bsum += 0x000080; - bsum >>= 8; - - if (rsum > 0xFF0000) rsum = 0xFF0000; - if (gsum > 0x00FF00) gsum = 0x00FF00; - if (bsum > 0x0000FF) bsum = 0x0000FF; - - *dest++ = (rsum & 0xFF0000) | (gsum & 0x00FF00) | bsum; - } - - ++sums; - } -} - -static void filter(gambatte::uint_least32_t *dline, - std::ptrdiff_t const pitch, - gambatte::uint_least32_t const *sline) -{ - Colorsum sums[in_pitch]; - for (unsigned h = in_height; h--;) { - { - gambatte::uint_least32_t const *s = sline; - Colorsum *sum = sums; - unsigned n = in_pitch; - while (n--) { - unsigned long pixel = *s; - sum->r = pixel >> 12 & 0x000FF0 ; - pixel <<= 4; - sum->g = pixel & 0x0FF000; - sum->b = pixel & 0x000FF0; - - ++s; - ++sum; - } - } - - mergeColumns(dline, sums); - dline += pitch; - - { - gambatte::uint_least32_t const *s = sline; - Colorsum *sum = sums; - unsigned n = in_pitch; - while (n--) { - unsigned long pixel = *s; - unsigned long rsum = (pixel >> 16) * 9; - unsigned long gsum = (pixel & 0x00FF00) * 9; - unsigned long bsum = (pixel & 0x0000FF) * 9; - - pixel = s[-1 * in_pitch]; - rsum -= pixel >> 16; - gsum -= pixel & 0x00FF00; - bsum -= pixel & 0x0000FF; - - pixel = s[1 * in_pitch]; - rsum += (pixel >> 16) * 9; - gsum += (pixel & 0x00FF00) * 9; - bsum += (pixel & 0x0000FF) * 9; - - pixel = s[2 * in_pitch]; - rsum -= pixel >> 16; - gsum -= pixel & 0x00FF00; - bsum -= pixel & 0x0000FF; - - sum->r = rsum; - sum->g = gsum; - sum->b = bsum; - - ++s; - ++sum; - } - } - - mergeColumns(dline, sums); - dline += pitch; - sline += in_pitch; - } -} - -} // anon namespace - -Catrom2x::Catrom2x() -: buffer_((in_height + 3UL) * in_pitch) -{ - std::fill_n(buffer_.get(), buffer_.size(), 0); -} - -void * Catrom2x::inBuf() const { - return buffer_ + in_pitch + 1; -} - -std::ptrdiff_t Catrom2x::inPitch() const { - return in_pitch; -} - -void Catrom2x::draw(void *dbuffer, std::ptrdiff_t pitch) { - ::filter(static_cast(dbuffer), pitch, buffer_ + in_pitch); -} diff --git a/common/videolink/vfilters/catrom2x.h b/common/videolink/vfilters/catrom2x.h deleted file mode 100644 index f1025f77..00000000 --- a/common/videolink/vfilters/catrom2x.h +++ /dev/null @@ -1,41 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef CATROM2X_H -#define CATROM2X_H - -#include "../videolink.h" -#include "../vfilterinfo.h" -#include "array.h" -#include "gbint.h" - -class Catrom2x : public VideoLink { -public: - enum { out_width = VfilterInfo::in_width * 2 }; - enum { out_height = VfilterInfo::in_height * 2 }; - - Catrom2x(); - virtual void * inBuf() const; - virtual std::ptrdiff_t inPitch() const; - virtual void draw(void *dst, std::ptrdiff_t dstpitch); - -private: - Array const buffer_; -}; - -#endif diff --git a/common/videolink/vfilters/catrom3x.cpp b/common/videolink/vfilters/catrom3x.cpp deleted file mode 100644 index 65f55e52..00000000 --- a/common/videolink/vfilters/catrom3x.cpp +++ /dev/null @@ -1,345 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#include "catrom3x.h" -#include - -namespace { - -enum { in_width = VfilterInfo::in_width }; -enum { in_height = VfilterInfo::in_height }; -enum { in_pitch = in_width + 3 }; - -struct Colorsum { - gambatte::uint_least32_t r, g, b; -}; - -static void mergeColumns(gambatte::uint_least32_t *dest, Colorsum const *sums) { - for (unsigned w = in_width; w--;) { - { - gambatte::uint_least32_t rsum = sums[1].r; - gambatte::uint_least32_t gsum = sums[1].g; - gambatte::uint_least32_t bsum = sums[1].b; - - if (rsum >= 0x80000000) { - rsum = 0; - } else if (rsum > 6869) { - rsum = 0xFF0000; - } else { - rsum *= 607; - rsum <<= 2; - rsum += 0x008000; - rsum &= 0xFF0000; - } - - if (gsum >= 0x80000000) { - gsum = 0; - } else if (gsum > 1758567) { - gsum = 0xFF00; - } else { - gsum *= 607; - gsum >>= 14; - gsum += 0x000080; - gsum &= 0x00FF00; - } - - if (bsum >= 0x80000000) { - bsum = 0; - } else if (bsum > 6869) { - bsum = 0xFF; - } else { - bsum *= 607; - bsum += 8192; - bsum >>= 14; - } - - /*rsum/=27; - rsum<<=8; - gsum/=27; - gsum<<=5; - bsum<<=4; - bsum+=27; - bsum/=54; - rsum+=0x008000; - gsum+=0x000080; - - if(rsum>0xFF0000) rsum=0xFF0000; - if(gsum>0x00FF00) gsum=0x00FF00; - if(bsum>0x0000FF) bsum=0x0000FF;*/ - - *dest++ = rsum/*&0xFF0000*/ | gsum/*&0x00FF00*/ | bsum; - } - { - gambatte::uint_least32_t rsum = sums[1].r * 21; - gambatte::uint_least32_t gsum = sums[1].g * 21; - gambatte::uint_least32_t bsum = sums[1].b * 21; - - rsum -= sums[0].r << 1; - gsum -= sums[0].g << 1; - bsum -= sums[0].b << 1; - - rsum += sums[2].r * 9; - gsum += sums[2].g * 9; - bsum += sums[2].b * 9; - - rsum -= sums[3].r; - gsum -= sums[3].g; - bsum -= sums[3].b; - - if (rsum >= 0x80000000) { - rsum = 0; - } else if (rsum > 185578) { - rsum = 0xFF0000; - } else { - rsum *= 719; - rsum >>= 3; - rsum += 0x008000; - rsum &= 0xFF0000; - } - - if (gsum >= 0x80000000) { - gsum = 0; - } else if (gsum > 47508223) { - gsum = 0x00FF00; - } else { - gsum >>= 8; - gsum *= 719; - gsum >>= 11; - gsum += 0x000080; - gsum &= 0x00FF00; - } - - if (bsum >= 0x80000000) { - bsum = 0; - } else if (bsum > 185578) { - bsum = 0x0000FF; - } else { - bsum *= 719; - bsum += 0x040000; - bsum >>= 19; - } - - /*rsum/=729; - rsum<<=8; - gsum/=729; - gsum<<=5; - bsum<<=4; - bsum+=729; - bsum/=1458; - rsum+=0x008000; - gsum+=0x000080; - - if(rsum>0xFF0000) rsum=0xFF0000; - if(gsum>0x00FF00) gsum=0x00FF00; - if(bsum>0x0000FF) bsum=0x0000FF;*/ - - *dest++ = rsum/*&0xFF0000*/ | gsum/*&0x00FF00*/ | bsum; - } - { - gambatte::uint_least32_t rsum = sums[1].r * 9; - gambatte::uint_least32_t gsum = sums[1].g * 9; - gambatte::uint_least32_t bsum = sums[1].b * 9; - - rsum -= sums[0].r; - gsum -= sums[0].g; - bsum -= sums[0].b; - - rsum += sums[2].r * 21; - gsum += sums[2].g * 21; - bsum += sums[2].b * 21; - - rsum -= sums[3].r << 1; - gsum -= sums[3].g << 1; - bsum -= sums[3].b << 1; - - if (rsum >= 0x80000000) { - rsum = 0; - } else if (rsum > 185578) { - rsum = 0xFF0000; - } else { - rsum *= 719; - rsum >>= 3; - rsum += 0x008000; - rsum &= 0xFF0000; - } - - if (gsum >= 0x80000000) { - gsum = 0; - } else if (gsum > 47508223) { - gsum = 0xFF00; - } else { - gsum >>= 8; - gsum *= 719; - gsum >>= 11; - gsum += 0x000080; - gsum &= 0x00FF00; - } - - if (bsum >= 0x80000000) { - bsum = 0; - } else if (bsum > 185578) { - bsum = 0x0000FF; - } else { - bsum *= 719; - bsum += 0x040000; - bsum >>= 19; - } - - /*rsum/=729; - rsum<<=8; - gsum/=729; - gsum<<=5; - bsum<<=4; - bsum+=729; - bsum/=1458; - rsum+=0x008000; - gsum+=0x000080; - - if(rsum>0xFF0000) rsum=0xFF0000; - if(gsum>0x00FF00) gsum=0x00FF00; - if(bsum>0x0000FF) bsum=0x0000FF;*/ - - *dest++ = rsum/*&0xFF0000*/ | gsum/*&0x00FF00*/ | bsum; - } - - ++sums; - } -} - -static void filter(gambatte::uint_least32_t *dline, - std::ptrdiff_t const pitch, - gambatte::uint_least32_t const *sline) -{ - Colorsum sums[in_pitch]; - for (unsigned h = in_height; h--;) { - { - gambatte::uint_least32_t const *s = sline; - Colorsum *sum = sums; - unsigned n = in_pitch; - while (n--) { - unsigned long const pixel = *s; - sum->r = (pixel >> 16) * 27; - sum->g = (pixel & 0x00FF00) * 27; - sum->b = (pixel & 0x0000FF) * 27; - - ++s; - ++sum; - } - } - - mergeColumns(dline, sums); - dline += pitch; - - { - gambatte::uint_least32_t const *s = sline; - Colorsum *sum = sums; - unsigned n = in_pitch; - while (n--) { - unsigned long pixel = *s; - unsigned long rsum = (pixel >> 16) * 21; - unsigned long gsum = (pixel & 0x00FF00) * 21; - unsigned long bsum = (pixel & 0x0000FF) * 21; - - pixel = s[-1 * in_pitch]; - rsum -= (pixel >> 16) << 1; - pixel <<= 1; - gsum -= pixel & 0x01FE00; - bsum -= pixel & 0x0001FE; - - pixel = s[1 * in_pitch]; - rsum += (pixel >> 16) * 9; - gsum += (pixel & 0x00FF00) * 9; - bsum += (pixel & 0x0000FF) * 9; - - pixel = s[2 * in_pitch]; - rsum -= pixel >> 16; - gsum -= pixel & 0x00FF00; - bsum -= pixel & 0x0000FF; - - sum->r = rsum; - sum->g = gsum; - sum->b = bsum; - - ++s; - ++sum; - } - } - - mergeColumns(dline, sums); - dline += pitch; - - { - gambatte::uint_least32_t const *s = sline; - Colorsum *sum = sums; - unsigned n = in_pitch; - while (n--) { - unsigned long pixel = *s; - unsigned long rsum = (pixel >> 16) * 9; - unsigned long gsum = (pixel & 0x00FF00) * 9; - unsigned long bsum = (pixel & 0x0000FF) * 9; - - pixel = s[-1 * in_pitch]; - rsum -= pixel >> 16; - gsum -= pixel & 0x00FF00; - bsum -= pixel & 0x0000FF; - - pixel = s[1 * in_pitch]; - rsum += (pixel >> 16) * 21; - gsum += (pixel & 0x00FF00) * 21; - bsum += (pixel & 0x0000FF) * 21; - - pixel = s[2 * in_pitch]; - rsum -= (pixel >> 16) << 1; - pixel <<= 1; - gsum -= pixel & 0x01FE00; - bsum -= pixel & 0x0001FE; - - sum->r = rsum; - sum->g = gsum; - sum->b = bsum; - - ++s; - ++sum; - } - } - - mergeColumns(dline, sums); - dline += pitch; - sline += in_pitch; - } -} - -} // anon namespace - -Catrom3x::Catrom3x() -: buffer_((in_height + 3UL) * in_pitch) -{ - std::fill_n(buffer_.get(), buffer_.size(), 0); -} - -void * Catrom3x::inBuf() const { - return buffer_ + in_pitch + 1; -} - -std::ptrdiff_t Catrom3x::inPitch() const { - return in_pitch; -} - -void Catrom3x::draw(void *dbuffer, std::ptrdiff_t pitch) { - ::filter(static_cast(dbuffer), pitch, buffer_ + in_pitch); -} diff --git a/common/videolink/vfilters/catrom3x.h b/common/videolink/vfilters/catrom3x.h deleted file mode 100644 index b5fd1716..00000000 --- a/common/videolink/vfilters/catrom3x.h +++ /dev/null @@ -1,41 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef CATROM3X_H -#define CATROM3X_H - -#include "../videolink.h" -#include "../vfilterinfo.h" -#include "array.h" -#include "gbint.h" - -class Catrom3x : public VideoLink { -public: - enum { out_width = VfilterInfo::in_width * 3 }; - enum { out_height = VfilterInfo::in_height * 3 }; - - Catrom3x(); - virtual void * inBuf() const; - virtual std::ptrdiff_t inPitch() const; - virtual void draw(void *dst, std::ptrdiff_t dstpitch); - -private: - Array const buffer_; -}; - -#endif diff --git a/common/videolink/vfilters/kreed2xsai.cpp b/common/videolink/vfilters/kreed2xsai.cpp deleted file mode 100644 index 9014f4af..00000000 --- a/common/videolink/vfilters/kreed2xsai.cpp +++ /dev/null @@ -1,233 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * Copyright (C) 1999 Derek Liauw Kie Fa (Kreed) * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#include "kreed2xsai.h" -#include - -namespace { - -static int getResult1(unsigned long const a, - unsigned long const b, - unsigned long const c, - unsigned long const d) -{ - int x = 0; - int y = 0; - int r = 0; - - if (a == c) ++x; - else if (b == c) ++y; - - if (a == d) ++x; - else if (b == d) ++y; - - if (x <= 1) ++r; - if (y <= 1) --r; - - return r; -} - -static int getResult2(unsigned long const a, - unsigned long const b, - unsigned long const c, - unsigned long const d) -{ - int x = 0; - int y = 0; - int r = 0; - - if (a == c) ++x; - else if (b == c) ++y; - - if (a == d) ++x; - else if (b == d) ++y; - - if (x <= 1) --r; - if (y <= 1) ++r; - - return r; -} - -static unsigned long interpolate(unsigned long a, unsigned long b) { - return (a + b - ((a ^ b) & 0x010101)) >> 1; -} - -static unsigned long qInterpolate(unsigned long const a, - unsigned long const b, - unsigned long const c, - unsigned long const d) -{ - unsigned long lowBits = ((a & 0x030303) - + (b & 0x030303) - + (c & 0x030303) - + (d & 0x030303)) & 0x030303; - return (a + b + c + d - lowBits) >> 2; -} - -template -static void filter(gambatte::uint_least32_t *dstPtr, - std::ptrdiff_t const dstPitch, - gambatte::uint_least32_t const *srcPtr) -{ - for (unsigned h = height; h--;) { - gambatte::uint_least32_t const *bP = srcPtr; - gambatte::uint_least32_t *dP = dstPtr; - for (unsigned w = width; w--;) { - unsigned long colorA, colorB, colorC, colorD, - colorE, colorF, colorG, colorH, - colorI, colorJ, colorK, colorL, - colorM, colorN, colorO/*, colorP*/; - - //--------------------------------------- - // Map of the pixels: I|E F|J - // G|A B|K - // H|C D|L - // M|N O|P - - colorI = *(bP - srcPitch - 1); - colorE = *(bP - srcPitch ); - colorF = *(bP - srcPitch + 1); - colorJ = *(bP - srcPitch + 2); - - colorG = *(bP - 1); - colorA = *(bP ); - colorB = *(bP + 1); - colorK = *(bP + 2); - - colorH = *(bP + srcPitch - 1); - colorC = *(bP + srcPitch ); - colorD = *(bP + srcPitch + 1); - colorL = *(bP + srcPitch + 2); - - colorM = *(bP + srcPitch * 2 - 1); - colorN = *(bP + srcPitch * 2 ); - colorO = *(bP + srcPitch * 2 + 1); - // colorP = *(bP + srcPitch * 2 + 2); - - unsigned long product0, product1, product2; - if (colorA == colorD && colorB != colorC) { - product0 = (colorA == colorE && colorB == colorL) - || (colorA == colorC && colorA == colorF - && colorB != colorE && colorB == colorJ) - ? colorA - : interpolate(colorA, colorB); - product1 = (colorA == colorG && colorC == colorO) - || (colorA == colorB && colorA == colorH - && colorG != colorC && colorC == colorM) - ? colorA - : interpolate(colorA, colorC); - product2 = colorA; - } else if (colorB == colorC && colorA != colorD) { - product0 = (colorB == colorF && colorA == colorH) - || (colorB == colorE && colorB == colorD - && colorA != colorF && colorA == colorI) - ? colorB - : interpolate(colorA, colorB); - product1 = (colorC == colorH && colorA == colorF) - || (colorC == colorG && colorC == colorD - && colorA != colorH && colorA == colorI) - ? colorC - : interpolate(colorA, colorC); - product2 = colorB; - } else if (colorA == colorD && colorB == colorC) { - if (colorA == colorB) { - product0 = colorA; - product1 = colorA; - product2 = colorA; - } else { - product0 = interpolate(colorA, colorB); - product1 = interpolate(colorA, colorC); - - int r = 0; - r += getResult1(colorA, colorB, colorG, colorE); - r += getResult2(colorB, colorA, colorK, colorF); - r += getResult2(colorB, colorA, colorH, colorN); - r += getResult1(colorA, colorB, colorL, colorO); - if (r > 0) { - product2 = colorA; - } else if (r < 0) { - product2 = colorB; - } else { - product2 = qInterpolate(colorA, colorB, colorC, colorD); - } - } - } else { - product2 = qInterpolate(colorA, colorB, colorC, colorD); - - if (colorA == colorC && colorA == colorF - && colorB != colorE && colorB == colorJ) { - product0 = colorA; - } else if (colorB == colorE && colorB == colorD - && colorA != colorF && colorA == colorI) { - product0 = colorB; - } else { - product0 = interpolate(colorA, colorB); - } - - if (colorA == colorB && colorA == colorH - && colorG != colorC && colorC == colorM) { - product1 = colorA; - } else if (colorC == colorG && colorC == colorD - && colorA != colorH && colorA == colorI) { - product1 = colorC; - } else { - product1 = interpolate(colorA, colorC); - } - } - - *(dP ) = colorA; - *(dP + 1) = product0; - *(dP + dstPitch ) = product1; - *(dP + dstPitch + 1) = product2; - dP += 2; - ++bP; - } - - srcPtr += srcPitch; - dstPtr += dstPitch * 2; - } -} - -enum { in_width = VfilterInfo::in_width }; -enum { in_height = VfilterInfo::in_height }; -enum { in_pitch = in_width + 3 }; -enum { buf_size = (in_height + 3ul) * in_pitch }; -enum { buf_offset = in_pitch + 1 }; - -} // anon namespace - -Kreed2xSaI::Kreed2xSaI() -: buffer_(buf_size) -{ - std::fill_n(buffer_.get(), buffer_.size(), 0); -} - -void * Kreed2xSaI::inBuf() const { - return buffer_ + buf_offset; -} - -std::ptrdiff_t Kreed2xSaI::inPitch() const { - return in_pitch; -} - -void Kreed2xSaI::draw(void *dbuffer, std::ptrdiff_t dpitch) { - ::filter(static_cast(dbuffer), - dpitch, buffer_ + buf_offset); -} diff --git a/common/videolink/vfilters/kreed2xsai.h b/common/videolink/vfilters/kreed2xsai.h deleted file mode 100644 index 49efa5e5..00000000 --- a/common/videolink/vfilters/kreed2xsai.h +++ /dev/null @@ -1,41 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef KREED2XSAI_H -#define KREED2XSAI_H - -#include "../videolink.h" -#include "../vfilterinfo.h" -#include "array.h" -#include "gbint.h" - -class Kreed2xSaI : public VideoLink { -public: - enum { out_width = VfilterInfo::in_width * 2 }; - enum { out_height = VfilterInfo::in_height * 2 }; - - Kreed2xSaI(); - virtual void * inBuf() const; - virtual std::ptrdiff_t inPitch() const; - virtual void draw(void *dst, std::ptrdiff_t dstpitch); - -private: - Array const buffer_; -}; - -#endif diff --git a/common/videolink/vfilters/maxsthq2x.cpp b/common/videolink/vfilters/maxsthq2x.cpp deleted file mode 100644 index 0e6a1039..00000000 --- a/common/videolink/vfilters/maxsthq2x.cpp +++ /dev/null @@ -1,2858 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * Copyright (C) 2003 MaxSt * - * maxst@hiend3d.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#include "maxsthq2x.h" - -static unsigned long blend1(unsigned long c1, unsigned long c2) { - unsigned long lowbits = ((c1 & 0x030303) * 3 + (c2 & 0x030303)) & 0x030303; - return (c1 * 3 + c2 - lowbits) >> 2; -} - -static unsigned long blend2(unsigned long c1, unsigned long c2, unsigned long c3) { - unsigned long lowbits = ((c1 & 0x030303) * 2 - + (c2 & 0x030303) - + (c3 & 0x030303)) & 0x030303; - return (c1 * 2 + c2 + c3 - lowbits) >> 2; -} - -static unsigned long blend6(unsigned long c1, unsigned long c2, unsigned long c3) { - unsigned long lowbits = ((c1 & 0x070707) * 5 - + (c2 & 0x070707) * 2 - + (c3 & 0x070707)) & 0x070707; - return ((c1 * 5 + c2 * 2 + c3) - lowbits) >> 3; -} - -static unsigned long blend7(unsigned long c1, unsigned long c2, unsigned long c3) { - unsigned long lowbits = ((c1 & 0x070707) * 6 - + (c2 & 0x070707) - + (c3 & 0x070707)) & 0x070707; - return ((c1 * 6 + c2 + c3) - lowbits) >> 3; -} - -static unsigned long blend9(unsigned long c1, unsigned long c2, unsigned long c3) { - unsigned long lowbits = ((c1 & 0x070707) * 2 - + ((c2 & 0x070707) + (c3 & 0x070707)) * 3) & 0x070707; - return (c1 * 2 + (c2 + c3) * 3 - lowbits) >> 3; -} - -static unsigned long blend10(unsigned long c1, unsigned long c2, unsigned long c3) { - unsigned long lowbits = ((c1 & 0x0F0F0F) * 14 - + (c2 & 0x0F0F0F) - + (c3 & 0x0F0F0F)) & 0x0F0F0F; - return (c1 * 14 + c2 + c3 - lowbits) >> 4; -} - -#define PIXEL00_0 *(out ) = w[5]; -#define PIXEL00_10 *(out ) = blend1(w[5], w[1]); -#define PIXEL00_11 *(out ) = blend1(w[5], w[4]); -#define PIXEL00_12 *(out ) = blend1(w[5], w[2]); -#define PIXEL00_20 *(out ) = blend2(w[5], w[4], w[2]); -#define PIXEL00_21 *(out ) = blend2(w[5], w[1], w[2]); -#define PIXEL00_22 *(out ) = blend2(w[5], w[1], w[4]); -#define PIXEL00_60 *(out ) = blend6(w[5], w[2], w[4]); -#define PIXEL00_61 *(out ) = blend6(w[5], w[4], w[2]); -#define PIXEL00_70 *(out ) = blend7(w[5], w[4], w[2]); -#define PIXEL00_90 *(out ) = blend9(w[5], w[4], w[2]); -#define PIXEL00_100 *(out ) = blend10(w[5], w[4], w[2]); -#define PIXEL01_0 *(out + 1) = w[5]; -#define PIXEL01_10 *(out + 1) = blend1(w[5], w[3]); -#define PIXEL01_11 *(out + 1) = blend1(w[5], w[2]); -#define PIXEL01_12 *(out + 1) = blend1(w[5], w[6]); -#define PIXEL01_20 *(out + 1) = blend2(w[5], w[2], w[6]); -#define PIXEL01_21 *(out + 1) = blend2(w[5], w[3], w[6]); -#define PIXEL01_22 *(out + 1) = blend2(w[5], w[3], w[2]); -#define PIXEL01_60 *(out + 1) = blend6(w[5], w[6], w[2]); -#define PIXEL01_61 *(out + 1) = blend6(w[5], w[2], w[6]); -#define PIXEL01_70 *(out + 1) = blend7(w[5], w[2], w[6]); -#define PIXEL01_90 *(out + 1) = blend9(w[5], w[2], w[6]); -#define PIXEL01_100 *(out + 1) = blend10(w[5], w[2], w[6]); -#define PIXEL10_0 *(out + dstPitch ) = w[5]; -#define PIXEL10_10 *(out + dstPitch ) = blend1(w[5], w[7]); -#define PIXEL10_11 *(out + dstPitch ) = blend1(w[5], w[8]); -#define PIXEL10_12 *(out + dstPitch ) = blend1(w[5], w[4]); -#define PIXEL10_20 *(out + dstPitch ) = blend2(w[5], w[8], w[4]); -#define PIXEL10_21 *(out + dstPitch ) = blend2(w[5], w[7], w[4]); -#define PIXEL10_22 *(out + dstPitch ) = blend2(w[5], w[7], w[8]); -#define PIXEL10_60 *(out + dstPitch ) = blend6(w[5], w[4], w[8]); -#define PIXEL10_61 *(out + dstPitch ) = blend6(w[5], w[8], w[4]); -#define PIXEL10_70 *(out + dstPitch ) = blend7(w[5], w[8], w[4]); -#define PIXEL10_90 *(out + dstPitch ) = blend9(w[5], w[8], w[4]); -#define PIXEL10_100 *(out + dstPitch ) = blend10(w[5], w[8], w[4]); -#define PIXEL11_0 *(out + dstPitch + 1) = w[5]; -#define PIXEL11_10 *(out + dstPitch + 1) = blend1(w[5], w[9]); -#define PIXEL11_11 *(out + dstPitch + 1) = blend1(w[5], w[6]); -#define PIXEL11_12 *(out + dstPitch + 1) = blend1(w[5], w[8]); -#define PIXEL11_20 *(out + dstPitch + 1) = blend2(w[5], w[6], w[8]); -#define PIXEL11_21 *(out + dstPitch + 1) = blend2(w[5], w[9], w[8]); -#define PIXEL11_22 *(out + dstPitch + 1) = blend2(w[5], w[9], w[6]); -#define PIXEL11_60 *(out + dstPitch + 1) = blend6(w[5], w[8], w[6]); -#define PIXEL11_61 *(out + dstPitch + 1) = blend6(w[5], w[6], w[8]); -#define PIXEL11_70 *(out + dstPitch + 1) = blend7(w[5], w[6], w[8]); -#define PIXEL11_90 *(out + dstPitch + 1) = blend9(w[5], w[6], w[8]); -#define PIXEL11_100 *(out + dstPitch + 1) = blend10(w[5], w[6], w[8]); - -static bool diff(unsigned long const w1, unsigned long const w2) { - unsigned rdiff = (w1 >> 16 ) - (w2 >> 16 ); - unsigned gdiff = (w1 >> 8 & 0xFF) - (w2 >> 8 & 0xFF); - unsigned bdiff = (w1 & 0xFF) - (w2 & 0xFF); - - return rdiff + gdiff + bdiff + 0xC0U > 0xC0U * 2 - || rdiff - bdiff + 0x1CU > 0x1CU * 2 - || gdiff * 2 - rdiff - bdiff + 0x30U > 0x30U * 2; -} - -template -static void filter(gambatte::uint_least32_t *out, - std::ptrdiff_t const dstPitch, - gambatte::uint_least32_t const *in) -{ - unsigned long w[10]; - // +----+----+----+ - // | | | | - // | w1 | w2 | w3 | - // +----+----+----+ - // | | | | - // | w4 | w5 | w6 | - // +----+----+----+ - // | | | | - // | w7 | w8 | w9 | - // +----+----+----+ - - for (int j = 0; j < y_res; j++) { - std::ptrdiff_t const prevline = j > 0 ? -x_res : 0; - std::ptrdiff_t const nextline = j < y_res - 1 ? x_res : 0; - for (int i = 0; i < x_res; i++) { - w[2] = *(in + prevline); - w[5] = *(in ); - w[8] = *(in + nextline); - if (i > 0) { - w[1] = *(in + prevline - 1); - w[4] = *(in - 1); - w[7] = *(in + nextline - 1); - } else { - w[1] = w[2]; - w[4] = w[5]; - w[7] = w[8]; - } - if (i < x_res - 1) { - w[3] = *(in + prevline + 1); - w[6] = *(in + 1); - w[9] = *(in + nextline + 1); - } else { - w[3] = w[2]; - w[6] = w[5]; - w[9] = w[8]; - } - - unsigned pattern = 0; - - { - unsigned const r1 = w[5] >> 16; - unsigned const g1 = w[5] >> 8 & 0xFF; - unsigned const b1 = w[5] & 0xFF; - unsigned flag = 1; - for (int k = 1; k < 10; ++k) { - if (k == 5) - continue; - - if (w[k] != w[5]) { - unsigned const rdiff = r1 - (w[k] >> 16 ); - unsigned const gdiff = g1 - (w[k] >> 8 & 0xFF); - unsigned const bdiff = b1 - (w[k] & 0xFF); - if (rdiff + gdiff + bdiff + 0xC0U > 0xC0U * 2 - || rdiff - bdiff + 0x1CU > 0x1CU * 2 - || gdiff * 2 - rdiff - bdiff + 0x30U > 0x30U * 2) { - pattern |= flag; - } - } - - flag <<= 1; - } - } - - switch (pattern) { - case 0: - case 1: - case 4: - case 32: - case 128: - case 5: - case 132: - case 160: - case 33: - case 129: - case 36: - case 133: - case 164: - case 161: - case 37: - case 165: - { - PIXEL00_20 - PIXEL01_20 - PIXEL10_20 - PIXEL11_20 - break; - } - case 2: - case 34: - case 130: - case 162: - { - PIXEL00_22 - PIXEL01_21 - PIXEL10_20 - PIXEL11_20 - break; - } - case 16: - case 17: - case 48: - case 49: - { - PIXEL00_20 - PIXEL01_22 - PIXEL10_20 - PIXEL11_21 - break; - } - case 64: - case 65: - case 68: - case 69: - { - PIXEL00_20 - PIXEL01_20 - PIXEL10_21 - PIXEL11_22 - break; - } - case 8: - case 12: - case 136: - case 140: - { - PIXEL00_21 - PIXEL01_20 - PIXEL10_22 - PIXEL11_20 - break; - } - case 3: - case 35: - case 131: - case 163: - { - PIXEL00_11 - PIXEL01_21 - PIXEL10_20 - PIXEL11_20 - break; - } - case 6: - case 38: - case 134: - case 166: - { - PIXEL00_22 - PIXEL01_12 - PIXEL10_20 - PIXEL11_20 - break; - } - case 20: - case 21: - case 52: - case 53: - { - PIXEL00_20 - PIXEL01_11 - PIXEL10_20 - PIXEL11_21 - break; - } - case 144: - case 145: - case 176: - case 177: - { - PIXEL00_20 - PIXEL01_22 - PIXEL10_20 - PIXEL11_12 - break; - } - case 192: - case 193: - case 196: - case 197: - { - PIXEL00_20 - PIXEL01_20 - PIXEL10_21 - PIXEL11_11 - break; - } - case 96: - case 97: - case 100: - case 101: - { - PIXEL00_20 - PIXEL01_20 - PIXEL10_12 - PIXEL11_22 - break; - } - case 40: - case 44: - case 168: - case 172: - { - PIXEL00_21 - PIXEL01_20 - PIXEL10_11 - PIXEL11_20 - break; - } - case 9: - case 13: - case 137: - case 141: - { - PIXEL00_12 - PIXEL01_20 - PIXEL10_22 - PIXEL11_20 - break; - } - case 18: - case 50: - { - PIXEL00_22 - if (diff(w[2], w[6])) - { - PIXEL01_10 - } - else - { - PIXEL01_20 - } - PIXEL10_20 - PIXEL11_21 - break; - } - case 80: - case 81: - { - PIXEL00_20 - PIXEL01_22 - PIXEL10_21 - if (diff(w[6], w[8])) - { - PIXEL11_10 - } - else - { - PIXEL11_20 - } - break; - } - case 72: - case 76: - { - PIXEL00_21 - PIXEL01_20 - if (diff(w[8], w[4])) - { - PIXEL10_10 - } - else - { - PIXEL10_20 - } - PIXEL11_22 - break; - } - case 10: - case 138: - { - if (diff(w[4], w[2])) - { - PIXEL00_10 - } - else - { - PIXEL00_20 - } - PIXEL01_21 - PIXEL10_22 - PIXEL11_20 - break; - } - case 66: - { - PIXEL00_22 - PIXEL01_21 - PIXEL10_21 - PIXEL11_22 - break; - } - case 24: - { - PIXEL00_21 - PIXEL01_22 - PIXEL10_22 - PIXEL11_21 - break; - } - case 7: - case 39: - case 135: - { - PIXEL00_11 - PIXEL01_12 - PIXEL10_20 - PIXEL11_20 - break; - } - case 148: - case 149: - case 180: - { - PIXEL00_20 - PIXEL01_11 - PIXEL10_20 - PIXEL11_12 - break; - } - case 224: - case 228: - case 225: - { - PIXEL00_20 - PIXEL01_20 - PIXEL10_12 - PIXEL11_11 - break; - } - case 41: - case 169: - case 45: - { - PIXEL00_12 - PIXEL01_20 - PIXEL10_11 - PIXEL11_20 - break; - } - case 22: - case 54: - { - PIXEL00_22 - if (diff(w[2], w[6])) - { - PIXEL01_0 - } - else - { - PIXEL01_20 - } - PIXEL10_20 - PIXEL11_21 - break; - } - case 208: - case 209: - { - PIXEL00_20 - PIXEL01_22 - PIXEL10_21 - if (diff(w[6], w[8])) - { - PIXEL11_0 - } - else - { - PIXEL11_20 - } - break; - } - case 104: - case 108: - { - PIXEL00_21 - PIXEL01_20 - if (diff(w[8], w[4])) - { - PIXEL10_0 - } - else - { - PIXEL10_20 - } - PIXEL11_22 - break; - } - case 11: - case 139: - { - if (diff(w[4], w[2])) - { - PIXEL00_0 - } - else - { - PIXEL00_20 - } - PIXEL01_21 - PIXEL10_22 - PIXEL11_20 - break; - } - case 19: - case 51: - { - if (diff(w[2], w[6])) - { - PIXEL00_11 - PIXEL01_10 - } - else - { - PIXEL00_60 - PIXEL01_90 - } - PIXEL10_20 - PIXEL11_21 - break; - } - case 146: - case 178: - { - PIXEL00_22 - if (diff(w[2], w[6])) - { - PIXEL01_10 - PIXEL11_12 - } - else - { - PIXEL01_90 - PIXEL11_61 - } - PIXEL10_20 - break; - } - case 84: - case 85: - { - PIXEL00_20 - if (diff(w[6], w[8])) - { - PIXEL01_11 - PIXEL11_10 - } - else - { - PIXEL01_60 - PIXEL11_90 - } - PIXEL10_21 - break; - } - case 112: - case 113: - { - PIXEL00_20 - PIXEL01_22 - if (diff(w[6], w[8])) - { - PIXEL10_12 - PIXEL11_10 - } - else - { - PIXEL10_61 - PIXEL11_90 - } - break; - } - case 200: - case 204: - { - PIXEL00_21 - PIXEL01_20 - if (diff(w[8], w[4])) - { - PIXEL10_10 - PIXEL11_11 - } - else - { - PIXEL10_90 - PIXEL11_60 - } - break; - } - case 73: - case 77: - { - if (diff(w[8], w[4])) - { - PIXEL00_12 - PIXEL10_10 - } - else - { - PIXEL00_61 - PIXEL10_90 - } - PIXEL01_20 - PIXEL11_22 - break; - } - case 42: - case 170: - { - if (diff(w[4], w[2])) - { - PIXEL00_10 - PIXEL10_11 - } - else - { - PIXEL00_90 - PIXEL10_60 - } - PIXEL01_21 - PIXEL11_20 - break; - } - case 14: - case 142: - { - if (diff(w[4], w[2])) - { - PIXEL00_10 - PIXEL01_12 - } - else - { - PIXEL00_90 - PIXEL01_61 - } - PIXEL10_22 - PIXEL11_20 - break; - } - case 67: - { - PIXEL00_11 - PIXEL01_21 - PIXEL10_21 - PIXEL11_22 - break; - } - case 70: - { - PIXEL00_22 - PIXEL01_12 - PIXEL10_21 - PIXEL11_22 - break; - } - case 28: - { - PIXEL00_21 - PIXEL01_11 - PIXEL10_22 - PIXEL11_21 - break; - } - case 152: - { - PIXEL00_21 - PIXEL01_22 - PIXEL10_22 - PIXEL11_12 - break; - } - case 194: - { - PIXEL00_22 - PIXEL01_21 - PIXEL10_21 - PIXEL11_11 - break; - } - case 98: - { - PIXEL00_22 - PIXEL01_21 - PIXEL10_12 - PIXEL11_22 - break; - } - case 56: - { - PIXEL00_21 - PIXEL01_22 - PIXEL10_11 - PIXEL11_21 - break; - } - case 25: - { - PIXEL00_12 - PIXEL01_22 - PIXEL10_22 - PIXEL11_21 - break; - } - case 26: - case 31: - { - if (diff(w[4], w[2])) - { - PIXEL00_0 - } - else - { - PIXEL00_20 - } - if (diff(w[2], w[6])) - { - PIXEL01_0 - } - else - { - PIXEL01_20 - } - PIXEL10_22 - PIXEL11_21 - break; - } - case 82: - case 214: - { - PIXEL00_22 - if (diff(w[2], w[6])) - { - PIXEL01_0 - } - else - { - PIXEL01_20 - } - PIXEL10_21 - if (diff(w[6], w[8])) - { - PIXEL11_0 - } - else - { - PIXEL11_20 - } - break; - } - case 88: - case 248: - { - PIXEL00_21 - PIXEL01_22 - if (diff(w[8], w[4])) - { - PIXEL10_0 - } - else - { - PIXEL10_20 - } - if (diff(w[6], w[8])) - { - PIXEL11_0 - } - else - { - PIXEL11_20 - } - break; - } - case 74: - case 107: - { - if (diff(w[4], w[2])) - { - PIXEL00_0 - } - else - { - PIXEL00_20 - } - PIXEL01_21 - if (diff(w[8], w[4])) - { - PIXEL10_0 - } - else - { - PIXEL10_20 - } - PIXEL11_22 - break; - } - case 27: - { - if (diff(w[4], w[2])) - { - PIXEL00_0 - } - else - { - PIXEL00_20 - } - PIXEL01_10 - PIXEL10_22 - PIXEL11_21 - break; - } - case 86: - { - PIXEL00_22 - if (diff(w[2], w[6])) - { - PIXEL01_0 - } - else - { - PIXEL01_20 - } - PIXEL10_21 - PIXEL11_10 - break; - } - case 216: - { - PIXEL00_21 - PIXEL01_22 - PIXEL10_10 - if (diff(w[6], w[8])) - { - PIXEL11_0 - } - else - { - PIXEL11_20 - } - break; - } - case 106: - { - PIXEL00_10 - PIXEL01_21 - if (diff(w[8], w[4])) - { - PIXEL10_0 - } - else - { - PIXEL10_20 - } - PIXEL11_22 - break; - } - case 30: - { - PIXEL00_10 - if (diff(w[2], w[6])) - { - PIXEL01_0 - } - else - { - PIXEL01_20 - } - PIXEL10_22 - PIXEL11_21 - break; - } - case 210: - { - PIXEL00_22 - PIXEL01_10 - PIXEL10_21 - if (diff(w[6], w[8])) - { - PIXEL11_0 - } - else - { - PIXEL11_20 - } - break; - } - case 120: - { - PIXEL00_21 - PIXEL01_22 - if (diff(w[8], w[4])) - { - PIXEL10_0 - } - else - { - PIXEL10_20 - } - PIXEL11_10 - break; - } - case 75: - { - if (diff(w[4], w[2])) - { - PIXEL00_0 - } - else - { - PIXEL00_20 - } - PIXEL01_21 - PIXEL10_10 - PIXEL11_22 - break; - } - case 29: - { - PIXEL00_12 - PIXEL01_11 - PIXEL10_22 - PIXEL11_21 - break; - } - case 198: - { - PIXEL00_22 - PIXEL01_12 - PIXEL10_21 - PIXEL11_11 - break; - } - case 184: - { - PIXEL00_21 - PIXEL01_22 - PIXEL10_11 - PIXEL11_12 - break; - } - case 99: - { - PIXEL00_11 - PIXEL01_21 - PIXEL10_12 - PIXEL11_22 - break; - } - case 57: - { - PIXEL00_12 - PIXEL01_22 - PIXEL10_11 - PIXEL11_21 - break; - } - case 71: - { - PIXEL00_11 - PIXEL01_12 - PIXEL10_21 - PIXEL11_22 - break; - } - case 156: - { - PIXEL00_21 - PIXEL01_11 - PIXEL10_22 - PIXEL11_12 - break; - } - case 226: - { - PIXEL00_22 - PIXEL01_21 - PIXEL10_12 - PIXEL11_11 - break; - } - case 60: - { - PIXEL00_21 - PIXEL01_11 - PIXEL10_11 - PIXEL11_21 - break; - } - case 195: - { - PIXEL00_11 - PIXEL01_21 - PIXEL10_21 - PIXEL11_11 - break; - } - case 102: - { - PIXEL00_22 - PIXEL01_12 - PIXEL10_12 - PIXEL11_22 - break; - } - case 153: - { - PIXEL00_12 - PIXEL01_22 - PIXEL10_22 - PIXEL11_12 - break; - } - case 58: - { - if (diff(w[4], w[2])) - { - PIXEL00_10 - } - else - { - PIXEL00_70 - } - if (diff(w[2], w[6])) - { - PIXEL01_10 - } - else - { - PIXEL01_70 - } - PIXEL10_11 - PIXEL11_21 - break; - } - case 83: - { - PIXEL00_11 - if (diff(w[2], w[6])) - { - PIXEL01_10 - } - else - { - PIXEL01_70 - } - PIXEL10_21 - if (diff(w[6], w[8])) - { - PIXEL11_10 - } - else - { - PIXEL11_70 - } - break; - } - case 92: - { - PIXEL00_21 - PIXEL01_11 - if (diff(w[8], w[4])) - { - PIXEL10_10 - } - else - { - PIXEL10_70 - } - if (diff(w[6], w[8])) - { - PIXEL11_10 - } - else - { - PIXEL11_70 - } - break; - } - case 202: - { - if (diff(w[4], w[2])) - { - PIXEL00_10 - } - else - { - PIXEL00_70 - } - PIXEL01_21 - if (diff(w[8], w[4])) - { - PIXEL10_10 - } - else - { - PIXEL10_70 - } - PIXEL11_11 - break; - } - case 78: - { - if (diff(w[4], w[2])) - { - PIXEL00_10 - } - else - { - PIXEL00_70 - } - PIXEL01_12 - if (diff(w[8], w[4])) - { - PIXEL10_10 - } - else - { - PIXEL10_70 - } - PIXEL11_22 - break; - } - case 154: - { - if (diff(w[4], w[2])) - { - PIXEL00_10 - } - else - { - PIXEL00_70 - } - if (diff(w[2], w[6])) - { - PIXEL01_10 - } - else - { - PIXEL01_70 - } - PIXEL10_22 - PIXEL11_12 - break; - } - case 114: - { - PIXEL00_22 - if (diff(w[2], w[6])) - { - PIXEL01_10 - } - else - { - PIXEL01_70 - } - PIXEL10_12 - if (diff(w[6], w[8])) - { - PIXEL11_10 - } - else - { - PIXEL11_70 - } - break; - } - case 89: - { - PIXEL00_12 - PIXEL01_22 - if (diff(w[8], w[4])) - { - PIXEL10_10 - } - else - { - PIXEL10_70 - } - if (diff(w[6], w[8])) - { - PIXEL11_10 - } - else - { - PIXEL11_70 - } - break; - } - case 90: - { - if (diff(w[4], w[2])) - { - PIXEL00_10 - } - else - { - PIXEL00_70 - } - if (diff(w[2], w[6])) - { - PIXEL01_10 - } - else - { - PIXEL01_70 - } - if (diff(w[8], w[4])) - { - PIXEL10_10 - } - else - { - PIXEL10_70 - } - if (diff(w[6], w[8])) - { - PIXEL11_10 - } - else - { - PIXEL11_70 - } - break; - } - case 55: - case 23: - { - if (diff(w[2], w[6])) - { - PIXEL00_11 - PIXEL01_0 - } - else - { - PIXEL00_60 - PIXEL01_90 - } - PIXEL10_20 - PIXEL11_21 - break; - } - case 182: - case 150: - { - PIXEL00_22 - if (diff(w[2], w[6])) - { - PIXEL01_0 - PIXEL11_12 - } - else - { - PIXEL01_90 - PIXEL11_61 - } - PIXEL10_20 - break; - } - case 213: - case 212: - { - PIXEL00_20 - if (diff(w[6], w[8])) - { - PIXEL01_11 - PIXEL11_0 - } - else - { - PIXEL01_60 - PIXEL11_90 - } - PIXEL10_21 - break; - } - case 241: - case 240: - { - PIXEL00_20 - PIXEL01_22 - if (diff(w[6], w[8])) - { - PIXEL10_12 - PIXEL11_0 - } - else - { - PIXEL10_61 - PIXEL11_90 - } - break; - } - case 236: - case 232: - { - PIXEL00_21 - PIXEL01_20 - if (diff(w[8], w[4])) - { - PIXEL10_0 - PIXEL11_11 - } - else - { - PIXEL10_90 - PIXEL11_60 - } - break; - } - case 109: - case 105: - { - if (diff(w[8], w[4])) - { - PIXEL00_12 - PIXEL10_0 - } - else - { - PIXEL00_61 - PIXEL10_90 - } - PIXEL01_20 - PIXEL11_22 - break; - } - case 171: - case 43: - { - if (diff(w[4], w[2])) - { - PIXEL00_0 - PIXEL10_11 - } - else - { - PIXEL00_90 - PIXEL10_60 - } - PIXEL01_21 - PIXEL11_20 - break; - } - case 143: - case 15: - { - if (diff(w[4], w[2])) - { - PIXEL00_0 - PIXEL01_12 - } - else - { - PIXEL00_90 - PIXEL01_61 - } - PIXEL10_22 - PIXEL11_20 - break; - } - case 124: - { - PIXEL00_21 - PIXEL01_11 - if (diff(w[8], w[4])) - { - PIXEL10_0 - } - else - { - PIXEL10_20 - } - PIXEL11_10 - break; - } - case 203: - { - if (diff(w[4], w[2])) - { - PIXEL00_0 - } - else - { - PIXEL00_20 - } - PIXEL01_21 - PIXEL10_10 - PIXEL11_11 - break; - } - case 62: - { - PIXEL00_10 - if (diff(w[2], w[6])) - { - PIXEL01_0 - } - else - { - PIXEL01_20 - } - PIXEL10_11 - PIXEL11_21 - break; - } - case 211: - { - PIXEL00_11 - PIXEL01_10 - PIXEL10_21 - if (diff(w[6], w[8])) - { - PIXEL11_0 - } - else - { - PIXEL11_20 - } - break; - } - case 118: - { - PIXEL00_22 - if (diff(w[2], w[6])) - { - PIXEL01_0 - } - else - { - PIXEL01_20 - } - PIXEL10_12 - PIXEL11_10 - break; - } - case 217: - { - PIXEL00_12 - PIXEL01_22 - PIXEL10_10 - if (diff(w[6], w[8])) - { - PIXEL11_0 - } - else - { - PIXEL11_20 - } - break; - } - case 110: - { - PIXEL00_10 - PIXEL01_12 - if (diff(w[8], w[4])) - { - PIXEL10_0 - } - else - { - PIXEL10_20 - } - PIXEL11_22 - break; - } - case 155: - { - if (diff(w[4], w[2])) - { - PIXEL00_0 - } - else - { - PIXEL00_20 - } - PIXEL01_10 - PIXEL10_22 - PIXEL11_12 - break; - } - case 188: - { - PIXEL00_21 - PIXEL01_11 - PIXEL10_11 - PIXEL11_12 - break; - } - case 185: - { - PIXEL00_12 - PIXEL01_22 - PIXEL10_11 - PIXEL11_12 - break; - } - case 61: - { - PIXEL00_12 - PIXEL01_11 - PIXEL10_11 - PIXEL11_21 - break; - } - case 157: - { - PIXEL00_12 - PIXEL01_11 - PIXEL10_22 - PIXEL11_12 - break; - } - case 103: - { - PIXEL00_11 - PIXEL01_12 - PIXEL10_12 - PIXEL11_22 - break; - } - case 227: - { - PIXEL00_11 - PIXEL01_21 - PIXEL10_12 - PIXEL11_11 - break; - } - case 230: - { - PIXEL00_22 - PIXEL01_12 - PIXEL10_12 - PIXEL11_11 - break; - } - case 199: - { - PIXEL00_11 - PIXEL01_12 - PIXEL10_21 - PIXEL11_11 - break; - } - case 220: - { - PIXEL00_21 - PIXEL01_11 - if (diff(w[8], w[4])) - { - PIXEL10_10 - } - else - { - PIXEL10_70 - } - if (diff(w[6], w[8])) - { - PIXEL11_0 - } - else - { - PIXEL11_20 - } - break; - } - case 158: - { - if (diff(w[4], w[2])) - { - PIXEL00_10 - } - else - { - PIXEL00_70 - } - if (diff(w[2], w[6])) - { - PIXEL01_0 - } - else - { - PIXEL01_20 - } - PIXEL10_22 - PIXEL11_12 - break; - } - case 234: - { - if (diff(w[4], w[2])) - { - PIXEL00_10 - } - else - { - PIXEL00_70 - } - PIXEL01_21 - if (diff(w[8], w[4])) - { - PIXEL10_0 - } - else - { - PIXEL10_20 - } - PIXEL11_11 - break; - } - case 242: - { - PIXEL00_22 - if (diff(w[2], w[6])) - { - PIXEL01_10 - } - else - { - PIXEL01_70 - } - PIXEL10_12 - if (diff(w[6], w[8])) - { - PIXEL11_0 - } - else - { - PIXEL11_20 - } - break; - } - case 59: - { - if (diff(w[4], w[2])) - { - PIXEL00_0 - } - else - { - PIXEL00_20 - } - if (diff(w[2], w[6])) - { - PIXEL01_10 - } - else - { - PIXEL01_70 - } - PIXEL10_11 - PIXEL11_21 - break; - } - case 121: - { - PIXEL00_12 - PIXEL01_22 - if (diff(w[8], w[4])) - { - PIXEL10_0 - } - else - { - PIXEL10_20 - } - if (diff(w[6], w[8])) - { - PIXEL11_10 - } - else - { - PIXEL11_70 - } - break; - } - case 87: - { - PIXEL00_11 - if (diff(w[2], w[6])) - { - PIXEL01_0 - } - else - { - PIXEL01_20 - } - PIXEL10_21 - if (diff(w[6], w[8])) - { - PIXEL11_10 - } - else - { - PIXEL11_70 - } - break; - } - case 79: - { - if (diff(w[4], w[2])) - { - PIXEL00_0 - } - else - { - PIXEL00_20 - } - PIXEL01_12 - if (diff(w[8], w[4])) - { - PIXEL10_10 - } - else - { - PIXEL10_70 - } - PIXEL11_22 - break; - } - case 122: - { - if (diff(w[4], w[2])) - { - PIXEL00_10 - } - else - { - PIXEL00_70 - } - if (diff(w[2], w[6])) - { - PIXEL01_10 - } - else - { - PIXEL01_70 - } - if (diff(w[8], w[4])) - { - PIXEL10_0 - } - else - { - PIXEL10_20 - } - if (diff(w[6], w[8])) - { - PIXEL11_10 - } - else - { - PIXEL11_70 - } - break; - } - case 94: - { - if (diff(w[4], w[2])) - { - PIXEL00_10 - } - else - { - PIXEL00_70 - } - if (diff(w[2], w[6])) - { - PIXEL01_0 - } - else - { - PIXEL01_20 - } - if (diff(w[8], w[4])) - { - PIXEL10_10 - } - else - { - PIXEL10_70 - } - if (diff(w[6], w[8])) - { - PIXEL11_10 - } - else - { - PIXEL11_70 - } - break; - } - case 218: - { - if (diff(w[4], w[2])) - { - PIXEL00_10 - } - else - { - PIXEL00_70 - } - if (diff(w[2], w[6])) - { - PIXEL01_10 - } - else - { - PIXEL01_70 - } - if (diff(w[8], w[4])) - { - PIXEL10_10 - } - else - { - PIXEL10_70 - } - if (diff(w[6], w[8])) - { - PIXEL11_0 - } - else - { - PIXEL11_20 - } - break; - } - case 91: - { - if (diff(w[4], w[2])) - { - PIXEL00_0 - } - else - { - PIXEL00_20 - } - if (diff(w[2], w[6])) - { - PIXEL01_10 - } - else - { - PIXEL01_70 - } - if (diff(w[8], w[4])) - { - PIXEL10_10 - } - else - { - PIXEL10_70 - } - if (diff(w[6], w[8])) - { - PIXEL11_10 - } - else - { - PIXEL11_70 - } - break; - } - case 229: - { - PIXEL00_20 - PIXEL01_20 - PIXEL10_12 - PIXEL11_11 - break; - } - case 167: - { - PIXEL00_11 - PIXEL01_12 - PIXEL10_20 - PIXEL11_20 - break; - } - case 173: - { - PIXEL00_12 - PIXEL01_20 - PIXEL10_11 - PIXEL11_20 - break; - } - case 181: - { - PIXEL00_20 - PIXEL01_11 - PIXEL10_20 - PIXEL11_12 - break; - } - case 186: - { - if (diff(w[4], w[2])) - { - PIXEL00_10 - } - else - { - PIXEL00_70 - } - if (diff(w[2], w[6])) - { - PIXEL01_10 - } - else - { - PIXEL01_70 - } - PIXEL10_11 - PIXEL11_12 - break; - } - case 115: - { - PIXEL00_11 - if (diff(w[2], w[6])) - { - PIXEL01_10 - } - else - { - PIXEL01_70 - } - PIXEL10_12 - if (diff(w[6], w[8])) - { - PIXEL11_10 - } - else - { - PIXEL11_70 - } - break; - } - case 93: - { - PIXEL00_12 - PIXEL01_11 - if (diff(w[8], w[4])) - { - PIXEL10_10 - } - else - { - PIXEL10_70 - } - if (diff(w[6], w[8])) - { - PIXEL11_10 - } - else - { - PIXEL11_70 - } - break; - } - case 206: - { - if (diff(w[4], w[2])) - { - PIXEL00_10 - } - else - { - PIXEL00_70 - } - PIXEL01_12 - if (diff(w[8], w[4])) - { - PIXEL10_10 - } - else - { - PIXEL10_70 - } - PIXEL11_11 - break; - } - case 205: - case 201: - { - PIXEL00_12 - PIXEL01_20 - if (diff(w[8], w[4])) - { - PIXEL10_10 - } - else - { - PIXEL10_70 - } - PIXEL11_11 - break; - } - case 174: - case 46: - { - if (diff(w[4], w[2])) - { - PIXEL00_10 - } - else - { - PIXEL00_70 - } - PIXEL01_12 - PIXEL10_11 - PIXEL11_20 - break; - } - case 179: - case 147: - { - PIXEL00_11 - if (diff(w[2], w[6])) - { - PIXEL01_10 - } - else - { - PIXEL01_70 - } - PIXEL10_20 - PIXEL11_12 - break; - } - case 117: - case 116: - { - PIXEL00_20 - PIXEL01_11 - PIXEL10_12 - if (diff(w[6], w[8])) - { - PIXEL11_10 - } - else - { - PIXEL11_70 - } - break; - } - case 189: - { - PIXEL00_12 - PIXEL01_11 - PIXEL10_11 - PIXEL11_12 - break; - } - case 231: - { - PIXEL00_11 - PIXEL01_12 - PIXEL10_12 - PIXEL11_11 - break; - } - case 126: - { - PIXEL00_10 - if (diff(w[2], w[6])) - { - PIXEL01_0 - } - else - { - PIXEL01_20 - } - if (diff(w[8], w[4])) - { - PIXEL10_0 - } - else - { - PIXEL10_20 - } - PIXEL11_10 - break; - } - case 219: - { - if (diff(w[4], w[2])) - { - PIXEL00_0 - } - else - { - PIXEL00_20 - } - PIXEL01_10 - PIXEL10_10 - if (diff(w[6], w[8])) - { - PIXEL11_0 - } - else - { - PIXEL11_20 - } - break; - } - case 125: - { - if (diff(w[8], w[4])) - { - PIXEL00_12 - PIXEL10_0 - } - else - { - PIXEL00_61 - PIXEL10_90 - } - PIXEL01_11 - PIXEL11_10 - break; - } - case 221: - { - PIXEL00_12 - if (diff(w[6], w[8])) - { - PIXEL01_11 - PIXEL11_0 - } - else - { - PIXEL01_60 - PIXEL11_90 - } - PIXEL10_10 - break; - } - case 207: - { - if (diff(w[4], w[2])) - { - PIXEL00_0 - PIXEL01_12 - } - else - { - PIXEL00_90 - PIXEL01_61 - } - PIXEL10_10 - PIXEL11_11 - break; - } - case 238: - { - PIXEL00_10 - PIXEL01_12 - if (diff(w[8], w[4])) - { - PIXEL10_0 - PIXEL11_11 - } - else - { - PIXEL10_90 - PIXEL11_60 - } - break; - } - case 190: - { - PIXEL00_10 - if (diff(w[2], w[6])) - { - PIXEL01_0 - PIXEL11_12 - } - else - { - PIXEL01_90 - PIXEL11_61 - } - PIXEL10_11 - break; - } - case 187: - { - if (diff(w[4], w[2])) - { - PIXEL00_0 - PIXEL10_11 - } - else - { - PIXEL00_90 - PIXEL10_60 - } - PIXEL01_10 - PIXEL11_12 - break; - } - case 243: - { - PIXEL00_11 - PIXEL01_10 - if (diff(w[6], w[8])) - { - PIXEL10_12 - PIXEL11_0 - } - else - { - PIXEL10_61 - PIXEL11_90 - } - break; - } - case 119: - { - if (diff(w[2], w[6])) - { - PIXEL00_11 - PIXEL01_0 - } - else - { - PIXEL00_60 - PIXEL01_90 - } - PIXEL10_12 - PIXEL11_10 - break; - } - case 237: - case 233: - { - PIXEL00_12 - PIXEL01_20 - if (diff(w[8], w[4])) - { - PIXEL10_0 - } - else - { - PIXEL10_100 - } - PIXEL11_11 - break; - } - case 175: - case 47: - { - if (diff(w[4], w[2])) - { - PIXEL00_0 - } - else - { - PIXEL00_100 - } - PIXEL01_12 - PIXEL10_11 - PIXEL11_20 - break; - } - case 183: - case 151: - { - PIXEL00_11 - if (diff(w[2], w[6])) - { - PIXEL01_0 - } - else - { - PIXEL01_100 - } - PIXEL10_20 - PIXEL11_12 - break; - } - case 245: - case 244: - { - PIXEL00_20 - PIXEL01_11 - PIXEL10_12 - if (diff(w[6], w[8])) - { - PIXEL11_0 - } - else - { - PIXEL11_100 - } - break; - } - case 250: - { - PIXEL00_10 - PIXEL01_10 - if (diff(w[8], w[4])) - { - PIXEL10_0 - } - else - { - PIXEL10_20 - } - if (diff(w[6], w[8])) - { - PIXEL11_0 - } - else - { - PIXEL11_20 - } - break; - } - case 123: - { - if (diff(w[4], w[2])) - { - PIXEL00_0 - } - else - { - PIXEL00_20 - } - PIXEL01_10 - if (diff(w[8], w[4])) - { - PIXEL10_0 - } - else - { - PIXEL10_20 - } - PIXEL11_10 - break; - } - case 95: - { - if (diff(w[4], w[2])) - { - PIXEL00_0 - } - else - { - PIXEL00_20 - } - if (diff(w[2], w[6])) - { - PIXEL01_0 - } - else - { - PIXEL01_20 - } - PIXEL10_10 - PIXEL11_10 - break; - } - case 222: - { - PIXEL00_10 - if (diff(w[2], w[6])) - { - PIXEL01_0 - } - else - { - PIXEL01_20 - } - PIXEL10_10 - if (diff(w[6], w[8])) - { - PIXEL11_0 - } - else - { - PIXEL11_20 - } - break; - } - case 252: - { - PIXEL00_21 - PIXEL01_11 - if (diff(w[8], w[4])) - { - PIXEL10_0 - } - else - { - PIXEL10_20 - } - if (diff(w[6], w[8])) - { - PIXEL11_0 - } - else - { - PIXEL11_100 - } - break; - } - case 249: - { - PIXEL00_12 - PIXEL01_22 - if (diff(w[8], w[4])) - { - PIXEL10_0 - } - else - { - PIXEL10_100 - } - if (diff(w[6], w[8])) - { - PIXEL11_0 - } - else - { - PIXEL11_20 - } - break; - } - case 235: - { - if (diff(w[4], w[2])) - { - PIXEL00_0 - } - else - { - PIXEL00_20 - } - PIXEL01_21 - if (diff(w[8], w[4])) - { - PIXEL10_0 - } - else - { - PIXEL10_100 - } - PIXEL11_11 - break; - } - case 111: - { - if (diff(w[4], w[2])) - { - PIXEL00_0 - } - else - { - PIXEL00_100 - } - PIXEL01_12 - if (diff(w[8], w[4])) - { - PIXEL10_0 - } - else - { - PIXEL10_20 - } - PIXEL11_22 - break; - } - case 63: - { - if (diff(w[4], w[2])) - { - PIXEL00_0 - } - else - { - PIXEL00_100 - } - if (diff(w[2], w[6])) - { - PIXEL01_0 - } - else - { - PIXEL01_20 - } - PIXEL10_11 - PIXEL11_21 - break; - } - case 159: - { - if (diff(w[4], w[2])) - { - PIXEL00_0 - } - else - { - PIXEL00_20 - } - if (diff(w[2], w[6])) - { - PIXEL01_0 - } - else - { - PIXEL01_100 - } - PIXEL10_22 - PIXEL11_12 - break; - } - case 215: - { - PIXEL00_11 - if (diff(w[2], w[6])) - { - PIXEL01_0 - } - else - { - PIXEL01_100 - } - PIXEL10_21 - if (diff(w[6], w[8])) - { - PIXEL11_0 - } - else - { - PIXEL11_20 - } - break; - } - case 246: - { - PIXEL00_22 - if (diff(w[2], w[6])) - { - PIXEL01_0 - } - else - { - PIXEL01_20 - } - PIXEL10_12 - if (diff(w[6], w[8])) - { - PIXEL11_0 - } - else - { - PIXEL11_100 - } - break; - } - case 254: - { - PIXEL00_10 - if (diff(w[2], w[6])) - { - PIXEL01_0 - } - else - { - PIXEL01_20 - } - if (diff(w[8], w[4])) - { - PIXEL10_0 - } - else - { - PIXEL10_20 - } - if (diff(w[6], w[8])) - { - PIXEL11_0 - } - else - { - PIXEL11_100 - } - break; - } - case 253: - { - PIXEL00_12 - PIXEL01_11 - if (diff(w[8], w[4])) - { - PIXEL10_0 - } - else - { - PIXEL10_100 - } - if (diff(w[6], w[8])) - { - PIXEL11_0 - } - else - { - PIXEL11_100 - } - break; - } - case 251: - { - if (diff(w[4], w[2])) - { - PIXEL00_0 - } - else - { - PIXEL00_20 - } - PIXEL01_10 - if (diff(w[8], w[4])) - { - PIXEL10_0 - } - else - { - PIXEL10_100 - } - if (diff(w[6], w[8])) - { - PIXEL11_0 - } - else - { - PIXEL11_20 - } - break; - } - case 239: - { - if (diff(w[4], w[2])) - { - PIXEL00_0 - } - else - { - PIXEL00_100 - } - PIXEL01_12 - if (diff(w[8], w[4])) - { - PIXEL10_0 - } - else - { - PIXEL10_100 - } - PIXEL11_11 - break; - } - case 127: - { - if (diff(w[4], w[2])) - { - PIXEL00_0 - } - else - { - PIXEL00_100 - } - if (diff(w[2], w[6])) - { - PIXEL01_0 - } - else - { - PIXEL01_20 - } - if (diff(w[8], w[4])) - { - PIXEL10_0 - } - else - { - PIXEL10_20 - } - PIXEL11_10 - break; - } - case 191: - { - if (diff(w[4], w[2])) - { - PIXEL00_0 - } - else - { - PIXEL00_100 - } - if (diff(w[2], w[6])) - { - PIXEL01_0 - } - else - { - PIXEL01_100 - } - PIXEL10_11 - PIXEL11_12 - break; - } - case 223: - { - if (diff(w[4], w[2])) - { - PIXEL00_0 - } - else - { - PIXEL00_20 - } - if (diff(w[2], w[6])) - { - PIXEL01_0 - } - else - { - PIXEL01_100 - } - PIXEL10_10 - if (diff(w[6], w[8])) - { - PIXEL11_0 - } - else - { - PIXEL11_20 - } - break; - } - case 247: - { - PIXEL00_11 - if (diff(w[2], w[6])) - { - PIXEL01_0 - } - else - { - PIXEL01_100 - } - PIXEL10_12 - if (diff(w[6], w[8])) - { - PIXEL11_0 - } - else - { - PIXEL11_100 - } - break; - } - case 255: - { - if (diff(w[4], w[2])) - { - PIXEL00_0 - } - else - { - PIXEL00_100 - } - if (diff(w[2], w[6])) - { - PIXEL01_0 - } - else - { - PIXEL01_100 - } - if (diff(w[8], w[4])) - { - PIXEL10_0 - } - else - { - PIXEL10_100 - } - if (diff(w[6], w[8])) - { - PIXEL11_0 - } - else - { - PIXEL11_100 - } - break; - } - } - - ++in; - out += 2; - } - - out += dstPitch * 2 - std::ptrdiff_t(x_res) * 2; - } -} - -MaxStHq2x::MaxStHq2x() -: buffer_(std::size_t(VfilterInfo::in_height) * VfilterInfo::in_width) -{ -} - -void * MaxStHq2x::inBuf() const { - return buffer_; -} - -std::ptrdiff_t MaxStHq2x::inPitch() const { - return VfilterInfo::in_width; -} - -void MaxStHq2x::draw(void *dbuffer, std::ptrdiff_t dpitch) { - ::filter( - static_cast(dbuffer), dpitch, - buffer_); -} diff --git a/common/videolink/vfilters/maxsthq2x.h b/common/videolink/vfilters/maxsthq2x.h deleted file mode 100644 index e9388e4a..00000000 --- a/common/videolink/vfilters/maxsthq2x.h +++ /dev/null @@ -1,41 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef MAXSTHQ2X_H -#define MAXSTHQ2X_H - -#include "../videolink.h" -#include "../vfilterinfo.h" -#include "array.h" -#include "gbint.h" - -class MaxStHq2x : public VideoLink { -public: - enum { out_width = VfilterInfo::in_width * 2 }; - enum { out_height = VfilterInfo::in_height * 2 }; - - MaxStHq2x(); - virtual void * inBuf() const; - virtual std::ptrdiff_t inPitch() const; - virtual void draw(void *dst, std::ptrdiff_t dstpitch); - -private: - SimpleArray const buffer_; -}; - -#endif diff --git a/common/videolink/vfilters/maxsthq3x.cpp b/common/videolink/vfilters/maxsthq3x.cpp deleted file mode 100644 index fd52ade5..00000000 --- a/common/videolink/vfilters/maxsthq3x.cpp +++ /dev/null @@ -1,3824 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * Copyright (C) 2003 MaxSt * - * maxst@hiend3d.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#include "maxsthq3x.h" - -static unsigned long blend1(unsigned long c1, unsigned long c2) { - unsigned long lowbits = ((c1 & 0x030303) * 3 + (c2 & 0x030303)) & 0x030303; - return (c1 * 3 + c2 - lowbits) >> 2; -} - -static unsigned long blend2(unsigned long c1, unsigned long c2, unsigned long c3) { - unsigned long lowbits = ((c1 & 0x030303) * 2 - + (c2 & 0x030303) - + (c3 & 0x030303)) & 0x030303; - return (c1 * 2 + c2 + c3 - lowbits) >> 2; -} - -static unsigned long blend3(unsigned long c1, unsigned long c2) { - unsigned long lowbits = ((c1 & 0x070707) * 7 + (c2 & 0x070707)) & 0x070707; - return (c1 * 7 + c2 - lowbits) >> 3; -} - -static unsigned long blend4(unsigned long c1, unsigned long c2, unsigned long c3) { - unsigned long lowbits = ((c1 & 0x0F0F0F) * 2 - + ((c2 & 0x0F0F0F) + (c3 & 0x0F0F0F)) * 7) & 0x0F0F0F; - return (c1 * 2 + (c2 + c3) * 7 - lowbits) >> 4; -} - -static unsigned long blend5(unsigned long c1, unsigned long c2) { - return (c1 + c2 - ((c1 ^ c2) & 0x010101)) >> 1; -} - -#define PIXEL00_1M *(out ) = blend1(w[5], w[1]); -#define PIXEL00_1U *(out ) = blend1(w[5], w[2]); -#define PIXEL00_1L *(out ) = blend1(w[5], w[4]); -#define PIXEL00_2 *(out ) = blend2(w[5], w[4], w[2]); -#define PIXEL00_4 *(out ) = blend4(w[5], w[4], w[2]); -#define PIXEL00_5 *(out ) = blend5(w[4], w[2]); -#define PIXEL00_C *(out ) = w[5]; - -#define PIXEL01_1 *(out + 1) = blend1(w[5], w[2]); -#define PIXEL01_3 *(out + 1) = blend3(w[5], w[2]); -#define PIXEL01_6 *(out + 1) = blend1(w[2], w[5]); -#define PIXEL01_C *(out + 1) = w[5]; - -#define PIXEL02_1M *(out + 2) = blend1(w[5], w[3]); -#define PIXEL02_1U *(out + 2) = blend1(w[5], w[2]); -#define PIXEL02_1R *(out + 2) = blend1(w[5], w[6]); -#define PIXEL02_2 *(out + 2) = blend2(w[5], w[2], w[6]); -#define PIXEL02_4 *(out + 2) = blend4(w[5], w[2], w[6]); -#define PIXEL02_5 *(out + 2) = blend5(w[2], w[6]); -#define PIXEL02_C *(out + 2) = w[5]; - -#define PIXEL10_1 *(out + dstPitch ) = blend1(w[5], w[4]); -#define PIXEL10_3 *(out + dstPitch ) = blend3(w[5], w[4]); -#define PIXEL10_6 *(out + dstPitch ) = blend1(w[4], w[5]); -#define PIXEL10_C *(out + dstPitch ) = w[5]; - -#define PIXEL11 *(out + dstPitch + 1) = w[5]; - -#define PIXEL12_1 *(out + dstPitch + 2) = blend1(w[5], w[6]); -#define PIXEL12_3 *(out + dstPitch + 2) = blend3(w[5], w[6]); -#define PIXEL12_6 *(out + dstPitch + 2) = blend1(w[6], w[5]); -#define PIXEL12_C *(out + dstPitch + 2) = w[5]; - -#define PIXEL20_1M *(out + dstPitch * 2 ) = blend1(w[5], w[7]); -#define PIXEL20_1D *(out + dstPitch * 2 ) = blend1(w[5], w[8]); -#define PIXEL20_1L *(out + dstPitch * 2 ) = blend1(w[5], w[4]); -#define PIXEL20_2 *(out + dstPitch * 2 ) = blend2(w[5], w[8], w[4]); -#define PIXEL20_4 *(out + dstPitch * 2 ) = blend4(w[5], w[8], w[4]); -#define PIXEL20_5 *(out + dstPitch * 2 ) = blend5(w[8], w[4]); -#define PIXEL20_C *(out + dstPitch * 2 ) = w[5]; - -#define PIXEL21_1 *(out + dstPitch * 2 + 1) = blend1(w[5], w[8]); -#define PIXEL21_3 *(out + dstPitch * 2 + 1) = blend3(w[5], w[8]); -#define PIXEL21_6 *(out + dstPitch * 2 + 1) = blend1(w[8], w[5]); -#define PIXEL21_C *(out + dstPitch * 2 + 1) = w[5]; - -#define PIXEL22_1M *(out + dstPitch * 2 + 2) = blend1(w[5], w[9]); -#define PIXEL22_1D *(out + dstPitch * 2 + 2) = blend1(w[5], w[8]); -#define PIXEL22_1R *(out + dstPitch * 2 + 2) = blend1(w[5], w[6]); -#define PIXEL22_2 *(out + dstPitch * 2 + 2) = blend2(w[5], w[6], w[8]); -#define PIXEL22_4 *(out + dstPitch * 2 + 2) = blend4(w[5], w[6], w[8]); -#define PIXEL22_5 *(out + dstPitch * 2 + 2) = blend5(w[6], w[8]); -#define PIXEL22_C *(out + dstPitch * 2 + 2) = w[5]; - -static bool diff(unsigned long const w1, unsigned long const w2) { - unsigned rdiff = (w1 >> 16 ) - (w2 >> 16 ); - unsigned gdiff = (w1 >> 8 & 0xFF) - (w2 >> 8 & 0xFF); - unsigned bdiff = (w1 & 0xFF) - (w2 & 0xFF); - - return rdiff + gdiff + bdiff + 0xC0U > 0xC0U * 2 - || rdiff - bdiff + 0x1CU > 0x1CU * 2 - || gdiff * 2 - rdiff - bdiff + 0x30U > 0x30U * 2; -} - -template -static void filter(gambatte::uint_least32_t *out, - std::ptrdiff_t const dstPitch, - gambatte::uint_least32_t const *in) -{ - unsigned long w[10]; - // +----+----+----+ - // | | | | - // | w1 | w2 | w3 | - // +----+----+----+ - // | | | | - // | w4 | w5 | w6 | - // +----+----+----+ - // | | | | - // | w7 | w8 | w9 | - // +----+----+----+ - - for (int j = 0; j < y_res; j++) { - std::ptrdiff_t const prevline = j > 0 ? -x_res : 0; - std::ptrdiff_t const nextline = j < y_res - 1 ? x_res : 0; - for (int i = 0; i < x_res; i++) { - w[2] = *(in + prevline); - w[5] = *(in ); - w[8] = *(in + nextline); - if (i > 0) { - w[1] = *(in + prevline - 1); - w[4] = *(in - 1); - w[7] = *(in + nextline - 1); - } else { - w[1] = w[2]; - w[4] = w[5]; - w[7] = w[8]; - } - if (i < x_res - 1) { - w[3] = *(in + prevline + 1); - w[6] = *(in + 1); - w[9] = *(in + nextline + 1); - } else { - w[3] = w[2]; - w[6] = w[5]; - w[9] = w[8]; - } - - unsigned pattern = 0; - - { - unsigned const r1 = w[5] >> 16 ; - unsigned const g1 = w[5] >> 8 & 0xFF; - unsigned const b1 = w[5] & 0xFF; - unsigned flag = 1; - for (int k = 1; k < 10; ++k) { - if (k == 5) - continue; - - if (w[k] != w[5]) { - unsigned const rdiff = r1 - (w[k] >> 16 ); - unsigned const gdiff = g1 - (w[k] >> 8 & 0xFF); - unsigned const bdiff = b1 - (w[k] & 0xFF); - if (rdiff + gdiff + bdiff + 0xC0U > 0xC0U * 2 - || rdiff - bdiff + 0x1CU > 0x1CU * 2 - || gdiff * 2 - rdiff - bdiff + 0x30U > 0x30U * 2) { - pattern |= flag; - } - } - - flag <<= 1; - } - } - - switch (pattern) { - case 0: - case 1: - case 4: - case 32: - case 128: - case 5: - case 132: - case 160: - case 33: - case 129: - case 36: - case 133: - case 164: - case 161: - case 37: - case 165: - { - PIXEL00_2 - PIXEL01_1 - PIXEL02_2 - PIXEL10_1 - PIXEL11 - PIXEL12_1 - PIXEL20_2 - PIXEL21_1 - PIXEL22_2 - break; - } - case 2: - case 34: - case 130: - case 162: - { - PIXEL00_1M - PIXEL01_C - PIXEL02_1M - PIXEL10_1 - PIXEL11 - PIXEL12_1 - PIXEL20_2 - PIXEL21_1 - PIXEL22_2 - break; - } - case 16: - case 17: - case 48: - case 49: - { - PIXEL00_2 - PIXEL01_1 - PIXEL02_1M - PIXEL10_1 - PIXEL11 - PIXEL12_C - PIXEL20_2 - PIXEL21_1 - PIXEL22_1M - break; - } - case 64: - case 65: - case 68: - case 69: - { - PIXEL00_2 - PIXEL01_1 - PIXEL02_2 - PIXEL10_1 - PIXEL11 - PIXEL12_1 - PIXEL20_1M - PIXEL21_C - PIXEL22_1M - break; - } - case 8: - case 12: - case 136: - case 140: - { - PIXEL00_1M - PIXEL01_1 - PIXEL02_2 - PIXEL10_C - PIXEL11 - PIXEL12_1 - PIXEL20_1M - PIXEL21_1 - PIXEL22_2 - break; - } - case 3: - case 35: - case 131: - case 163: - { - PIXEL00_1L - PIXEL01_C - PIXEL02_1M - PIXEL10_1 - PIXEL11 - PIXEL12_1 - PIXEL20_2 - PIXEL21_1 - PIXEL22_2 - break; - } - case 6: - case 38: - case 134: - case 166: - { - PIXEL00_1M - PIXEL01_C - PIXEL02_1R - PIXEL10_1 - PIXEL11 - PIXEL12_1 - PIXEL20_2 - PIXEL21_1 - PIXEL22_2 - break; - } - case 20: - case 21: - case 52: - case 53: - { - PIXEL00_2 - PIXEL01_1 - PIXEL02_1U - PIXEL10_1 - PIXEL11 - PIXEL12_C - PIXEL20_2 - PIXEL21_1 - PIXEL22_1M - break; - } - case 144: - case 145: - case 176: - case 177: - { - PIXEL00_2 - PIXEL01_1 - PIXEL02_1M - PIXEL10_1 - PIXEL11 - PIXEL12_C - PIXEL20_2 - PIXEL21_1 - PIXEL22_1D - break; - } - case 192: - case 193: - case 196: - case 197: - { - PIXEL00_2 - PIXEL01_1 - PIXEL02_2 - PIXEL10_1 - PIXEL11 - PIXEL12_1 - PIXEL20_1M - PIXEL21_C - PIXEL22_1R - break; - } - case 96: - case 97: - case 100: - case 101: - { - PIXEL00_2 - PIXEL01_1 - PIXEL02_2 - PIXEL10_1 - PIXEL11 - PIXEL12_1 - PIXEL20_1L - PIXEL21_C - PIXEL22_1M - break; - } - case 40: - case 44: - case 168: - case 172: - { - PIXEL00_1M - PIXEL01_1 - PIXEL02_2 - PIXEL10_C - PIXEL11 - PIXEL12_1 - PIXEL20_1D - PIXEL21_1 - PIXEL22_2 - break; - } - case 9: - case 13: - case 137: - case 141: - { - PIXEL00_1U - PIXEL01_1 - PIXEL02_2 - PIXEL10_C - PIXEL11 - PIXEL12_1 - PIXEL20_1M - PIXEL21_1 - PIXEL22_2 - break; - } - case 18: - case 50: - { - PIXEL00_1M - if (diff(w[2], w[6])) - { - PIXEL01_C - PIXEL02_1M - PIXEL12_C - } - else - { - PIXEL01_3 - PIXEL02_4 - PIXEL12_3 - } - PIXEL10_1 - PIXEL11 - PIXEL20_2 - PIXEL21_1 - PIXEL22_1M - break; - } - case 80: - case 81: - { - PIXEL00_2 - PIXEL01_1 - PIXEL02_1M - PIXEL10_1 - PIXEL11 - PIXEL20_1M - if (diff(w[6], w[8])) - { - PIXEL12_C - PIXEL21_C - PIXEL22_1M - } - else - { - PIXEL12_3 - PIXEL21_3 - PIXEL22_4 - } - break; - } - case 72: - case 76: - { - PIXEL00_1M - PIXEL01_1 - PIXEL02_2 - PIXEL11 - PIXEL12_1 - if (diff(w[8], w[4])) - { - PIXEL10_C - PIXEL20_1M - PIXEL21_C - } - else - { - PIXEL10_3 - PIXEL20_4 - PIXEL21_3 - } - PIXEL22_1M - break; - } - case 10: - case 138: - { - if (diff(w[4], w[2])) - { - PIXEL00_1M - PIXEL01_C - PIXEL10_C - } - else - { - PIXEL00_4 - PIXEL01_3 - PIXEL10_3 - } - PIXEL02_1M - PIXEL11 - PIXEL12_1 - PIXEL20_1M - PIXEL21_1 - PIXEL22_2 - break; - } - case 66: - { - PIXEL00_1M - PIXEL01_C - PIXEL02_1M - PIXEL10_1 - PIXEL11 - PIXEL12_1 - PIXEL20_1M - PIXEL21_C - PIXEL22_1M - break; - } - case 24: - { - PIXEL00_1M - PIXEL01_1 - PIXEL02_1M - PIXEL10_C - PIXEL11 - PIXEL12_C - PIXEL20_1M - PIXEL21_1 - PIXEL22_1M - break; - } - case 7: - case 39: - case 135: - { - PIXEL00_1L - PIXEL01_C - PIXEL02_1R - PIXEL10_1 - PIXEL11 - PIXEL12_1 - PIXEL20_2 - PIXEL21_1 - PIXEL22_2 - break; - } - case 148: - case 149: - case 180: - { - PIXEL00_2 - PIXEL01_1 - PIXEL02_1U - PIXEL10_1 - PIXEL11 - PIXEL12_C - PIXEL20_2 - PIXEL21_1 - PIXEL22_1D - break; - } - case 224: - case 228: - case 225: - { - PIXEL00_2 - PIXEL01_1 - PIXEL02_2 - PIXEL10_1 - PIXEL11 - PIXEL12_1 - PIXEL20_1L - PIXEL21_C - PIXEL22_1R - break; - } - case 41: - case 169: - case 45: - { - PIXEL00_1U - PIXEL01_1 - PIXEL02_2 - PIXEL10_C - PIXEL11 - PIXEL12_1 - PIXEL20_1D - PIXEL21_1 - PIXEL22_2 - break; - } - case 22: - case 54: - { - PIXEL00_1M - if (diff(w[2], w[6])) - { - PIXEL01_C - PIXEL02_C - PIXEL12_C - } - else - { - PIXEL01_3 - PIXEL02_4 - PIXEL12_3 - } - PIXEL10_1 - PIXEL11 - PIXEL20_2 - PIXEL21_1 - PIXEL22_1M - break; - } - case 208: - case 209: - { - PIXEL00_2 - PIXEL01_1 - PIXEL02_1M - PIXEL10_1 - PIXEL11 - PIXEL20_1M - if (diff(w[6], w[8])) - { - PIXEL12_C - PIXEL21_C - PIXEL22_C - } - else - { - PIXEL12_3 - PIXEL21_3 - PIXEL22_4 - } - break; - } - case 104: - case 108: - { - PIXEL00_1M - PIXEL01_1 - PIXEL02_2 - PIXEL11 - PIXEL12_1 - if (diff(w[8], w[4])) - { - PIXEL10_C - PIXEL20_C - PIXEL21_C - } - else - { - PIXEL10_3 - PIXEL20_4 - PIXEL21_3 - } - PIXEL22_1M - break; - } - case 11: - case 139: - { - if (diff(w[4], w[2])) - { - PIXEL00_C - PIXEL01_C - PIXEL10_C - } - else - { - PIXEL00_4 - PIXEL01_3 - PIXEL10_3 - } - PIXEL02_1M - PIXEL11 - PIXEL12_1 - PIXEL20_1M - PIXEL21_1 - PIXEL22_2 - break; - } - case 19: - case 51: - { - if (diff(w[2], w[6])) - { - PIXEL00_1L - PIXEL01_C - PIXEL02_1M - PIXEL12_C - } - else - { - PIXEL00_2 - PIXEL01_6 - PIXEL02_5 - PIXEL12_1 - } - PIXEL10_1 - PIXEL11 - PIXEL20_2 - PIXEL21_1 - PIXEL22_1M - break; - } - case 146: - case 178: - { - if (diff(w[2], w[6])) - { - PIXEL01_C - PIXEL02_1M - PIXEL12_C - PIXEL22_1D - } - else - { - PIXEL01_1 - PIXEL02_5 - PIXEL12_6 - PIXEL22_2 - } - PIXEL00_1M - PIXEL10_1 - PIXEL11 - PIXEL20_2 - PIXEL21_1 - break; - } - case 84: - case 85: - { - if (diff(w[6], w[8])) - { - PIXEL02_1U - PIXEL12_C - PIXEL21_C - PIXEL22_1M - } - else - { - PIXEL02_2 - PIXEL12_6 - PIXEL21_1 - PIXEL22_5 - } - PIXEL00_2 - PIXEL01_1 - PIXEL10_1 - PIXEL11 - PIXEL20_1M - break; - } - case 112: - case 113: - { - if (diff(w[6], w[8])) - { - PIXEL12_C - PIXEL20_1L - PIXEL21_C - PIXEL22_1M - } - else - { - PIXEL12_1 - PIXEL20_2 - PIXEL21_6 - PIXEL22_5 - } - PIXEL00_2 - PIXEL01_1 - PIXEL02_1M - PIXEL10_1 - PIXEL11 - break; - } - case 200: - case 204: - { - if (diff(w[8], w[4])) - { - PIXEL10_C - PIXEL20_1M - PIXEL21_C - PIXEL22_1R - } - else - { - PIXEL10_1 - PIXEL20_5 - PIXEL21_6 - PIXEL22_2 - } - PIXEL00_1M - PIXEL01_1 - PIXEL02_2 - PIXEL11 - PIXEL12_1 - break; - } - case 73: - case 77: - { - if (diff(w[8], w[4])) - { - PIXEL00_1U - PIXEL10_C - PIXEL20_1M - PIXEL21_C - } - else - { - PIXEL00_2 - PIXEL10_6 - PIXEL20_5 - PIXEL21_1 - } - PIXEL01_1 - PIXEL02_2 - PIXEL11 - PIXEL12_1 - PIXEL22_1M - break; - } - case 42: - case 170: - { - if (diff(w[4], w[2])) - { - PIXEL00_1M - PIXEL01_C - PIXEL10_C - PIXEL20_1D - } - else - { - PIXEL00_5 - PIXEL01_1 - PIXEL10_6 - PIXEL20_2 - } - PIXEL02_1M - PIXEL11 - PIXEL12_1 - PIXEL21_1 - PIXEL22_2 - break; - } - case 14: - case 142: - { - if (diff(w[4], w[2])) - { - PIXEL00_1M - PIXEL01_C - PIXEL02_1R - PIXEL10_C - } - else - { - PIXEL00_5 - PIXEL01_6 - PIXEL02_2 - PIXEL10_1 - } - PIXEL11 - PIXEL12_1 - PIXEL20_1M - PIXEL21_1 - PIXEL22_2 - break; - } - case 67: - { - PIXEL00_1L - PIXEL01_C - PIXEL02_1M - PIXEL10_1 - PIXEL11 - PIXEL12_1 - PIXEL20_1M - PIXEL21_C - PIXEL22_1M - break; - } - case 70: - { - PIXEL00_1M - PIXEL01_C - PIXEL02_1R - PIXEL10_1 - PIXEL11 - PIXEL12_1 - PIXEL20_1M - PIXEL21_C - PIXEL22_1M - break; - } - case 28: - { - PIXEL00_1M - PIXEL01_1 - PIXEL02_1U - PIXEL10_C - PIXEL11 - PIXEL12_C - PIXEL20_1M - PIXEL21_1 - PIXEL22_1M - break; - } - case 152: - { - PIXEL00_1M - PIXEL01_1 - PIXEL02_1M - PIXEL10_C - PIXEL11 - PIXEL12_C - PIXEL20_1M - PIXEL21_1 - PIXEL22_1D - break; - } - case 194: - { - PIXEL00_1M - PIXEL01_C - PIXEL02_1M - PIXEL10_1 - PIXEL11 - PIXEL12_1 - PIXEL20_1M - PIXEL21_C - PIXEL22_1R - break; - } - case 98: - { - PIXEL00_1M - PIXEL01_C - PIXEL02_1M - PIXEL10_1 - PIXEL11 - PIXEL12_1 - PIXEL20_1L - PIXEL21_C - PIXEL22_1M - break; - } - case 56: - { - PIXEL00_1M - PIXEL01_1 - PIXEL02_1M - PIXEL10_C - PIXEL11 - PIXEL12_C - PIXEL20_1D - PIXEL21_1 - PIXEL22_1M - break; - } - case 25: - { - PIXEL00_1U - PIXEL01_1 - PIXEL02_1M - PIXEL10_C - PIXEL11 - PIXEL12_C - PIXEL20_1M - PIXEL21_1 - PIXEL22_1M - break; - } - case 26: - case 31: - { - if (diff(w[4], w[2])) - { - PIXEL00_C - PIXEL10_C - } - else - { - PIXEL00_4 - PIXEL10_3 - } - PIXEL01_C - if (diff(w[2], w[6])) - { - PIXEL02_C - PIXEL12_C - } - else - { - PIXEL02_4 - PIXEL12_3 - } - PIXEL11 - PIXEL20_1M - PIXEL21_1 - PIXEL22_1M - break; - } - case 82: - case 214: - { - PIXEL00_1M - if (diff(w[2], w[6])) - { - PIXEL01_C - PIXEL02_C - } - else - { - PIXEL01_3 - PIXEL02_4 - } - PIXEL10_1 - PIXEL11 - PIXEL12_C - PIXEL20_1M - if (diff(w[6], w[8])) - { - PIXEL21_C - PIXEL22_C - } - else - { - PIXEL21_3 - PIXEL22_4 - } - break; - } - case 88: - case 248: - { - PIXEL00_1M - PIXEL01_1 - PIXEL02_1M - PIXEL11 - if (diff(w[8], w[4])) - { - PIXEL10_C - PIXEL20_C - } - else - { - PIXEL10_3 - PIXEL20_4 - } - PIXEL21_C - if (diff(w[6], w[8])) - { - PIXEL12_C - PIXEL22_C - } - else - { - PIXEL12_3 - PIXEL22_4 - } - break; - } - case 74: - case 107: - { - if (diff(w[4], w[2])) - { - PIXEL00_C - PIXEL01_C - } - else - { - PIXEL00_4 - PIXEL01_3 - } - PIXEL02_1M - PIXEL10_C - PIXEL11 - PIXEL12_1 - if (diff(w[8], w[4])) - { - PIXEL20_C - PIXEL21_C - } - else - { - PIXEL20_4 - PIXEL21_3 - } - PIXEL22_1M - break; - } - case 27: - { - if (diff(w[4], w[2])) - { - PIXEL00_C - PIXEL01_C - PIXEL10_C - } - else - { - PIXEL00_4 - PIXEL01_3 - PIXEL10_3 - } - PIXEL02_1M - PIXEL11 - PIXEL12_C - PIXEL20_1M - PIXEL21_1 - PIXEL22_1M - break; - } - case 86: - { - PIXEL00_1M - if (diff(w[2], w[6])) - { - PIXEL01_C - PIXEL02_C - PIXEL12_C - } - else - { - PIXEL01_3 - PIXEL02_4 - PIXEL12_3 - } - PIXEL10_1 - PIXEL11 - PIXEL20_1M - PIXEL21_C - PIXEL22_1M - break; - } - case 216: - { - PIXEL00_1M - PIXEL01_1 - PIXEL02_1M - PIXEL10_C - PIXEL11 - PIXEL20_1M - if (diff(w[6], w[8])) - { - PIXEL12_C - PIXEL21_C - PIXEL22_C - } - else - { - PIXEL12_3 - PIXEL21_3 - PIXEL22_4 - } - break; - } - case 106: - { - PIXEL00_1M - PIXEL01_C - PIXEL02_1M - PIXEL11 - PIXEL12_1 - if (diff(w[8], w[4])) - { - PIXEL10_C - PIXEL20_C - PIXEL21_C - } - else - { - PIXEL10_3 - PIXEL20_4 - PIXEL21_3 - } - PIXEL22_1M - break; - } - case 30: - { - PIXEL00_1M - if (diff(w[2], w[6])) - { - PIXEL01_C - PIXEL02_C - PIXEL12_C - } - else - { - PIXEL01_3 - PIXEL02_4 - PIXEL12_3 - } - PIXEL10_C - PIXEL11 - PIXEL20_1M - PIXEL21_1 - PIXEL22_1M - break; - } - case 210: - { - PIXEL00_1M - PIXEL01_C - PIXEL02_1M - PIXEL10_1 - PIXEL11 - PIXEL20_1M - if (diff(w[6], w[8])) - { - PIXEL12_C - PIXEL21_C - PIXEL22_C - } - else - { - PIXEL12_3 - PIXEL21_3 - PIXEL22_4 - } - break; - } - case 120: - { - PIXEL00_1M - PIXEL01_1 - PIXEL02_1M - PIXEL11 - PIXEL12_C - if (diff(w[8], w[4])) - { - PIXEL10_C - PIXEL20_C - PIXEL21_C - } - else - { - PIXEL10_3 - PIXEL20_4 - PIXEL21_3 - } - PIXEL22_1M - break; - } - case 75: - { - if (diff(w[4], w[2])) - { - PIXEL00_C - PIXEL01_C - PIXEL10_C - } - else - { - PIXEL00_4 - PIXEL01_3 - PIXEL10_3 - } - PIXEL02_1M - PIXEL11 - PIXEL12_1 - PIXEL20_1M - PIXEL21_C - PIXEL22_1M - break; - } - case 29: - { - PIXEL00_1U - PIXEL01_1 - PIXEL02_1U - PIXEL10_C - PIXEL11 - PIXEL12_C - PIXEL20_1M - PIXEL21_1 - PIXEL22_1M - break; - } - case 198: - { - PIXEL00_1M - PIXEL01_C - PIXEL02_1R - PIXEL10_1 - PIXEL11 - PIXEL12_1 - PIXEL20_1M - PIXEL21_C - PIXEL22_1R - break; - } - case 184: - { - PIXEL00_1M - PIXEL01_1 - PIXEL02_1M - PIXEL10_C - PIXEL11 - PIXEL12_C - PIXEL20_1D - PIXEL21_1 - PIXEL22_1D - break; - } - case 99: - { - PIXEL00_1L - PIXEL01_C - PIXEL02_1M - PIXEL10_1 - PIXEL11 - PIXEL12_1 - PIXEL20_1L - PIXEL21_C - PIXEL22_1M - break; - } - case 57: - { - PIXEL00_1U - PIXEL01_1 - PIXEL02_1M - PIXEL10_C - PIXEL11 - PIXEL12_C - PIXEL20_1D - PIXEL21_1 - PIXEL22_1M - break; - } - case 71: - { - PIXEL00_1L - PIXEL01_C - PIXEL02_1R - PIXEL10_1 - PIXEL11 - PIXEL12_1 - PIXEL20_1M - PIXEL21_C - PIXEL22_1M - break; - } - case 156: - { - PIXEL00_1M - PIXEL01_1 - PIXEL02_1U - PIXEL10_C - PIXEL11 - PIXEL12_C - PIXEL20_1M - PIXEL21_1 - PIXEL22_1D - break; - } - case 226: - { - PIXEL00_1M - PIXEL01_C - PIXEL02_1M - PIXEL10_1 - PIXEL11 - PIXEL12_1 - PIXEL20_1L - PIXEL21_C - PIXEL22_1R - break; - } - case 60: - { - PIXEL00_1M - PIXEL01_1 - PIXEL02_1U - PIXEL10_C - PIXEL11 - PIXEL12_C - PIXEL20_1D - PIXEL21_1 - PIXEL22_1M - break; - } - case 195: - { - PIXEL00_1L - PIXEL01_C - PIXEL02_1M - PIXEL10_1 - PIXEL11 - PIXEL12_1 - PIXEL20_1M - PIXEL21_C - PIXEL22_1R - break; - } - case 102: - { - PIXEL00_1M - PIXEL01_C - PIXEL02_1R - PIXEL10_1 - PIXEL11 - PIXEL12_1 - PIXEL20_1L - PIXEL21_C - PIXEL22_1M - break; - } - case 153: - { - PIXEL00_1U - PIXEL01_1 - PIXEL02_1M - PIXEL10_C - PIXEL11 - PIXEL12_C - PIXEL20_1M - PIXEL21_1 - PIXEL22_1D - break; - } - case 58: - { - if (diff(w[4], w[2])) - { - PIXEL00_1M - } - else - { - PIXEL00_2 - } - PIXEL01_C - if (diff(w[2], w[6])) - { - PIXEL02_1M - } - else - { - PIXEL02_2 - } - PIXEL10_C - PIXEL11 - PIXEL12_C - PIXEL20_1D - PIXEL21_1 - PIXEL22_1M - break; - } - case 83: - { - PIXEL00_1L - PIXEL01_C - if (diff(w[2], w[6])) - { - PIXEL02_1M - } - else - { - PIXEL02_2 - } - PIXEL10_1 - PIXEL11 - PIXEL12_C - PIXEL20_1M - PIXEL21_C - if (diff(w[6], w[8])) - { - PIXEL22_1M - } - else - { - PIXEL22_2 - } - break; - } - case 92: - { - PIXEL00_1M - PIXEL01_1 - PIXEL02_1U - PIXEL10_C - PIXEL11 - PIXEL12_C - if (diff(w[8], w[4])) - { - PIXEL20_1M - } - else - { - PIXEL20_2 - } - PIXEL21_C - if (diff(w[6], w[8])) - { - PIXEL22_1M - } - else - { - PIXEL22_2 - } - break; - } - case 202: - { - if (diff(w[4], w[2])) - { - PIXEL00_1M - } - else - { - PIXEL00_2 - } - PIXEL01_C - PIXEL02_1M - PIXEL10_C - PIXEL11 - PIXEL12_1 - if (diff(w[8], w[4])) - { - PIXEL20_1M - } - else - { - PIXEL20_2 - } - PIXEL21_C - PIXEL22_1R - break; - } - case 78: - { - if (diff(w[4], w[2])) - { - PIXEL00_1M - } - else - { - PIXEL00_2 - } - PIXEL01_C - PIXEL02_1R - PIXEL10_C - PIXEL11 - PIXEL12_1 - if (diff(w[8], w[4])) - { - PIXEL20_1M - } - else - { - PIXEL20_2 - } - PIXEL21_C - PIXEL22_1M - break; - } - case 154: - { - if (diff(w[4], w[2])) - { - PIXEL00_1M - } - else - { - PIXEL00_2 - } - PIXEL01_C - if (diff(w[2], w[6])) - { - PIXEL02_1M - } - else - { - PIXEL02_2 - } - PIXEL10_C - PIXEL11 - PIXEL12_C - PIXEL20_1M - PIXEL21_1 - PIXEL22_1D - break; - } - case 114: - { - PIXEL00_1M - PIXEL01_C - if (diff(w[2], w[6])) - { - PIXEL02_1M - } - else - { - PIXEL02_2 - } - PIXEL10_1 - PIXEL11 - PIXEL12_C - PIXEL20_1L - PIXEL21_C - if (diff(w[6], w[8])) - { - PIXEL22_1M - } - else - { - PIXEL22_2 - } - break; - } - case 89: - { - PIXEL00_1U - PIXEL01_1 - PIXEL02_1M - PIXEL10_C - PIXEL11 - PIXEL12_C - if (diff(w[8], w[4])) - { - PIXEL20_1M - } - else - { - PIXEL20_2 - } - PIXEL21_C - if (diff(w[6], w[8])) - { - PIXEL22_1M - } - else - { - PIXEL22_2 - } - break; - } - case 90: - { - if (diff(w[4], w[2])) - { - PIXEL00_1M - } - else - { - PIXEL00_2 - } - PIXEL01_C - if (diff(w[2], w[6])) - { - PIXEL02_1M - } - else - { - PIXEL02_2 - } - PIXEL10_C - PIXEL11 - PIXEL12_C - if (diff(w[8], w[4])) - { - PIXEL20_1M - } - else - { - PIXEL20_2 - } - PIXEL21_C - if (diff(w[6], w[8])) - { - PIXEL22_1M - } - else - { - PIXEL22_2 - } - break; - } - case 55: - case 23: - { - if (diff(w[2], w[6])) - { - PIXEL00_1L - PIXEL01_C - PIXEL02_C - PIXEL12_C - } - else - { - PIXEL00_2 - PIXEL01_6 - PIXEL02_5 - PIXEL12_1 - } - PIXEL10_1 - PIXEL11 - PIXEL20_2 - PIXEL21_1 - PIXEL22_1M - break; - } - case 182: - case 150: - { - if (diff(w[2], w[6])) - { - PIXEL01_C - PIXEL02_C - PIXEL12_C - PIXEL22_1D - } - else - { - PIXEL01_1 - PIXEL02_5 - PIXEL12_6 - PIXEL22_2 - } - PIXEL00_1M - PIXEL10_1 - PIXEL11 - PIXEL20_2 - PIXEL21_1 - break; - } - case 213: - case 212: - { - if (diff(w[6], w[8])) - { - PIXEL02_1U - PIXEL12_C - PIXEL21_C - PIXEL22_C - } - else - { - PIXEL02_2 - PIXEL12_6 - PIXEL21_1 - PIXEL22_5 - } - PIXEL00_2 - PIXEL01_1 - PIXEL10_1 - PIXEL11 - PIXEL20_1M - break; - } - case 241: - case 240: - { - if (diff(w[6], w[8])) - { - PIXEL12_C - PIXEL20_1L - PIXEL21_C - PIXEL22_C - } - else - { - PIXEL12_1 - PIXEL20_2 - PIXEL21_6 - PIXEL22_5 - } - PIXEL00_2 - PIXEL01_1 - PIXEL02_1M - PIXEL10_1 - PIXEL11 - break; - } - case 236: - case 232: - { - if (diff(w[8], w[4])) - { - PIXEL10_C - PIXEL20_C - PIXEL21_C - PIXEL22_1R - } - else - { - PIXEL10_1 - PIXEL20_5 - PIXEL21_6 - PIXEL22_2 - } - PIXEL00_1M - PIXEL01_1 - PIXEL02_2 - PIXEL11 - PIXEL12_1 - break; - } - case 109: - case 105: - { - if (diff(w[8], w[4])) - { - PIXEL00_1U - PIXEL10_C - PIXEL20_C - PIXEL21_C - } - else - { - PIXEL00_2 - PIXEL10_6 - PIXEL20_5 - PIXEL21_1 - } - PIXEL01_1 - PIXEL02_2 - PIXEL11 - PIXEL12_1 - PIXEL22_1M - break; - } - case 171: - case 43: - { - if (diff(w[4], w[2])) - { - PIXEL00_C - PIXEL01_C - PIXEL10_C - PIXEL20_1D - } - else - { - PIXEL00_5 - PIXEL01_1 - PIXEL10_6 - PIXEL20_2 - } - PIXEL02_1M - PIXEL11 - PIXEL12_1 - PIXEL21_1 - PIXEL22_2 - break; - } - case 143: - case 15: - { - if (diff(w[4], w[2])) - { - PIXEL00_C - PIXEL01_C - PIXEL02_1R - PIXEL10_C - } - else - { - PIXEL00_5 - PIXEL01_6 - PIXEL02_2 - PIXEL10_1 - } - PIXEL11 - PIXEL12_1 - PIXEL20_1M - PIXEL21_1 - PIXEL22_2 - break; - } - case 124: - { - PIXEL00_1M - PIXEL01_1 - PIXEL02_1U - PIXEL11 - PIXEL12_C - if (diff(w[8], w[4])) - { - PIXEL10_C - PIXEL20_C - PIXEL21_C - } - else - { - PIXEL10_3 - PIXEL20_4 - PIXEL21_3 - } - PIXEL22_1M - break; - } - case 203: - { - if (diff(w[4], w[2])) - { - PIXEL00_C - PIXEL01_C - PIXEL10_C - } - else - { - PIXEL00_4 - PIXEL01_3 - PIXEL10_3 - } - PIXEL02_1M - PIXEL11 - PIXEL12_1 - PIXEL20_1M - PIXEL21_C - PIXEL22_1R - break; - } - case 62: - { - PIXEL00_1M - if (diff(w[2], w[6])) - { - PIXEL01_C - PIXEL02_C - PIXEL12_C - } - else - { - PIXEL01_3 - PIXEL02_4 - PIXEL12_3 - } - PIXEL10_C - PIXEL11 - PIXEL20_1D - PIXEL21_1 - PIXEL22_1M - break; - } - case 211: - { - PIXEL00_1L - PIXEL01_C - PIXEL02_1M - PIXEL10_1 - PIXEL11 - PIXEL20_1M - if (diff(w[6], w[8])) - { - PIXEL12_C - PIXEL21_C - PIXEL22_C - } - else - { - PIXEL12_3 - PIXEL21_3 - PIXEL22_4 - } - break; - } - case 118: - { - PIXEL00_1M - if (diff(w[2], w[6])) - { - PIXEL01_C - PIXEL02_C - PIXEL12_C - } - else - { - PIXEL01_3 - PIXEL02_4 - PIXEL12_3 - } - PIXEL10_1 - PIXEL11 - PIXEL20_1L - PIXEL21_C - PIXEL22_1M - break; - } - case 217: - { - PIXEL00_1U - PIXEL01_1 - PIXEL02_1M - PIXEL10_C - PIXEL11 - PIXEL20_1M - if (diff(w[6], w[8])) - { - PIXEL12_C - PIXEL21_C - PIXEL22_C - } - else - { - PIXEL12_3 - PIXEL21_3 - PIXEL22_4 - } - break; - } - case 110: - { - PIXEL00_1M - PIXEL01_C - PIXEL02_1R - PIXEL11 - PIXEL12_1 - if (diff(w[8], w[4])) - { - PIXEL10_C - PIXEL20_C - PIXEL21_C - } - else - { - PIXEL10_3 - PIXEL20_4 - PIXEL21_3 - } - PIXEL22_1M - break; - } - case 155: - { - if (diff(w[4], w[2])) - { - PIXEL00_C - PIXEL01_C - PIXEL10_C - } - else - { - PIXEL00_4 - PIXEL01_3 - PIXEL10_3 - } - PIXEL02_1M - PIXEL11 - PIXEL12_C - PIXEL20_1M - PIXEL21_1 - PIXEL22_1D - break; - } - case 188: - { - PIXEL00_1M - PIXEL01_1 - PIXEL02_1U - PIXEL10_C - PIXEL11 - PIXEL12_C - PIXEL20_1D - PIXEL21_1 - PIXEL22_1D - break; - } - case 185: - { - PIXEL00_1U - PIXEL01_1 - PIXEL02_1M - PIXEL10_C - PIXEL11 - PIXEL12_C - PIXEL20_1D - PIXEL21_1 - PIXEL22_1D - break; - } - case 61: - { - PIXEL00_1U - PIXEL01_1 - PIXEL02_1U - PIXEL10_C - PIXEL11 - PIXEL12_C - PIXEL20_1D - PIXEL21_1 - PIXEL22_1M - break; - } - case 157: - { - PIXEL00_1U - PIXEL01_1 - PIXEL02_1U - PIXEL10_C - PIXEL11 - PIXEL12_C - PIXEL20_1M - PIXEL21_1 - PIXEL22_1D - break; - } - case 103: - { - PIXEL00_1L - PIXEL01_C - PIXEL02_1R - PIXEL10_1 - PIXEL11 - PIXEL12_1 - PIXEL20_1L - PIXEL21_C - PIXEL22_1M - break; - } - case 227: - { - PIXEL00_1L - PIXEL01_C - PIXEL02_1M - PIXEL10_1 - PIXEL11 - PIXEL12_1 - PIXEL20_1L - PIXEL21_C - PIXEL22_1R - break; - } - case 230: - { - PIXEL00_1M - PIXEL01_C - PIXEL02_1R - PIXEL10_1 - PIXEL11 - PIXEL12_1 - PIXEL20_1L - PIXEL21_C - PIXEL22_1R - break; - } - case 199: - { - PIXEL00_1L - PIXEL01_C - PIXEL02_1R - PIXEL10_1 - PIXEL11 - PIXEL12_1 - PIXEL20_1M - PIXEL21_C - PIXEL22_1R - break; - } - case 220: - { - PIXEL00_1M - PIXEL01_1 - PIXEL02_1U - PIXEL10_C - PIXEL11 - if (diff(w[8], w[4])) - { - PIXEL20_1M - } - else - { - PIXEL20_2 - } - if (diff(w[6], w[8])) - { - PIXEL12_C - PIXEL21_C - PIXEL22_C - } - else - { - PIXEL12_3 - PIXEL21_3 - PIXEL22_4 - } - break; - } - case 158: - { - if (diff(w[4], w[2])) - { - PIXEL00_1M - } - else - { - PIXEL00_2 - } - if (diff(w[2], w[6])) - { - PIXEL01_C - PIXEL02_C - PIXEL12_C - } - else - { - PIXEL01_3 - PIXEL02_4 - PIXEL12_3 - } - PIXEL10_C - PIXEL11 - PIXEL20_1M - PIXEL21_1 - PIXEL22_1D - break; - } - case 234: - { - if (diff(w[4], w[2])) - { - PIXEL00_1M - } - else - { - PIXEL00_2 - } - PIXEL01_C - PIXEL02_1M - PIXEL11 - PIXEL12_1 - if (diff(w[8], w[4])) - { - PIXEL10_C - PIXEL20_C - PIXEL21_C - } - else - { - PIXEL10_3 - PIXEL20_4 - PIXEL21_3 - } - PIXEL22_1R - break; - } - case 242: - { - PIXEL00_1M - PIXEL01_C - if (diff(w[2], w[6])) - { - PIXEL02_1M - } - else - { - PIXEL02_2 - } - PIXEL10_1 - PIXEL11 - PIXEL20_1L - if (diff(w[6], w[8])) - { - PIXEL12_C - PIXEL21_C - PIXEL22_C - } - else - { - PIXEL12_3 - PIXEL21_3 - PIXEL22_4 - } - break; - } - case 59: - { - if (diff(w[4], w[2])) - { - PIXEL00_C - PIXEL01_C - PIXEL10_C - } - else - { - PIXEL00_4 - PIXEL01_3 - PIXEL10_3 - } - if (diff(w[2], w[6])) - { - PIXEL02_1M - } - else - { - PIXEL02_2 - } - PIXEL11 - PIXEL12_C - PIXEL20_1D - PIXEL21_1 - PIXEL22_1M - break; - } - case 121: - { - PIXEL00_1U - PIXEL01_1 - PIXEL02_1M - PIXEL11 - PIXEL12_C - if (diff(w[8], w[4])) - { - PIXEL10_C - PIXEL20_C - PIXEL21_C - } - else - { - PIXEL10_3 - PIXEL20_4 - PIXEL21_3 - } - if (diff(w[6], w[8])) - { - PIXEL22_1M - } - else - { - PIXEL22_2 - } - break; - } - case 87: - { - PIXEL00_1L - if (diff(w[2], w[6])) - { - PIXEL01_C - PIXEL02_C - PIXEL12_C - } - else - { - PIXEL01_3 - PIXEL02_4 - PIXEL12_3 - } - PIXEL10_1 - PIXEL11 - PIXEL20_1M - PIXEL21_C - if (diff(w[6], w[8])) - { - PIXEL22_1M - } - else - { - PIXEL22_2 - } - break; - } - case 79: - { - if (diff(w[4], w[2])) - { - PIXEL00_C - PIXEL01_C - PIXEL10_C - } - else - { - PIXEL00_4 - PIXEL01_3 - PIXEL10_3 - } - PIXEL02_1R - PIXEL11 - PIXEL12_1 - if (diff(w[8], w[4])) - { - PIXEL20_1M - } - else - { - PIXEL20_2 - } - PIXEL21_C - PIXEL22_1M - break; - } - case 122: - { - if (diff(w[4], w[2])) - { - PIXEL00_1M - } - else - { - PIXEL00_2 - } - PIXEL01_C - if (diff(w[2], w[6])) - { - PIXEL02_1M - } - else - { - PIXEL02_2 - } - PIXEL11 - PIXEL12_C - if (diff(w[8], w[4])) - { - PIXEL10_C - PIXEL20_C - PIXEL21_C - } - else - { - PIXEL10_3 - PIXEL20_4 - PIXEL21_3 - } - if (diff(w[6], w[8])) - { - PIXEL22_1M - } - else - { - PIXEL22_2 - } - break; - } - case 94: - { - if (diff(w[4], w[2])) - { - PIXEL00_1M - } - else - { - PIXEL00_2 - } - if (diff(w[2], w[6])) - { - PIXEL01_C - PIXEL02_C - PIXEL12_C - } - else - { - PIXEL01_3 - PIXEL02_4 - PIXEL12_3 - } - PIXEL10_C - PIXEL11 - if (diff(w[8], w[4])) - { - PIXEL20_1M - } - else - { - PIXEL20_2 - } - PIXEL21_C - if (diff(w[6], w[8])) - { - PIXEL22_1M - } - else - { - PIXEL22_2 - } - break; - } - case 218: - { - if (diff(w[4], w[2])) - { - PIXEL00_1M - } - else - { - PIXEL00_2 - } - PIXEL01_C - if (diff(w[2], w[6])) - { - PIXEL02_1M - } - else - { - PIXEL02_2 - } - PIXEL10_C - PIXEL11 - if (diff(w[8], w[4])) - { - PIXEL20_1M - } - else - { - PIXEL20_2 - } - if (diff(w[6], w[8])) - { - PIXEL12_C - PIXEL21_C - PIXEL22_C - } - else - { - PIXEL12_3 - PIXEL21_3 - PIXEL22_4 - } - break; - } - case 91: - { - if (diff(w[4], w[2])) - { - PIXEL00_C - PIXEL01_C - PIXEL10_C - } - else - { - PIXEL00_4 - PIXEL01_3 - PIXEL10_3 - } - if (diff(w[2], w[6])) - { - PIXEL02_1M - } - else - { - PIXEL02_2 - } - PIXEL11 - PIXEL12_C - if (diff(w[8], w[4])) - { - PIXEL20_1M - } - else - { - PIXEL20_2 - } - PIXEL21_C - if (diff(w[6], w[8])) - { - PIXEL22_1M - } - else - { - PIXEL22_2 - } - break; - } - case 229: - { - PIXEL00_2 - PIXEL01_1 - PIXEL02_2 - PIXEL10_1 - PIXEL11 - PIXEL12_1 - PIXEL20_1L - PIXEL21_C - PIXEL22_1R - break; - } - case 167: - { - PIXEL00_1L - PIXEL01_C - PIXEL02_1R - PIXEL10_1 - PIXEL11 - PIXEL12_1 - PIXEL20_2 - PIXEL21_1 - PIXEL22_2 - break; - } - case 173: - { - PIXEL00_1U - PIXEL01_1 - PIXEL02_2 - PIXEL10_C - PIXEL11 - PIXEL12_1 - PIXEL20_1D - PIXEL21_1 - PIXEL22_2 - break; - } - case 181: - { - PIXEL00_2 - PIXEL01_1 - PIXEL02_1U - PIXEL10_1 - PIXEL11 - PIXEL12_C - PIXEL20_2 - PIXEL21_1 - PIXEL22_1D - break; - } - case 186: - { - if (diff(w[4], w[2])) - { - PIXEL00_1M - } - else - { - PIXEL00_2 - } - PIXEL01_C - if (diff(w[2], w[6])) - { - PIXEL02_1M - } - else - { - PIXEL02_2 - } - PIXEL10_C - PIXEL11 - PIXEL12_C - PIXEL20_1D - PIXEL21_1 - PIXEL22_1D - break; - } - case 115: - { - PIXEL00_1L - PIXEL01_C - if (diff(w[2], w[6])) - { - PIXEL02_1M - } - else - { - PIXEL02_2 - } - PIXEL10_1 - PIXEL11 - PIXEL12_C - PIXEL20_1L - PIXEL21_C - if (diff(w[6], w[8])) - { - PIXEL22_1M - } - else - { - PIXEL22_2 - } - break; - } - case 93: - { - PIXEL00_1U - PIXEL01_1 - PIXEL02_1U - PIXEL10_C - PIXEL11 - PIXEL12_C - if (diff(w[8], w[4])) - { - PIXEL20_1M - } - else - { - PIXEL20_2 - } - PIXEL21_C - if (diff(w[6], w[8])) - { - PIXEL22_1M - } - else - { - PIXEL22_2 - } - break; - } - case 206: - { - if (diff(w[4], w[2])) - { - PIXEL00_1M - } - else - { - PIXEL00_2 - } - PIXEL01_C - PIXEL02_1R - PIXEL10_C - PIXEL11 - PIXEL12_1 - if (diff(w[8], w[4])) - { - PIXEL20_1M - } - else - { - PIXEL20_2 - } - PIXEL21_C - PIXEL22_1R - break; - } - case 205: - case 201: - { - PIXEL00_1U - PIXEL01_1 - PIXEL02_2 - PIXEL10_C - PIXEL11 - PIXEL12_1 - if (diff(w[8], w[4])) - { - PIXEL20_1M - } - else - { - PIXEL20_2 - } - PIXEL21_C - PIXEL22_1R - break; - } - case 174: - case 46: - { - if (diff(w[4], w[2])) - { - PIXEL00_1M - } - else - { - PIXEL00_2 - } - PIXEL01_C - PIXEL02_1R - PIXEL10_C - PIXEL11 - PIXEL12_1 - PIXEL20_1D - PIXEL21_1 - PIXEL22_2 - break; - } - case 179: - case 147: - { - PIXEL00_1L - PIXEL01_C - if (diff(w[2], w[6])) - { - PIXEL02_1M - } - else - { - PIXEL02_2 - } - PIXEL10_1 - PIXEL11 - PIXEL12_C - PIXEL20_2 - PIXEL21_1 - PIXEL22_1D - break; - } - case 117: - case 116: - { - PIXEL00_2 - PIXEL01_1 - PIXEL02_1U - PIXEL10_1 - PIXEL11 - PIXEL12_C - PIXEL20_1L - PIXEL21_C - if (diff(w[6], w[8])) - { - PIXEL22_1M - } - else - { - PIXEL22_2 - } - break; - } - case 189: - { - PIXEL00_1U - PIXEL01_1 - PIXEL02_1U - PIXEL10_C - PIXEL11 - PIXEL12_C - PIXEL20_1D - PIXEL21_1 - PIXEL22_1D - break; - } - case 231: - { - PIXEL00_1L - PIXEL01_C - PIXEL02_1R - PIXEL10_1 - PIXEL11 - PIXEL12_1 - PIXEL20_1L - PIXEL21_C - PIXEL22_1R - break; - } - case 126: - { - PIXEL00_1M - if (diff(w[2], w[6])) - { - PIXEL01_C - PIXEL02_C - PIXEL12_C - } - else - { - PIXEL01_3 - PIXEL02_4 - PIXEL12_3 - } - PIXEL11 - if (diff(w[8], w[4])) - { - PIXEL10_C - PIXEL20_C - PIXEL21_C - } - else - { - PIXEL10_3 - PIXEL20_4 - PIXEL21_3 - } - PIXEL22_1M - break; - } - case 219: - { - if (diff(w[4], w[2])) - { - PIXEL00_C - PIXEL01_C - PIXEL10_C - } - else - { - PIXEL00_4 - PIXEL01_3 - PIXEL10_3 - } - PIXEL02_1M - PIXEL11 - PIXEL20_1M - if (diff(w[6], w[8])) - { - PIXEL12_C - PIXEL21_C - PIXEL22_C - } - else - { - PIXEL12_3 - PIXEL21_3 - PIXEL22_4 - } - break; - } - case 125: - { - if (diff(w[8], w[4])) - { - PIXEL00_1U - PIXEL10_C - PIXEL20_C - PIXEL21_C - } - else - { - PIXEL00_2 - PIXEL10_6 - PIXEL20_5 - PIXEL21_1 - } - PIXEL01_1 - PIXEL02_1U - PIXEL11 - PIXEL12_C - PIXEL22_1M - break; - } - case 221: - { - if (diff(w[6], w[8])) - { - PIXEL02_1U - PIXEL12_C - PIXEL21_C - PIXEL22_C - } - else - { - PIXEL02_2 - PIXEL12_6 - PIXEL21_1 - PIXEL22_5 - } - PIXEL00_1U - PIXEL01_1 - PIXEL10_C - PIXEL11 - PIXEL20_1M - break; - } - case 207: - { - if (diff(w[4], w[2])) - { - PIXEL00_C - PIXEL01_C - PIXEL02_1R - PIXEL10_C - } - else - { - PIXEL00_5 - PIXEL01_6 - PIXEL02_2 - PIXEL10_1 - } - PIXEL11 - PIXEL12_1 - PIXEL20_1M - PIXEL21_C - PIXEL22_1R - break; - } - case 238: - { - if (diff(w[8], w[4])) - { - PIXEL10_C - PIXEL20_C - PIXEL21_C - PIXEL22_1R - } - else - { - PIXEL10_1 - PIXEL20_5 - PIXEL21_6 - PIXEL22_2 - } - PIXEL00_1M - PIXEL01_C - PIXEL02_1R - PIXEL11 - PIXEL12_1 - break; - } - case 190: - { - if (diff(w[2], w[6])) - { - PIXEL01_C - PIXEL02_C - PIXEL12_C - PIXEL22_1D - } - else - { - PIXEL01_1 - PIXEL02_5 - PIXEL12_6 - PIXEL22_2 - } - PIXEL00_1M - PIXEL10_C - PIXEL11 - PIXEL20_1D - PIXEL21_1 - break; - } - case 187: - { - if (diff(w[4], w[2])) - { - PIXEL00_C - PIXEL01_C - PIXEL10_C - PIXEL20_1D - } - else - { - PIXEL00_5 - PIXEL01_1 - PIXEL10_6 - PIXEL20_2 - } - PIXEL02_1M - PIXEL11 - PIXEL12_C - PIXEL21_1 - PIXEL22_1D - break; - } - case 243: - { - if (diff(w[6], w[8])) - { - PIXEL12_C - PIXEL20_1L - PIXEL21_C - PIXEL22_C - } - else - { - PIXEL12_1 - PIXEL20_2 - PIXEL21_6 - PIXEL22_5 - } - PIXEL00_1L - PIXEL01_C - PIXEL02_1M - PIXEL10_1 - PIXEL11 - break; - } - case 119: - { - if (diff(w[2], w[6])) - { - PIXEL00_1L - PIXEL01_C - PIXEL02_C - PIXEL12_C - } - else - { - PIXEL00_2 - PIXEL01_6 - PIXEL02_5 - PIXEL12_1 - } - PIXEL10_1 - PIXEL11 - PIXEL20_1L - PIXEL21_C - PIXEL22_1M - break; - } - case 237: - case 233: - { - PIXEL00_1U - PIXEL01_1 - PIXEL02_2 - PIXEL10_C - PIXEL11 - PIXEL12_1 - if (diff(w[8], w[4])) - { - PIXEL20_C - } - else - { - PIXEL20_2 - } - PIXEL21_C - PIXEL22_1R - break; - } - case 175: - case 47: - { - if (diff(w[4], w[2])) - { - PIXEL00_C - } - else - { - PIXEL00_2 - } - PIXEL01_C - PIXEL02_1R - PIXEL10_C - PIXEL11 - PIXEL12_1 - PIXEL20_1D - PIXEL21_1 - PIXEL22_2 - break; - } - case 183: - case 151: - { - PIXEL00_1L - PIXEL01_C - if (diff(w[2], w[6])) - { - PIXEL02_C - } - else - { - PIXEL02_2 - } - PIXEL10_1 - PIXEL11 - PIXEL12_C - PIXEL20_2 - PIXEL21_1 - PIXEL22_1D - break; - } - case 245: - case 244: - { - PIXEL00_2 - PIXEL01_1 - PIXEL02_1U - PIXEL10_1 - PIXEL11 - PIXEL12_C - PIXEL20_1L - PIXEL21_C - if (diff(w[6], w[8])) - { - PIXEL22_C - } - else - { - PIXEL22_2 - } - break; - } - case 250: - { - PIXEL00_1M - PIXEL01_C - PIXEL02_1M - PIXEL11 - if (diff(w[8], w[4])) - { - PIXEL10_C - PIXEL20_C - } - else - { - PIXEL10_3 - PIXEL20_4 - } - PIXEL21_C - if (diff(w[6], w[8])) - { - PIXEL12_C - PIXEL22_C - } - else - { - PIXEL12_3 - PIXEL22_4 - } - break; - } - case 123: - { - if (diff(w[4], w[2])) - { - PIXEL00_C - PIXEL01_C - } - else - { - PIXEL00_4 - PIXEL01_3 - } - PIXEL02_1M - PIXEL10_C - PIXEL11 - PIXEL12_C - if (diff(w[8], w[4])) - { - PIXEL20_C - PIXEL21_C - } - else - { - PIXEL20_4 - PIXEL21_3 - } - PIXEL22_1M - break; - } - case 95: - { - if (diff(w[4], w[2])) - { - PIXEL00_C - PIXEL10_C - } - else - { - PIXEL00_4 - PIXEL10_3 - } - PIXEL01_C - if (diff(w[2], w[6])) - { - PIXEL02_C - PIXEL12_C - } - else - { - PIXEL02_4 - PIXEL12_3 - } - PIXEL11 - PIXEL20_1M - PIXEL21_C - PIXEL22_1M - break; - } - case 222: - { - PIXEL00_1M - if (diff(w[2], w[6])) - { - PIXEL01_C - PIXEL02_C - } - else - { - PIXEL01_3 - PIXEL02_4 - } - PIXEL10_C - PIXEL11 - PIXEL12_C - PIXEL20_1M - if (diff(w[6], w[8])) - { - PIXEL21_C - PIXEL22_C - } - else - { - PIXEL21_3 - PIXEL22_4 - } - break; - } - case 252: - { - PIXEL00_1M - PIXEL01_1 - PIXEL02_1U - PIXEL11 - PIXEL12_C - if (diff(w[8], w[4])) - { - PIXEL10_C - PIXEL20_C - } - else - { - PIXEL10_3 - PIXEL20_4 - } - PIXEL21_C - if (diff(w[6], w[8])) - { - PIXEL22_C - } - else - { - PIXEL22_2 - } - break; - } - case 249: - { - PIXEL00_1U - PIXEL01_1 - PIXEL02_1M - PIXEL10_C - PIXEL11 - if (diff(w[8], w[4])) - { - PIXEL20_C - } - else - { - PIXEL20_2 - } - PIXEL21_C - if (diff(w[6], w[8])) - { - PIXEL12_C - PIXEL22_C - } - else - { - PIXEL12_3 - PIXEL22_4 - } - break; - } - case 235: - { - if (diff(w[4], w[2])) - { - PIXEL00_C - PIXEL01_C - } - else - { - PIXEL00_4 - PIXEL01_3 - } - PIXEL02_1M - PIXEL10_C - PIXEL11 - PIXEL12_1 - if (diff(w[8], w[4])) - { - PIXEL20_C - } - else - { - PIXEL20_2 - } - PIXEL21_C - PIXEL22_1R - break; - } - case 111: - { - if (diff(w[4], w[2])) - { - PIXEL00_C - } - else - { - PIXEL00_2 - } - PIXEL01_C - PIXEL02_1R - PIXEL10_C - PIXEL11 - PIXEL12_1 - if (diff(w[8], w[4])) - { - PIXEL20_C - PIXEL21_C - } - else - { - PIXEL20_4 - PIXEL21_3 - } - PIXEL22_1M - break; - } - case 63: - { - if (diff(w[4], w[2])) - { - PIXEL00_C - } - else - { - PIXEL00_2 - } - PIXEL01_C - if (diff(w[2], w[6])) - { - PIXEL02_C - PIXEL12_C - } - else - { - PIXEL02_4 - PIXEL12_3 - } - PIXEL10_C - PIXEL11 - PIXEL20_1D - PIXEL21_1 - PIXEL22_1M - break; - } - case 159: - { - if (diff(w[4], w[2])) - { - PIXEL00_C - PIXEL10_C - } - else - { - PIXEL00_4 - PIXEL10_3 - } - PIXEL01_C - if (diff(w[2], w[6])) - { - PIXEL02_C - } - else - { - PIXEL02_2 - } - PIXEL11 - PIXEL12_C - PIXEL20_1M - PIXEL21_1 - PIXEL22_1D - break; - } - case 215: - { - PIXEL00_1L - PIXEL01_C - if (diff(w[2], w[6])) - { - PIXEL02_C - } - else - { - PIXEL02_2 - } - PIXEL10_1 - PIXEL11 - PIXEL12_C - PIXEL20_1M - if (diff(w[6], w[8])) - { - PIXEL21_C - PIXEL22_C - } - else - { - PIXEL21_3 - PIXEL22_4 - } - break; - } - case 246: - { - PIXEL00_1M - if (diff(w[2], w[6])) - { - PIXEL01_C - PIXEL02_C - } - else - { - PIXEL01_3 - PIXEL02_4 - } - PIXEL10_1 - PIXEL11 - PIXEL12_C - PIXEL20_1L - PIXEL21_C - if (diff(w[6], w[8])) - { - PIXEL22_C - } - else - { - PIXEL22_2 - } - break; - } - case 254: - { - PIXEL00_1M - if (diff(w[2], w[6])) - { - PIXEL01_C - PIXEL02_C - } - else - { - PIXEL01_3 - PIXEL02_4 - } - PIXEL11 - if (diff(w[8], w[4])) - { - PIXEL10_C - PIXEL20_C - } - else - { - PIXEL10_3 - PIXEL20_4 - } - if (diff(w[6], w[8])) - { - PIXEL12_C - PIXEL21_C - PIXEL22_C - } - else - { - PIXEL12_3 - PIXEL21_3 - PIXEL22_2 - } - break; - } - case 253: - { - PIXEL00_1U - PIXEL01_1 - PIXEL02_1U - PIXEL10_C - PIXEL11 - PIXEL12_C - if (diff(w[8], w[4])) - { - PIXEL20_C - } - else - { - PIXEL20_2 - } - PIXEL21_C - if (diff(w[6], w[8])) - { - PIXEL22_C - } - else - { - PIXEL22_2 - } - break; - } - case 251: - { - if (diff(w[4], w[2])) - { - PIXEL00_C - PIXEL01_C - } - else - { - PIXEL00_4 - PIXEL01_3 - } - PIXEL02_1M - PIXEL11 - if (diff(w[8], w[4])) - { - PIXEL10_C - PIXEL20_C - PIXEL21_C - } - else - { - PIXEL10_3 - PIXEL20_2 - PIXEL21_3 - } - if (diff(w[6], w[8])) - { - PIXEL12_C - PIXEL22_C - } - else - { - PIXEL12_3 - PIXEL22_4 - } - break; - } - case 239: - { - if (diff(w[4], w[2])) - { - PIXEL00_C - } - else - { - PIXEL00_2 - } - PIXEL01_C - PIXEL02_1R - PIXEL10_C - PIXEL11 - PIXEL12_1 - if (diff(w[8], w[4])) - { - PIXEL20_C - } - else - { - PIXEL20_2 - } - PIXEL21_C - PIXEL22_1R - break; - } - case 127: - { - if (diff(w[4], w[2])) - { - PIXEL00_C - PIXEL01_C - PIXEL10_C - } - else - { - PIXEL00_2 - PIXEL01_3 - PIXEL10_3 - } - if (diff(w[2], w[6])) - { - PIXEL02_C - PIXEL12_C - } - else - { - PIXEL02_4 - PIXEL12_3 - } - PIXEL11 - if (diff(w[8], w[4])) - { - PIXEL20_C - PIXEL21_C - } - else - { - PIXEL20_4 - PIXEL21_3 - } - PIXEL22_1M - break; - } - case 191: - { - if (diff(w[4], w[2])) - { - PIXEL00_C - } - else - { - PIXEL00_2 - } - PIXEL01_C - if (diff(w[2], w[6])) - { - PIXEL02_C - } - else - { - PIXEL02_2 - } - PIXEL10_C - PIXEL11 - PIXEL12_C - PIXEL20_1D - PIXEL21_1 - PIXEL22_1D - break; - } - case 223: - { - if (diff(w[4], w[2])) - { - PIXEL00_C - PIXEL10_C - } - else - { - PIXEL00_4 - PIXEL10_3 - } - if (diff(w[2], w[6])) - { - PIXEL01_C - PIXEL02_C - PIXEL12_C - } - else - { - PIXEL01_3 - PIXEL02_2 - PIXEL12_3 - } - PIXEL11 - PIXEL20_1M - if (diff(w[6], w[8])) - { - PIXEL21_C - PIXEL22_C - } - else - { - PIXEL21_3 - PIXEL22_4 - } - break; - } - case 247: - { - PIXEL00_1L - PIXEL01_C - if (diff(w[2], w[6])) - { - PIXEL02_C - } - else - { - PIXEL02_2 - } - PIXEL10_1 - PIXEL11 - PIXEL12_C - PIXEL20_1L - PIXEL21_C - if (diff(w[6], w[8])) - { - PIXEL22_C - } - else - { - PIXEL22_2 - } - break; - } - case 255: - { - if (diff(w[4], w[2])) - { - PIXEL00_C - } - else - { - PIXEL00_2 - } - PIXEL01_C - if (diff(w[2], w[6])) - { - PIXEL02_C - } - else - { - PIXEL02_2 - } - PIXEL10_C - PIXEL11 - PIXEL12_C - if (diff(w[8], w[4])) - { - PIXEL20_C - } - else - { - PIXEL20_2 - } - PIXEL21_C - if (diff(w[6], w[8])) - { - PIXEL22_C - } - else - { - PIXEL22_2 - } - break; - } - } - - ++in; - out += 3; - } - - out += dstPitch * 3 - std::ptrdiff_t(x_res) * 3; - } -} - -MaxStHq3x::MaxStHq3x() -: buffer_(std::size_t(VfilterInfo::in_height) * VfilterInfo::in_width) -{ -} - -void * MaxStHq3x::inBuf() const { - return buffer_; -} - -std::ptrdiff_t MaxStHq3x::inPitch() const { - return VfilterInfo::in_width; -} - -void MaxStHq3x::draw(void *dbuffer, std::ptrdiff_t dpitch) { - ::filter( - static_cast(dbuffer), dpitch, - buffer_); -} diff --git a/common/videolink/vfilters/maxsthq3x.h b/common/videolink/vfilters/maxsthq3x.h deleted file mode 100644 index e5ef8494..00000000 --- a/common/videolink/vfilters/maxsthq3x.h +++ /dev/null @@ -1,41 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef MAXSTHQ3X_H -#define MAXSTHQ3X_H - -#include "../videolink.h" -#include "../vfilterinfo.h" -#include "array.h" -#include "gbint.h" - -class MaxStHq3x : public VideoLink { -public: - enum { out_width = VfilterInfo::in_width * 3 }; - enum { out_height = VfilterInfo::in_height * 3 }; - - MaxStHq3x(); - virtual void * inBuf() const; - virtual std::ptrdiff_t inPitch() const; - virtual void draw(void *dst, std::ptrdiff_t dstpitch); - -private: - SimpleArray const buffer_; -}; - -#endif diff --git a/common/videolink/videolink.h b/common/videolink/videolink.h deleted file mode 100644 index 2b30c464..00000000 --- a/common/videolink/videolink.h +++ /dev/null @@ -1,32 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Sindre Aamås * - * sinamas@users.sourceforge.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program 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 version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef VIDEOLINK_H -#define VIDEOLINK_H - -#include - -class VideoLink { -public: - virtual ~VideoLink() {} - virtual void * inBuf() const = 0; - virtual std::ptrdiff_t inPitch() const = 0; - virtual void draw(void *dst, std::ptrdiff_t dstpitch) = 0; -}; - -#endif diff --git a/gambatte_core b/gambatte_core index 6e475f76..41625838 160000 --- a/gambatte_core +++ b/gambatte_core @@ -1 +1 @@ -Subproject commit 6e475f769d69b1b7f2ad3e5af1d48fdb46ebbbe8 +Subproject commit 41625838dfcd4904c4f143cce9b7a118b9f6edc3 diff --git a/gambatte_qt/src/gambattesource.cpp b/gambatte_qt/src/gambattesource.cpp index 6e35074a..5ffd11c2 100644 --- a/gambatte_qt/src/gambattesource.cpp +++ b/gambatte_qt/src/gambattesource.cpp @@ -32,14 +32,46 @@ struct ButtonInfo { unsigned char defaultFpp; }; -static ButtonInfo const buttonInfoGbUp = { "Up", "Game", Qt::Key_Up, 0, 0 }; -static ButtonInfo const buttonInfoGbDown = { "Down", "Game", Qt::Key_Down, 0, 0 }; -static ButtonInfo const buttonInfoGbLeft = { "Left", "Game", Qt::Key_Left, 0, 0 }; -static ButtonInfo const buttonInfoGbRight = { "Right", "Game", Qt::Key_Right, 0, 0 }; -static ButtonInfo const buttonInfoGbA = { "A", "Game", Qt::Key_D, 0, 0 }; -static ButtonInfo const buttonInfoGbB = { "B", "Game", Qt::Key_C, 0, 0 }; -static ButtonInfo const buttonInfoGbStart = { "Start", "Game", Qt::Key_Return, 0, 0 }; -static ButtonInfo const buttonInfoGbSelect = { "Select", "Game", Qt::Key_Shift, 0, 0 }; +static ButtonInfo const buttonInfoGbUp[4] = { +{ "Up", "Game", Qt::Key_Up, 0, 0 }, +{ "Up", "Player 2 (SGB)", 0, 0, 0 }, +{ "Up", "Player 3 (SGB)", 0, 0, 0 }, +{ "Up", "Player 4 (SGB)", 0, 0, 0 } }; +static ButtonInfo const buttonInfoGbDown[4] = { +{ "Down", "Game", Qt::Key_Down, 0, 0 }, +{ "Down", "Player 2 (SGB)", 0, 0, 0 }, +{ "Down", "Player 3 (SGB)", 0, 0, 0 }, +{ "Down", "Player 4 (SGB)", 0, 0, 0 } }; +static ButtonInfo const buttonInfoGbLeft[4] = { +{ "Left", "Game", Qt::Key_Left, 0, 0 }, +{ "Left", "Player 2 (SGB)", 0, 0, 0 }, +{ "Left", "Player 3 (SGB)", 0, 0, 0 }, +{ "Left", "Player 4 (SGB)", 0, 0, 0 } }; +static ButtonInfo const buttonInfoGbRight[4] = { +{ "Right", "Game", Qt::Key_Right, 0, 0 }, +{ "Right", "Player 2 (SGB)", 0, 0, 0 }, +{ "Right", "Player 3 (SGB)", 0, 0, 0 }, +{ "Right", "Player 4 (SGB)", 0, 0, 0 } }; +static ButtonInfo const buttonInfoGbA[4] = { +{ "A", "Game", Qt::Key_D, 0, 0 }, +{ "A", "Player 2 (SGB)", 0, 0, 0 }, +{ "A", "Player 3 (SGB)", 0, 0, 0 }, +{ "A", "Player 4 (SGB)", 0, 0, 0 } }; +static ButtonInfo const buttonInfoGbB[4] = { +{ "B", "Game", Qt::Key_C, 0, 0 }, +{ "B", "Player 2 (SGB)", 0, 0, 0 }, +{ "B", "Player 3 (SGB)", 0, 0, 0 }, +{ "B", "Player 4 (SGB)", 0, 0, 0 } }; +static ButtonInfo const buttonInfoGbStart[4] = { +{ "Start", "Game", Qt::Key_Return, 0, 0 }, +{ "Start", "Player 2 (SGB)", 0, 0, 0 }, +{ "Start", "Player 3 (SGB)", 0, 0, 0 }, +{ "Start", "Player 4 (SGB)", 0, 0, 0 } }; +static ButtonInfo const buttonInfoGbSelect[4] = { +{ "Select", "Game", Qt::Key_Shift, 0, 0 }, +{ "Select", "Player 2 (SGB)", 0, 0, 0 }, +{ "Select", "Player 3 (SGB)", 0, 0, 0 }, +{ "Select", "Player 4 (SGB)", 0, 0, 0 } }; static ButtonInfo const buttonInfoPause = { "Pause", "Play", Qt::Key_Pause, 0, 0 }; static ButtonInfo const buttonInfoFrameStep = { "Frame step", "Play", Qt::Key_F1, 0, 0 }; static ButtonInfo const buttonInfoDecFrameRate = { "Decrease frame rate", "Play", Qt::Key_F2, 0, 0 }; @@ -146,39 +178,54 @@ enum { a_but, b_but, select_but, start_but, right_but, left_but, up_but, down_bu GambatteSource::GambatteSource() : MediaSource(2064) +, inputGetter_(gb_) , inputDialog_(createInputDialog()) , pxformat_(PixelBuffer::RGB32) , vsrci_(0) , inputState_() -, dpadUp_(false) -, dpadDown_(false) -, dpadLeft_(false) -, dpadRight_(false) -, dpadUpLast_(false) -, dpadLeftLast_(false) , tryReset_(false) , isResetting_(false) , resetStage_(RESET_NOT) , resetCounter_(0) , resetFade_(1234567) , resetStall_(101 * (2 << 14)) +, sgbSampRm_(0) , rng_(std::random_device()()) , dist35112_(0, 35111) { + std::memset(dpadUp_, 0, sizeof dpadUp_); + std::memset(dpadDown_, 0, sizeof dpadDown_); + std::memset(dpadLeft_, 0, sizeof dpadLeft_); + std::memset(dpadRight_, 0, sizeof dpadRight_); + std::memset(dpadUpLast_, 0, sizeof dpadUpLast_); + std::memset(dpadLeftLast_, 0, sizeof dpadLeftLast_); gb_.setInputGetter((gambatte::InputGetter *)&GetInput::get, &inputGetter_); setBreakpoint(-1); } InputDialog * GambatteSource::createInputDialog() { auto_vector v; - addButton(v, &buttonInfoGbUp, GbDirAct(dpadUp_, dpadUpLast_)); - addButton(v, &buttonInfoGbDown, GbDirAct(dpadDown_, dpadUpLast_)); - addButton(v, &buttonInfoGbLeft, GbDirAct(dpadLeft_, dpadLeftLast_)); - addButton(v, &buttonInfoGbRight, GbDirAct(dpadRight_, dpadLeftLast_)); - addButton(v, &buttonInfoGbA, SetPressedAct(inputState_[a_but])); - addButton(v, &buttonInfoGbB, SetPressedAct(inputState_[b_but])); - addButton(v, &buttonInfoGbStart, SetPressedAct(inputState_[start_but])); - addButton(v, &buttonInfoGbSelect, SetPressedAct(inputState_[select_but])); +#ifdef SHOW_PLATFORM_SGB + for (unsigned i = 0; i < 4; i++) { + addButton(v, &buttonInfoGbUp[i], GbDirAct(dpadUp_[i], dpadUpLast_[i])); + addButton(v, &buttonInfoGbDown[i], GbDirAct(dpadDown_[i], dpadUpLast_[i])); + addButton(v, &buttonInfoGbLeft[i], GbDirAct(dpadLeft_[i], dpadLeftLast_[i])); + addButton(v, &buttonInfoGbRight[i], GbDirAct(dpadRight_[i], dpadLeftLast_[i])); + addButton(v, &buttonInfoGbA[i], SetPressedAct(inputState_[i][a_but])); + addButton(v, &buttonInfoGbB[i], SetPressedAct(inputState_[i][b_but])); + addButton(v, &buttonInfoGbStart[i], SetPressedAct(inputState_[i][start_but])); + addButton(v, &buttonInfoGbSelect[i], SetPressedAct(inputState_[i][select_but])); + } +#else + addButton(v, &buttonInfoGbUp[0], GbDirAct(dpadUp_[0], dpadUpLast_[0])); + addButton(v, &buttonInfoGbDown[0], GbDirAct(dpadDown_[0], dpadUpLast_[0])); + addButton(v, &buttonInfoGbLeft[0], GbDirAct(dpadLeft_[0], dpadLeftLast_[0])); + addButton(v, &buttonInfoGbRight[0], GbDirAct(dpadRight_[0], dpadLeftLast_[0])); + addButton(v, &buttonInfoGbA[0], SetPressedAct(inputState_[0][a_but])); + addButton(v, &buttonInfoGbB[0], SetPressedAct(inputState_[0][b_but])); + addButton(v, &buttonInfoGbStart[0], SetPressedAct(inputState_[0][start_but])); + addButton(v, &buttonInfoGbSelect[0], SetPressedAct(inputState_[0][select_but])); +#endif addButton(v, &buttonInfoPause, &GambatteSource::emitPause, this); addButton(v, &buttonInfoFrameStep, &GambatteSource::emitFrameStep, this); #ifdef ENABLE_TURBO_BUTTONS @@ -259,7 +306,7 @@ GambatteSource::GbVidBuf GambatteSource::setPixelBuffer( } static void setGbDir(bool &a, bool &b, - bool const aPressed, bool const bPressed, bool const preferA) { + bool const aPressed, bool const bPressed, bool const /*preferA*/) { if (aPressed & bPressed) { a = false; b = false; @@ -295,28 +342,78 @@ std::ptrdiff_t GambatteSource::update( return -1; } - setGbDir(inputState_[up_but], inputState_[down_but], - dpadUp_, dpadDown_, dpadUpLast_); - setGbDir(inputState_[left_but], inputState_[right_but], - dpadLeft_, dpadRight_, dpadLeftLast_); - inputGetter_.is = packedInputState(inputState_, sizeof inputState_ / sizeof inputState_[0]); + unsigned const players = gb_.isSgb() ? 4 : 1; + for (unsigned i = 0; i < players; i++) { + setGbDir(inputState_[i][up_but], inputState_[i][down_but], + dpadUp_[i], dpadDown_[i], dpadUpLast_[i]); + setGbDir(inputState_[i][left_but], inputState_[i][right_but], + dpadLeft_[i], dpadRight_[i], dpadLeftLast_[i]); + + inputGetter_.is[i] = packedInputState(inputState_[i], sizeof inputState_[0] / sizeof inputState_[0][0]); + } samples -= overUpdate; resetStepPre(samples); + uint_least32_t *gbPixels; + if (gb_.isSgb() && gbvidbuf.pitch == (256 + 3)) + gbPixels = &gbvidbuf.pixels[40 * (256 + 3) + 48]; + else + gbPixels = gbvidbuf.pixels; + std::ptrdiff_t const vidFrameSampleNo = - runFor(gbvidbuf.pixels, gbvidbuf.pitch, + runFor(gbPixels, gbvidbuf.pitch, ptr_cast(soundBuf), samples); + if (gb_.isSgb()) { + std::size_t sgbSamples; + qint16 sgbSoundBuf[2048 * 2]; + unsigned t = 65 - sgbSampRm_; + sgbSampRm_ = gb_.generateSgbSamples(sgbSoundBuf, sgbSamples); + if (!soundBuf || !sgbSamples) + goto end; + + short ls = sgbSoundBuf[0]; + short rs = sgbSoundBuf[1]; + for (unsigned i = 0; i < t; i++) { + int sumLs = soundBuf[i * 2] + ls; + soundBuf[(i * 2)] = std::clamp(sumLs, -0x8000, 0x7FFF); + int sumRs = soundBuf[(i * 2) + 1] + rs; + soundBuf[(i * 2) + 1] = std::clamp(sumRs, -0x8000, 0x7FFF); + } + for (unsigned i = 1; i < (sgbSamples - 1); i++, t += 65) { + ls = sgbSoundBuf[i * 2]; + rs = sgbSoundBuf[(i * 2) + 1]; + for (unsigned j = 0; j < 65; j++) { + int sumLs = soundBuf[(t + j) * 2] + ls; + soundBuf[(t + j) * 2] = std::clamp(sumLs, -0x8000, 0x7FFF); + int sumRs = soundBuf[((t + j) * 2) + 1] + rs; + soundBuf[((t + j) * 2) + 1] = std::clamp(sumRs, -0x8000, 0x7FFF); + } + } + ls = sgbSoundBuf[(sgbSamples - 1) * 2]; + rs = sgbSoundBuf[((sgbSamples - 1) * 2) + 1]; + for (unsigned i = 0; i < (samples - t); i++) { + int sumLs = soundBuf[(t + i) * 2] + ls; + soundBuf[(t + i) * 2] = std::clamp(sumLs, -0x8000, 0x7FFF); + int sumRs = soundBuf[((t + i) * 2) + 1] + rs; + soundBuf[((t + i) * 2) + 1] = std::clamp(sumRs, -0x8000, 0x7FFF); + } + } +end: + #ifdef ENABLE_INPUT_LOG - inputLog_.push(samples, inputGetter_.is); + inputLog_.push(samples, inputGetter_.is[0]); #endif resetStepPost(pb, soundBuf, samples); - if (vidFrameSampleNo >= 0) + if (vidFrameSampleNo >= 0) { inputDialog_->consumeAutoPress(); + if (gbPixels != gbvidbuf.pixels) + gb_.updateScreenBorder(gbvidbuf.pixels, gbvidbuf.pitch); + } return vidFrameSampleNo; } @@ -377,12 +474,12 @@ void GambatteSource::setVideoSource(std::size_t const videoSourceIndex) { void GambatteSource::saveState(PixelBuffer const &pb) { GbVidBuf gbvidbuf = setPixelBuffer(getpbdata(pb, vsrci_), pb.pixelFormat, pb.pitch); - gb_.saveState(gbvidbuf.pixels, gbvidbuf.pitch); + gb_.saveState((gb_.isSgb() && gbvidbuf.pitch == (256 + 3)) ? &gbvidbuf.pixels[40 * (256 + 3) + 48] : gbvidbuf.pixels, gbvidbuf.pitch); } void GambatteSource::saveState(PixelBuffer const &pb, std::string const &filepath) { GbVidBuf gbvidbuf = setPixelBuffer(getpbdata(pb, vsrci_), pb.pixelFormat, pb.pitch); - gb_.saveState(gbvidbuf.pixels, gbvidbuf.pitch, filepath); + gb_.saveState((gb_.isSgb() && gbvidbuf.pitch == (256 + 3)) ? &gbvidbuf.pixels[40 * (256 + 3) + 48] : gbvidbuf.pixels, gbvidbuf.pitch, filepath); } void GambatteSource::tryReset() { @@ -428,7 +525,8 @@ void GambatteSource::resetStepPost( } } - applyFade(pb, soundBuf, samples); + if (!gb_.isSgb()) + applyFade(pb, soundBuf, samples); } void GambatteSource::applyFade( diff --git a/gambatte_qt/src/gambattesource.h b/gambatte_qt/src/gambattesource.h index 0aa247ac..7a7b4e3d 100644 --- a/gambatte_qt/src/gambattesource.h +++ b/gambatte_qt/src/gambattesource.h @@ -149,9 +149,10 @@ public slots: struct GbVidBuf; struct GetInput { - unsigned is; - GetInput() : is(0) {} - static unsigned get(GetInput *p) { return p->is; } + unsigned is[4]; + gambatte::GB *gb_; + GetInput(gambatte::GB &gb) : gb_(&gb) { std::memset(is, 0, sizeof is); } + static unsigned get(GetInput *p) { return p->is[p->gb_->getJoypadIndex() * p->gb_->isSgb()]; } }; struct InputLog { @@ -185,10 +186,10 @@ public slots: scoped_ptr vfilter_; PixelBuffer::PixelFormat pxformat_; std::size_t vsrci_; - bool inputState_[10]; - bool dpadUp_, dpadDown_; - bool dpadLeft_, dpadRight_; - bool dpadUpLast_, dpadLeftLast_; + bool inputState_[4][10]; + bool dpadUp_[4], dpadDown_[4]; + bool dpadLeft_[4], dpadRight_[4]; + bool dpadUpLast_[4], dpadLeftLast_[4]; int breakpoint_[1]; bool tryReset_; bool isResetting_; @@ -196,6 +197,7 @@ public slots: signed resetCounter_; unsigned resetFade_; unsigned resetStall_; + unsigned sgbSampRm_; std::mt19937 rng_; std::uniform_int_distribution dist35112_; diff --git a/gambatte_qt/src/src.pro b/gambatte_qt/src/src.pro index bfdc2d0e..a8c73b4f 100644 --- a/gambatte_qt/src/src.pro +++ b/gambatte_qt/src/src.pro @@ -1,4 +1,4 @@ -COMMONPATH = ../../common +COMMONPATH = ../../gambatte_core/common include(framework/framework.pro) SOURCES += main.cpp \ @@ -12,6 +12,7 @@ SOURCES += main.cpp \ HEADERS += *.h SOURCES += $$COMMONPATH/videolink/rgb32conv.cpp \ $$COMMONPATH/videolink/vfilterinfo.cpp \ + $$COMMONPATH/videolink/vfilters/sgbborder.cpp \ $$COMMONPATH/videolink/vfilters/catrom2x.cpp \ $$COMMONPATH/videolink/vfilters/catrom3x.cpp \ $$COMMONPATH/videolink/vfilters/kreed2xsai.cpp \ @@ -23,7 +24,7 @@ TEMPLATE = app CONFIG += warn_on \ release QMAKE_CFLAGS += -fomit-frame-pointer -QMAKE_CXXFLAGS += -fomit-frame-pointer -fno-exceptions -fno-rtti +QMAKE_CXXFLAGS += -fomit-frame-pointer -fno-exceptions -fno-rtti -std=c++17 DESTDIR = ../bin INCLUDEPATH += ../../gambatte_core/libgambatte/include @@ -42,9 +43,16 @@ TARGET = "gambatte_speedrun" macx:TARGET = "Gambatte-Speedrun" VERSION_STR = interim # default to interim in case there's an issue getting revision count -exists(../../.git) { - MY_GIT_REVNO = $$system(git rev-list HEAD --count) - !isEmpty(MY_GIT_REVNO) { +exists(../../.git):exists(../../gambatte_core/.git) { + QT_GIT_REVNO = $$system(git rev-list HEAD --count) + CORE_GIT_REVNO = $$system(cd ../../gambatte_core/ && git rev-list HEAD --count) + SUBMODULE_SPLIT_REVNO = 743 + !isEmpty(QT_GIT_REVNO):!isEmpty(CORE_GIT_REVNO) { + win32 { + MY_GIT_REVNO = $$system(set /a $$QT_GIT_REVNO + $$CORE_GIT_REVNO - $$SUBMODULE_SPLIT_REVNO) + } else:unix { + MY_GIT_REVNO = $$system(echo $(($$QT_GIT_REVNO + $$CORE_GIT_REVNO - $$SUBMODULE_SPLIT_REVNO))) + } VERSION_STR = r$$MY_GIT_REVNO } }