Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem reading in P6 ppm files... Fairly Urgent  RSS feed

 
Tony Martino
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am trying to read in and process a P6 ppm file. The file looks fine in GIMP and all characters within the file (should) have values between 0 and 255. Only problem is that for some reason no matter what I do, certain characters are not being cast into that range.
I've tried to use the Character.getNumericValue() method to find out what it thinks it really is but I get a -1 returned.
The numbers that I do get upon casting it as an int are around 65500 or 8200 (roughly 2^13 & 2^16 -- something weird is going on) Using several other methods I've found online to read in and store the values has proven to yield the same problems.
I am currently reading in the values using the InputStreamReader.read(char[]) method, casting it as a byte, using the "int i = b & 0xff;" method to convert it into an unsigned byte and then storing those values. Obviously, the values I am storing are in the correct range but they are not always the correct values.
I tried to print out the values which are directly being cast out of my range and have pasted some of that output below.
If code samples and/or ppm files would help, I can attach them.
"�" => 8221
"�" => 8364
"₧" => 382
"�" => 8364
"�" => 8222
"�" => 381
"�" => 8216
"�" => 8364
"�" => 710
"�" => 8218
"�" => 381
"?" => 65533
"�" => 8225
"�" => 352
"�" => 8240
"�" => 402
"�" => 8482
-Tony Martino
 
Tony Martino
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is some more output...
the char it is... the int it thinks it is... the unsigned byte it converts to... and the char that it thought it was...?
"�" => 338 => 82 = R
"?" => 65533 => 253 = �
"?" => 65533 => 253 = �
"�" => 339 => 83 = S
"�" => 8212 => 20 = �
"�" => 8250 => 58 = :
"�" => 8249 => 57 = 9
"�" => 710 => 198 = ╞
"�" => 8482 => 198 = ╞
"�" => 8216 => 126 = ~
"�" => 8218 => 26 = →
"�" => 8249 => 26 = →

-Tony Martino
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!