Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Code4
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Auens
Code4
Commits
b7c77461
Commit
b7c77461
authored
3 years ago
by
Dario Wagner
Browse files
Options
Downloads
Patches
Plain Diff
Huffman ver. 1.0
parent
a5f878fd
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
greyscale.cpp
+113
-9
113 additions, 9 deletions
greyscale.cpp
greyscale.h
+2
-0
2 additions, 0 deletions
greyscale.h
with
115 additions
and
9 deletions
greyscale.cpp
+
113
−
9
View file @
b7c77461
...
...
@@ -2,9 +2,13 @@
#include
<bits/stdc++.h>
#include
"greyscale.h"
#include
"unit.h"
#include
<vector>
#include
<queue>
//BERALL SIZE T ZU INT gemacht !
//POTENTIELLER FEHLER: HHE BREITE GETAUSCHT gemacht!
using
std
::
vector
;
GreyScale
::
GreyScale
(
int
b
,
int
h
)
{
if
(
h
<
0
)
greyError
(
"Nur Vektoren mit positiver hoehe!"
);
...
...
@@ -15,8 +19,91 @@ GreyScale::GreyScale(int b,int h)
for
(
int
i
=
0
;
i
<
h
*
b
;
i
++
)
mat
[
i
]
=
1
;
}
struct
Node
{
byte_t
value
;
int
freq
;
Node
*
p0
,
*
p1
;
};
//void GreyScale::readman() const {
//
//}
//
//void GreyScale::writeman() const {
//
//}
//besser keine Funktion, sondern einfach reinschreiben
int
arr
[
256
];
for
(
int
i
=
0
;
i
<
hoehe
*
breite
;
i
++
)
{
arr
[
std
::
rint
(
mat
[
i
]
*
255
)]
+=
1
;
}
return
arr
;
bool
operator
>
(
Node
x
,
Node
y
)
{
if
(
x
.
freq
>
y
.
freq
)
return
true
;
else
if
(
x
.
freq
<
y
.
freq
)
return
false
;
else
{
if
(
x
.
value
>
y
.
value
)
return
true
;
else
return
false
;
}
}
std
::
priority_queue
<
Node
,
std
::
vector
<
Node
>
,
std
::
greater
<
Node
>>
q
//?
//
void
GreyScale
::
baummacher
(
int
arr
[]){
vector
<
Node
>
vec
;
Node
gw
;
for
(
int
i
=
0
;
i
<
256
;
i
++
)
{
if
(
arr
[
i
]
!=
0
)
//std priorityqueue (vergleichsoperator schreiben)
{
gw
.
value
=
i
;
gw
.
freq
=
arr
[
i
];
vec
.
push_back
(
gw
);
}
}
Node
k0
;
Node
k1
;
Node
papa
;
std
::
priority_queue
<
Node
,
vec
,
std
::
greater
<
Node
>>
q
;
while
(
q
.
size
()
>
1
)
{
k0
=
q
.
top
();
q
.
pop
();
//q.push(); //Frage?
k1
=
q
.
top
();
q
.
pop
();
papa
.
p0
=
k0
;
papa
.
p1
=
k1
;
q
.
push
(
papa
);
}
}
//void GreyScale::nodeschreiber(int arr[]){
// Node big;
// Node pipi[256];
// big.p0 = nodeschreiber()
//}
//for schleife die durch die gs geht,
//while schleife bis p0/p1 Nullzeiger sind (8bit durchgehen und weitermachen wo man aufgehrt hat)
//letzenode.value in gs rein
byte_t
GreyScale
::
baumleser
(
std
::
istream
&
s
,
"baum oder 1te Node"
){
if
(
p0
!=
'
leere
menge
lmao
'
)
char
a
=
s
.
get
();
if
(
a
==
1
)
baumleser
(
s
,
*
p1
);
if
(
a
==
0
)
baumleser
(
s
,
*
p0
);
return
value
;
}
GreyScale
::
GreyScale
(
const
GreyScale
&
x
){
hoehe
=
x
.
hoehe
;
...
...
@@ -34,7 +121,7 @@ float &GreyScale::operator()(int i,int j){
}
float
GreyScale
::
operator
()(
int
i
,
int
j
)
const
{
if
((
i
>
breite
+
1
)
or
(
j
>
hoehe
+
1
)
or
(
i
<
-
1
)
or
(
j
<
-
1
))
greyError
(
"lesezugriff drauen"
);
if
((
i
>
breite
)
or
(
j
>
hoehe
)
or
(
i
<
-
1
)
or
(
j
<
-
1
))
greyError
(
"lesezugriff drauen"
);
if
(
i
==
-
1
)
i
=
0
;
if
(
j
==
-
1
)
j
=
0
;
if
(
i
==
breite
)
i
=
breite
-
1
;
...
...
@@ -228,13 +315,12 @@ GreyScale GreyScale::convolve(const float mask[], int size) const
std
::
istream
&
operator
>>
(
std
::
istream
&
s
,
GreyScale
&
x
)
{
int
inpo
;
char
blar
;
std
::
string
mnr
;
float
skra
;
//std::string mull;
int
tmpbreite
=
0
;
int
tmphoehe
=
0
;
s
>>
mnr
;
if
(
mnr
!=
"P2"
)
GreyScale
::
greyError
(
"NOT PC"
);
x
.
check
(
s
);
s
>>
tmpbreite
;
x
.
check
(
s
);
...
...
@@ -242,7 +328,7 @@ std::istream &operator>>(std::istream &s, GreyScale &x) {
x
.
resize
(
tmpbreite
,
tmphoehe
);
x
.
check
(
s
);
s
>>
skra
;
if
(
mnr
==
"P2"
){
//besser vlt mit s.get und dann byte vergleichen
for
(
int
i
=
0
;
i
<
x
.
hoehe
*
x
.
breite
;
i
++
){
x
.
check
(
s
);
s
>>
inpo
;
...
...
@@ -250,7 +336,25 @@ std::istream &operator>>(std::istream &s, GreyScale &x) {
}
x
.
check
(
s
);
if
(
s
.
rdstate
()
!=
std
::
ios
::
eofbit
)
GreyScale
::
greyError
(
"nicht am ende"
);
}
else
if
(
mnr
==
"P5"
){
for
(
int
i
=
0
;
i
<
x
.
hoehe
*
x
.
breite
;
i
++
){
x
.
check
(
s
);
//maybe falsch
blar
=
s
.
get
();
inpo
=
int
(
blar
);
x
.
mat
[
i
]
=
float
(
inpo
)
/
skra
;
}
x
.
check
(
s
);
if
(
s
.
rdstate
()
!=
std
::
ios
::
eofbit
)
GreyScale
::
greyError
(
"nicht am ende"
);
}
else
if
(
mnr
==
"MHa"
){
}
else
if
(
mnr
==
"MHb"
){
}
else
return
s
;
}
...
...
This diff is collapsed.
Click to expand it.
greyscale.h
+
2
−
0
View file @
b7c77461
...
...
@@ -40,6 +40,8 @@ class GreyScale
GreyScale
convolve
(
const
float
mask
[],
int
size
=
3
)
const
;
void
check
(
std
::
istream
&
s
);
void
baummacher
(
int
arr
[]);
friend
std
::
istream
&
operator
>>
(
std
::
istream
&
,
GreyScale
&
);
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
,
const
GreyScale
&
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment