Skip to content
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

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open

Conversation

ishan98
Copy link

@ishan98 ishan98 commented Aug 31, 2017

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.

Copy link
Contributor

@mithro mithro left a 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!

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')
Copy link
Contributor

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')

Copy link
Author

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
Copy link
Contributor

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/

Copy link
Author

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
Copy link
Contributor

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.

Copy link
Author

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
Copy link
Contributor

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.

Copy link
Author

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)
Copy link
Contributor

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),
    ]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

]

# Handling FIFO write.
self.sync += [
Copy link
Contributor

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...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

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



class HuffmanEncoder(PipelinedActor, Module):
"""
Copy link
Contributor

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.

Copy link
Author

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.
"""
Copy link
Contributor

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,
    ]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

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?

Copy link
Author

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.

Copy link
Contributor

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

Copy link
Author

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.

size.append(row[1])
code = tuple(code)
size = tuple(size)
return code, size
Copy link
Contributor

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.

Copy link
Author

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 *
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newline before the comment.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

@mithro mithro left a 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.
"""
Copy link
Contributor

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):
Copy link
Contributor

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):
Copy link
Contributor

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):

from common import *

"""
Testbanch for the Huffman module.
Copy link
Contributor

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?

Copy link
Author

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))

Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"sys" : [main_generator(tb),
tb.streamer.generator(),
tb.logger.generator()]
}
Copy link
Contributor

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(),
    ]
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

]

# Handling FIFO write.
self.sync += [
Copy link
Contributor

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.
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@anuejn
Copy link

anuejn commented Feb 28, 2019

what holds this from being merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants