Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
F
File Recovery RecycleBin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wanglei
File Recovery RecycleBin
Commits
9d4f3cf1
Commit
9d4f3cf1
authored
Jul 30, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
4e7f8c4d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
19 deletions
+18
-19
SimilarHelper.kt
...va/com/base/filerecoveryrecyclebin/utils/SimilarHelper.kt
+18
-19
No files found.
app/src/main/java/com/base/filerecoveryrecyclebin/utils/SimilarHelper.kt
View file @
9d4f3cf1
...
...
@@ -96,38 +96,37 @@ object SimilarHelper {
// // 将相似度得分四舍五入到整数
// return similarityScore.toInt().coerceIn(0, 100)
// }
private
fun
similarPercent
(
srcFile
:
File
,
compareFile
:
File
):
Int
{
fun
similarPercent
(
srcFile
:
File
,
compareFile
:
File
):
Int
{
val
bitmap1
=
BitmapFactory
.
decodeFile
(
srcFile
.
absolutePath
)
val
bitmap2
=
BitmapFactory
.
decodeFile
(
compareFile
.
absolutePath
)
if
(
bitmap1
.
width
!=
bitmap2
.
width
||
bitmap1
.
height
!=
bitmap2
.
height
)
{
return
0
// 如果尺寸不同,则直接返回0
}
val
width
=
bitmap1
.
width
val
height
=
bitmap1
.
height
val
maxDifference
=
width
*
height
*
3
*
255
*
255
val
pixels1
=
IntArray
(
width
*
height
)
val
pixels2
=
IntArray
(
width
*
height
)
bitmap1
.
getPixels
(
pixels1
,
0
,
width
,
0
,
0
,
width
,
height
)
bitmap2
.
getPixels
(
pixels2
,
0
,
width
,
0
,
0
,
width
,
height
)
var
totalDifference
=
0L
val
pixel1
=
IntArray
(
1
)
val
pixel2
=
IntArray
(
1
)
for
(
x
in
0
until
width
)
{
for
(
y
in
0
until
height
)
{
bitmap1
.
getPixel
(
x
,
y
)
bitmap2
.
getPixel
(
x
,
y
)
val
red1
=
pixel1
[
0
]
shr
16
and
0
xff
val
green1
=
pixel1
[
0
]
shr
8
and
0
xff
val
blue1
=
pixel1
[
0
]
and
0
xff
val
red2
=
pixel2
[
0
]
shr
16
and
0
xff
val
green2
=
pixel2
[
0
]
shr
8
and
0
xff
val
blue2
=
pixel2
[
0
]
and
0
xff
val
redDiff
=
(
red1
-
red2
)
*
(
red1
-
red2
)
val
greenDiff
=
(
green1
-
green2
)
*
(
green1
-
green2
)
val
blueDiff
=
(
blue1
-
blue2
)
*
(
blue1
-
blue2
)
totalDifference
+=
(
redDiff
+
greenDiff
+
blueDiff
)
for
(
i
in
pixels1
.
indices
)
{
val
pixel1
=
pixels1
[
i
]
val
pixel2
=
pixels2
[
i
]
if
(
pixel1
!=
pixel2
)
{
val
redDifference
=
(
pixel1
shr
16
and
0
xff
)
-
(
pixel2
shr
16
and
0
xff
)
val
greenDifference
=
(
pixel1
shr
8
and
0
xff
)
-
(
pixel2
shr
8
and
0
xff
)
val
blueDifference
=
(
pixel1
and
0
xff
)
-
(
pixel2
and
0
xff
)
totalDifference
+=
(
redDifference
*
redDifference
+
greenDifference
*
greenDifference
+
blueDifference
*
blueDifference
)
}
}
val
maxDifference
=
width
*
height
*
3
*
255
*
255
val
similarityScore
=
(
1
-
totalDifference
.
toDouble
()
/
maxDifference
)
*
100
return
similarityScore
.
toInt
().
coerceIn
(
0
,
100
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment