TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Pablo Costa
NA
7
895
Create a method to decode a RLE byte-oriented image
Aug 4 2019 6:40 PM
Hello Everyone.
I am trying to create a code to decode an PostScript RLE image and save it.
However, my output is always invalid (the raw image). I try to open it on photoshop but its always an invalid image or something like that.
I've wrote at least three versions of it, all of them with the same result. So i'm asking for any help here.
My code goes on the comments, and this is how it should be decompressed (i think my code follows what the book says).
The method i created:
public
static
List <
byte
> RLETest(
byte
[] input) {
List <
byte
> final =
new
List <
byte
> ();
for
(
int
i = 0; i < input.Length; i++) {
var lengthByte = input[i];
if
(input[i] <= 127) {
int
currLen = input[i] + 1;
for
(
int
j = 0; j < currLen; j++) {
final.Add(input[i]);
}
}
else
{
int
currLen = 257 - input[i];
for
(
int
j = 0; j < currLen; j++) {
final.Add(input[i]);
}
}
}
return
final;
}
Sample file: https://drive.google.com/open?id=1-E4flwNsY6UE2ve-Ycg6Z4cwLeoKIQRu
Width: 212
Height: 154
Channels: 1
(For opening in Photoshop)
What PostScript Red Book says about its RLE Encoding:
"The RunLengthEncode filter encodes data in a simple byte-oriented format based on run length. The compressed data format is a sequence of runs, where each run consists of a length byte followed by 1 to 128 bytes of data. If the length byte is in the range 0 to 127, the following length + 1 bytes (1 to 128 bytes) are to be copied literally upon decompression. If the length is in the range 129 to 255, the following single byte is to be replicated 257 - length times (2 to 128 times) upon decompression."
Any help is appreciated. Thanks
Reply
Answers (
0
)
Primary foreign key in model class mvc
How to make my OCR faster