Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
data_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Vojtech Moravec
data_project
Commits
51c39cbe
Commit
51c39cbe
authored
6 years ago
by
Vojtěch Moravec
Browse files
Options
Downloads
Patches
Plain Diff
Memory Bit Stream.
parent
1fb8bc46
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
czi-format/czi-parser/stream/memory_bit_stream.cpp
+111
-0
111 additions, 0 deletions
czi-format/czi-parser/stream/memory_bit_stream.cpp
czi-format/czi-parser/stream/memory_bit_stream.h
+60
-0
60 additions, 0 deletions
czi-format/czi-parser/stream/memory_bit_stream.h
with
171 additions
and
0 deletions
czi-format/czi-parser/stream/memory_bit_stream.cpp
0 → 100644
+
111
−
0
View file @
51c39cbe
#include
"memory_bit_stream.h"
/******************************************************************************************************************************
* OutMemoryBitStream implementation
****************************************************************************************************************************/
OutMemoryBitStream
::
OutMemoryBitStream
()
{
bitBuffer
=
0
;
bitBufferSize
=
0
;
}
OutMemoryBitStream
::~
OutMemoryBitStream
()
{
flush_bit_buffer
();
bitBuffer
=
0
;
bitBufferSize
=
0
;
}
void
OutMemoryBitStream
::
operator
<<
(
const
bool
&
bit
)
{
write_bit
(
bit
);
}
void
OutMemoryBitStream
::
write_bit
(
const
bool
&
bit
)
{
++
bitBufferSize
;
if
(
bit
)
{
bitBuffer
|=
(
1
<<
(
8
-
bitBufferSize
));
}
if
(
bitBufferSize
==
8
)
{
flush_bit_buffer
();
}
}
void
OutMemoryBitStream
::
flush_bit_buffer
()
{
if
(
bitBufferSize
>
0
)
{
buffer
.
push_back
(
bitBuffer
);
bitBuffer
=
0
;
bitBufferSize
=
0
;
}
}
ByteArray
OutMemoryBitStream
::
get_buffer
()
const
{
return
buffer
;
}
ByteArray
OutMemoryBitStream
::
get_flushed_buffer
()
{
flush_bit_buffer
();
return
buffer
;
}
/******************************************************************************************************************************
* InMemoryBitStream implementation
****************************************************************************************************************************/
InMemoryBitStream
::
InMemoryBitStream
(
const
ByteArray
*
buffer
,
size_t
bufferPosition
)
{
memoryBuffer
=
buffer
;
memoryBufferPosition
=
bufferPosition
;
bitBufferSize
=
0
;
bitBuffer
=
0
;
}
InMemoryBitStream
::~
InMemoryBitStream
()
{
memoryBuffer
=
nullptr
;
memoryBufferPosition
=
0
;
bitBufferSize
=
0
;
bitBuffer
=
0
;
}
void
InMemoryBitStream
::
read_byte_to_bit_buffer
()
{
if
(
memoryBufferPosition
<
memoryBuffer
->
size
())
{
bitBuffer
=
(
*
memoryBuffer
)[
memoryBufferPosition
++
];
bitBufferSize
=
8
;
}
else
{
assert
(
false
&&
"Out ouf memory buffer"
);
}
}
bool
InMemoryBitStream
::
read_bit
()
{
if
(
bitBufferSize
==
0
)
{
read_byte_to_bit_buffer
();
}
--
bitBufferSize
;
bool
result
=
bitBuffer
&
(
1
<<
bitBufferSize
);
return
result
;
}
void
InMemoryBitStream
::
operator
>>
(
bool
&
bit
)
{
bit
=
read_bit
();
}
bool
InMemoryBitStream
::
can_read
()
const
{
return
((
bitBufferSize
>
0
)
||
(
memoryBufferPosition
<
memoryBuffer
->
size
()));
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
czi-format/czi-parser/stream/memory_bit_stream.h
0 → 100644
+
60
−
0
View file @
51c39cbe
#pragma once
#include
"../custom_types.h"
// Class allowing to write invidual bits to memory buffer.
class
OutMemoryBitStream
{
private:
// Memory buffer.
ByteArray
buffer
;
// Bit buffer.
byte
bitBuffer
;
// Actual size of bit buffer.
byte
bitBufferSize
=
0
;
public:
OutMemoryBitStream
();
~
OutMemoryBitStream
();
// Write bit to memory stream.
void
write_bit
(
const
bool
&
bit
);
// Write bit to memory stream.
void
operator
<<
(
const
bool
&
bit
);
// If flush buffer is not flushed, flush it to main buffer and clear it.
void
flush_bit_buffer
();
// Get buffer of written bits, which may not be flushed.
ByteArray
get_buffer
()
const
;
// Get buffer of written bits, which is flushed.
ByteArray
get_flushed_buffer
();
};
// Class alowing to read invidual bits from memory buffer.
class
InMemoryBitStream
{
private:
// Memory buffer.
const
ByteArray
*
memoryBuffer
=
nullptr
;
// Position in memory buffer.
size_t
memoryBufferPosition
=
0
;
// Bit buffer.
byte
bitBuffer
=
0
;
// Current bit buffer size.
byte
bitBufferSize
=
0
;
// Read byte into bit buffer.
void
read_byte_to_bit_buffer
();
public:
InMemoryBitStream
(
const
ByteArray
*
buffer
,
size_t
bufferPosition
=
0
);
~
InMemoryBitStream
();
// Read one bit from memory buffer.
bool
read_bit
();
// Read one bit from memory buffer.
void
operator
>>
(
bool
&
bit
);
// Check wheter atleast one bit can be read.
bool
can_read
()
const
;
};
#include
"memory_bit_stream.cpp"
\ No newline at end of file
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