-
Notifications
You must be signed in to change notification settings - Fork 4
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 Huffman to JPEG encoder #3
base: master
Are you sure you want to change the base?
Conversation
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.
Just some formatting and commenting fixes and we can merge this!
litejpeg/core/huffman/ac_cr_rom.py
Outdated
def ac_cr_rom(self,address1,address2,data_out_size,data_out_code): | ||
|
||
code, size = build_huffman_rom_tables( | ||
'/home/ishan/gsoc/environment/litejpeg-master/litejpeg/core/huffman/ac_cr_rom.csv') |
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.
Umm, this is a path to your computer :-P
You want to use file to find the path of this .py file. See https://docs.python.org/2/library/runpy.html and https://stackoverflow.com/questions/7116889/python-file-attribute-absolute-or-relative
Something like this should work
import os.path
HUFFMAN_DIR = os.path.dirname(__file__)
HUFFMAN_CSV = os.path.join(HUFFMAN_DIR, 'ac_cr_rom.csv')
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
@@ -0,0 +1,253 @@ | |||
0b1010,4 |
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.
It would be good if this file had some comments at the top describing what this file is used for, why it exists and what the values mean.
To read such a file, you'll need to do something like described here -> https://stackoverflow.com/questions/14158868/python-skip-comment-lines-marked-with-in-csv-dictreader or https://wuhrr.wordpress.com/2016/02/16/process-csv-with-comments/
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
@@ -0,0 +1,253 @@ | |||
0b1010,4 |
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.
Same as the other .csv 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.
Done
@@ -0,0 +1,13 @@ | |||
0b00,2 |
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.
Same as other csv 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.
Done
address = Signal(len(self.address1)+len(self.address2)) | ||
raddr = Signal(len(self.address1)+len(self.address2)) | ||
|
||
self.sync += raddr.eq(address) |
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.
self.comb += [
address.eq(Cat(self.address1,self.address2)),
rom_code_port.adr.eq(raddr),
self.data_out_code.eq(rom_code_port.dat_r),
rom_size_port.adr.eq(raddr),
self.data_out_size.eq(rom_size_port.dat_r),
]
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/huffman/huffmancore.py
Outdated
] | ||
|
||
# Handling FIFO write. | ||
self.sync += [ |
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 here is 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
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 the If
statements can you follow the style I describe here -> timvideos/getting-started#43
litejpeg/core/huffman/huffmancore.py
Outdated
|
||
|
||
class HuffmanEncoder(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.
Some extra newlines in this comment would be good.
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
These matrixes were taken from [`huffman_test_inputs.py` in cfelton's test_jpeg code] | ||
(https://github.com/cfelton/test_jpeg/blob/master/test/huff_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.
Indenting...
self.vli_test_y = [
10, 1, 2, 4, 8, 16, 32, 65,
128, 256, 1000, 1, 2, 4, 8, 16,
32, 65, 128, 256, 1000, 1, 2, 4,
8, 16, 32, 65, 128, 256, 1, 3,
3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3,
2, 2, 2, 2, 3, 3, 3, 2,
]
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
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 look to be done?
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.
@mithro, Do you want something else because I have already indented the values written in the matrix in proper order.
Kindly update if anything is missing.
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.
See my example in the first comment here -> https://github.com/timvideos/litejpeg/pull/3/files#r137180177
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 is redirecting to the same page, doesn't able to understand.
test/model/enc_frame.py
Outdated
size.append(row[1]) | ||
code = tuple(code) | ||
size = tuple(size) | ||
return code, size |
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 function seems to appear twice.
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.
@mithro , I am not able to find the function twice.
from litejpeg.core.common import * | ||
from litejpeg.core.huffman.huffmancore import HuffmanEncoder | ||
|
||
from 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.
Newline before the comment.
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
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 - just a few more style comments.
These matrixes were taken from [`huffman_test_inputs.py` in cfelton's test_jpeg code] | ||
(https://github.com/cfelton/test_jpeg/blob/master/test/huff_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.
See my example in the first comment here -> https://github.com/timvideos/litejpeg/pull/3/files#r137180177
import csv | ||
|
||
|
||
def build_huffman_rom_tables(csvfile): |
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 function is defined once here.
def build_huffman_rom_tables(csvfile):
def rle_code(block): | ||
return list(chain(*[(symbol,len(list(g))) for symbol, g in groupby(block)])) | ||
|
||
def build_huffman_rom_tables(csvfile): |
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 function is defined again here....
def build_huffman_rom_tables(csvfile):
test/new_huffman_tb.py
Outdated
from common import * | ||
|
||
""" | ||
Testbanch for the Huffman 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.
Testbanch.
Can you run spell check on all the comments? What do you use for an editor?
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 am using sublime as my text editor, working on that.
print((yield dut.data)," ",(yield dut.data_size)) | ||
yield | ||
print((yield dut.data)," ",(yield dut.data_size)) | ||
|
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 are too many newlines between stuff here.
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_huffman_tb.py
Outdated
"sys" : [main_generator(tb), | ||
tb.streamer.generator(), | ||
tb.logger.generator()] | ||
} |
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.
generators = {
"sys": [
main_generator(tb),
tb.streamer.generator(),
tb.logger.generator(),
]
}
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/huffman/huffmancore.py
Outdated
] | ||
|
||
# Handling FIFO write. | ||
self.sync += [ |
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 the If
statements can you follow the style I describe here -> timvideos/getting-started#43
|
||
] | ||
|
||
# Calculating the number of blocks to go as output. |
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 number of spaces for indenting in this file is wrong. You should always be using 4 spaces.
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
what holds this from being merged? |
This includes the addition of Huffman module to the JPEG encoder with Test Bench :
Huffman Core :
The module takes a serial input_data and generate the encoded data corresponding to the input by making the use of Huffman tables.
AC & DC ROM :
Provide the appropriate encoded values required for encoding the input data.
Table builder:
Makes the huffman tables by reading the .csv files in the directory.
Test Bench :
new_huffman_tb.py
This module is made for the testing of the Huffman Encoder.
Common.py :
Added input_data for testing the Huffman 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 Huffman module along with the test suite.