From ab987e10f154f5536bb8fd936ae0966e909fa969 Mon Sep 17 00:00:00 2001 From: luxagraf Date: Thu, 15 Jun 2023 15:58:59 -0500 Subject: added all my scripts --- gpr/source/lib/dng_sdk/dng_rational.cpp | 150 ++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 gpr/source/lib/dng_sdk/dng_rational.cpp (limited to 'gpr/source/lib/dng_sdk/dng_rational.cpp') diff --git a/gpr/source/lib/dng_sdk/dng_rational.cpp b/gpr/source/lib/dng_sdk/dng_rational.cpp new file mode 100644 index 0000000..c366b46 --- /dev/null +++ b/gpr/source/lib/dng_sdk/dng_rational.cpp @@ -0,0 +1,150 @@ +/*****************************************************************************/ +// Copyright 2006 Adobe Systems Incorporated +// All Rights Reserved. +// +// NOTICE: Adobe permits you to use, modify, and distribute this file in +// accordance with the terms of the Adobe license agreement accompanying it. +/*****************************************************************************/ + +/* $Id: //mondo/dng_sdk_1_4/dng_sdk/source/dng_rational.cpp#1 $ */ +/* $DateTime: 2012/05/30 13:28:51 $ */ +/* $Change: 832332 $ */ +/* $Author: tknoll $ */ + +/*****************************************************************************/ + +#include "dng_rational.h" + +#include "dng_utils.h" + +/*****************************************************************************/ + +real64 dng_srational::As_real64 () const + { + + if (d) + return (real64) n / (real64) d; + + else + return 0.0; + + } + +/*****************************************************************************/ + +void dng_srational::Set_real64 (real64 x, int32 dd) + { + + if (x == 0.0) + { + + *this = dng_srational (0, 1); + + } + + if (dd == 0) + { + + real64 y = Abs_real64 (x); + + if (y >= 32768.0) + { + dd = 1; + } + + else if (y >= 1.0) + { + dd = 32768; + } + + else + { + dd = 32768 * 32768; + } + + } + + *this = dng_srational (Round_int32 (x * dd), dd); + + } + +/*****************************************************************************/ + +void dng_srational::ReduceByFactor (int32 factor) + { + + while (n % factor == 0 && + d % factor == 0 && + d >= factor) + { + n /= factor; + d /= factor; + } + + } + +/*****************************************************************************/ + +real64 dng_urational::As_real64 () const + { + + if (d) + return (real64) n / (real64) d; + + else + return 0.0; + + } + +/*****************************************************************************/ + +void dng_urational::Set_real64 (real64 x, uint32 dd) + { + + if (x <= 0.0) + { + + *this = dng_urational (0, 1); + + } + + if (dd == 0) + { + + if (x >= 32768.0) + { + dd = 1; + } + + else if (x >= 1.0) + { + dd = 32768; + } + + else + { + dd = 32768 * 32768; + } + + } + + *this = dng_urational (Round_uint32 (x * dd), dd); + + } + +/*****************************************************************************/ + +void dng_urational::ReduceByFactor (uint32 factor) + { + + while (n % factor == 0 && + d % factor == 0 && + d >= factor) + { + n /= factor; + d /= factor; + } + + } + +/*****************************************************************************/ -- cgit v1.2.3