-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMathExtra.cs
59 lines (54 loc) · 1.39 KB
/
MathExtra.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* Openize.HEIC
* Copyright (c) 2024-2025 Openize Pty Ltd.
*
* This file is part of Openize.HEIC.
*
* Openize.HEIC is available under Openize license, which is
* available along with Openize.HEIC sources.
*/
namespace Openize.Heic.Decoder
{
/// <summary>
/// Class used to create extended math functions.
/// </summary>
internal static class MathExtra
{
internal static int Clip3(int x, int y, int z)
{
if (z < x)
return x;
else if (z > y)
return y;
else
return z;
}
internal static uint Clip3(uint x, uint y, uint z)
{
if (z < x)
return x;
else if (z > y)
return y;
else
return z;
}
internal static int ClipBitDepth(int x, int bitDepth)
{
return Clip3(0, (1 << bitDepth) - 1, x);
}
internal static uint ClipBitDepth(uint x, int bitDepth)
{
return Clip3(0, (uint)((1 << bitDepth) - 1), x);
}
internal static int CeilDiv(int a, int b)
{
int deleted = a / b;
return deleted +
(deleted > 0 && a % b != 0 ? 1 : 0);
}
internal static uint CeilDiv(uint a, uint b)
{
return (a + b - 1) / b;
}
}
}