New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding RLE-core module for JPEG encoder #2
Conversation
litejpeg/core/rle/entropycoder.py
Outdated
|
||
from litejpeg.core.common import * | ||
|
||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment should be the first thing in the file. Can you move it there?
litejpeg/core/rle/entropycoder.py
Outdated
Parameters: | ||
----------- | ||
sink : Get the input from the other modules. | ||
The input is the modulus of the input. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The input is the modulus of the input? I'm not sure what that means?
|
||
# For calculating the size. | ||
|
||
# Storing the size in the input_data. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your comments should concentrate on why you are doing something. The code explains how you are doing it.
For example, why do you want to iterate over different values from 1 to 12? Any python programmer understands that for i in range(12)
iterates over the values 0->11.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE
litejpeg/core/rle/entropycoder.py
Outdated
This module will connect the Entropycoder datapath with the input | ||
and output either from other modules or from the Test Benches. | ||
The input is been taken from the sink and source and is been transferred to | ||
the Entropycoder datapath by using read and write count. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But what does the Entropycoder actually do?
litejpeg/core/rle/entropycoder.py
Outdated
self.comb += source.data.eq(size) | ||
|
||
|
||
class Entropycoder(PipelinedActor, Module): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EntropyCoder
litejpeg/core/rle/rlecore.py
Outdated
] | ||
|
||
|
||
class Runlength(PipelinedActor, Module): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RunLength
test/common.py
Outdated
testing. | ||
""" | ||
def __init__(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do these values come from? What are they for?
Why is red_pixels_1
, self.red_pixels_1
while everything else is not assigned to self?
test/common.py
Outdated
for i in range(64): | ||
temp=self.data[i] | ||
Amplitude = temp%4096 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
amplitude
test/common.py
Outdated
for i in range(64): | ||
temp=self.data[i] | ||
Amplitude = temp%4096 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These numbers seem important. Why are you doing a %4096
and a %16
below.
test/new_rlemain_tb.py
Outdated
@@ -0,0 +1,66 @@ | |||
# This is the module for testing the RLEmain. | |||
|
|||
# !/usr/bin/env python3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# !/usr/bin/env python3
must be the first line in the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another round of comments. You are getting closer, I think we can probably get this merged today!
litejpeg/core/rle/entropycoder.py
Outdated
|
||
Parameters: | ||
----------- | ||
sink : Get the input from the other modules. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does it want the input from the other modules?
I should be able to understand what the other module this is being connected and why is that a separate module.
litejpeg/core/rle/entropycoder.py
Outdated
----------- | ||
sink : Get the input from the other modules. | ||
source : Give the output to the other modules. | ||
input_data : modulus of input of the matrix. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What matrix? I assume the matrix is coming from somewhere else?
litejpeg/core/rle/entropycoder.py
Outdated
It contains the steps for the Entropycoder to calculate the bits for the | ||
Amplitude to store. | ||
|
||
Parameters: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are actually Attributes
not Parameters
.
Parameters is pretty much a synonym for "argument". For example def foo(a, b)
has 2 parameters a
& b
.
litejpeg/core/rle/entropycoder.py
Outdated
""" | ||
EntropyDatapath : | ||
------------------ | ||
It contains the steps for the Entropycoder to calculate the bits for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Entroycoder case is wrong.
litejpeg/core/rle/entropycoder.py
Outdated
write_fsm.act("WRITE_INPUT", | ||
sink.ready.eq(1), | ||
If(sink.valid, | ||
If(write_count == 63, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If(write_count == (BLOCK_COUNT-1),
and then define BLOCK_COUNT to be 64 (and use it elsewhere).
litejpeg/core/rle/rlemain.py
Outdated
Parameters: | ||
----------- | ||
sink : 12 bits | ||
Recieves an input of 12 bits either from test bench or from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What to the 12 bits of data represent?
litejpeg/core/rle/rlemain.py
Outdated
sink : 12 bits | ||
Recieves an input of 12 bits either from test bench or from | ||
other modules. | ||
source : 21 bits |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do the 21 bits represent?
litejpeg/core/rle/rlemain.py
Outdated
datapath_latency = 3 | ||
|
||
|
||
class RLEmain(PipelinedActor, Module): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RLEmain
should be RLEMain
right?
test/common.py
Outdated
These class is been created in order to store the value or the matrix which | ||
are been used to test the RLE module. | ||
The matrix are from github repositories for the purpose of input for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which github repositories? There are plenty out there... How do I check that you haven't made a mistake in the matrixes?
test/common.py
Outdated
# number therefore in order to extracts the two we take the modulus | ||
# by 4096 to get last 12 bits and than shift and than again extracts | ||
# the next 4 representing runlength. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't explain why we want to modulus by 4096? Is this the size of the data? Is it got something to do with runlength?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there for merging this pull request!
litejpeg/core/rle/entropycoder.py
Outdated
----------- | ||
sink : Get the input from the Entrophycoder. | ||
source : Give the output to the Entrophycoder. | ||
input_data : for temporary storing the value of input, used |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
input_data / get_data / size are all not attributes. Attributes are things stored on self
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE
litejpeg/core/rle/entropycoder.py
Outdated
EntropyDatapath : | ||
------------------ | ||
It contains the steps for the EntropyCoder to calculate the bits for the | ||
Amplitude to store. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is amplitude capitalized here?
A better description would be something like Calculate the bit value for the amplitude using EntropyCoder
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE
litejpeg/core/rle/entropycoder.py
Outdated
|
||
Attributes: | ||
----------- | ||
sink : Get the input from the Entrophycoder. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two things here;
- Capitalization should always match. If the class is called
EntrophyCoder
you should always refer to it asEntrophyCoder
neverentrophyCoder
orEntrophycoder
. - "Get the input from the Entrophycoder." is not informative. It should be something like "Accepts data which is encoded in huffman entropy foo bad, such as the output from the EntrophyCoder class." -- The difference is that it tells me what the data is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE
litejpeg/core/rle/entropycoder.py
Outdated
# number of bits required to store the input_data. | ||
for i in range(12): | ||
self.sync += get_data[i].eq(input_data >> i) | ||
for i in range(12): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for i in range(11, -1, -1):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't not able to understand this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE
litejpeg/core/rle/entropycoder.py
Outdated
the amplitude. | ||
|
||
Attributes : | ||
------------ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indenting of the below things in a bit weird...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE
self.source = source = stream.Endpoint( | ||
EndpointDescription(block_layout(17))) | ||
|
||
# Adding PipelineActor to provide additional clock for the module. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need an additional clock?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE
litejpeg/core/rle/rlemain.py
Outdated
RLE core as the output will contain the amplitude in the last 12 bits along | ||
with the number of bits to store the amplitude as the next 4 bits and | ||
finally the RunLength for the next 4 bits. | ||
All these information is been synchronized once by the RLEmain and than |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"and then"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE
test/common.py
Outdated
""" | ||
These class is been created in order to store the value or the matrix which | ||
are been used to test the RLE module. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class stores the value of the matrixes used to test the RLE module.
These matrixes were taken from [`rle_test_inputs.py` in cfelton's test_jpeg code](https://github.com/cfelton/test_jpeg/blob/master/test/rle_test_inputs.py).
The matrix is an example of what the quantization module might produce.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE
self.data = data | ||
for i in range(64): | ||
temp=self.data[i] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The data we get contains amplitude and run length as a single number. In order to extract the values we use mod 4096 to get the last 12bits and then shift to extract the next 4 representing the run length.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE
test/new_rlecore_tb.py
Outdated
input to the RLE core and the output is been printed and compared | ||
with the one from the reference modules. | ||
In this way the result from the RLEcore is been verified. | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This module takes a matrix containing 64 blocks of XXXX and verifies the RLECore produces the same output as the reference data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
# To keep track over which value of the matrix is under process. | ||
write_count = Signal(6) | ||
|
||
# For tracking the data adress. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW For migen we normally wrap the code like this;
self.sync += \
If(write_clear,
write_count.eq(0)
).Elif(write_inc,
write_count.eq(write_count + 1)
)
IE
If(<condition>,
<4 spaces>statement
).Elif(<condition>,
<4 spaces>statement1,
<4 spaces>statement2,
).Else(
<4 spaces>statement1,
<4 spaces>statement2,
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE to most of the places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Merging.
This includes the addition of RLE module to the JPEG encoder with Test Bench :
RLE module :
The module takes an input_data and generate an output compressing all the zeros within two non-zero values in the form of runlength, which is used to compress the image.
RLEmain.py :
Connect the input to both the RLEcore and the Entrophycoder.
RLEcore.py :
Takes the input and calculate the runlength that is number of zeros between two non-zero values.
Entrophycoder.py :
Takes the input of the non-zero amplitude and calculate the number of bits required to store that amplitude.
Test Bench :
new_rlemain_tb.py
new_entrophycoder_tb.py
new_rlecore_tb.py
This three modules are made for the testing of the RLEmain, Entrophycoder and RLEcore respectively.
Common.py :
Added input_data for testing the RLE module and various functions such as setdata() to get the input and output in the required format.
After adding the above changes, the resultant repository contains the working model of the RLE module along with the test suite.