Skip to main content

JPEG file loading into Image object

20 replies [Last post]
Anonymous

Hi,

Recently i'd tried to load jpeg files and display it on a Canvas in
MIDP2.0 environment. With low resolution photos the code works good.
However when it comes to photo with higher resolution ( > 1.3MP) the
application will hang.

After a search on the web i found that the issue is about memory not
enough to hold the whole jpeg photo. But if i'm not able to assign the
picture to the Image object i can't perform a resize either. Currently i
could load all the bytes of the picture into a byte array though.

Wonder if anyone of you had face this problem before? Would like to know
any suggestion (other than using PNG that is :p) or advice.

Thanx
FooShyn

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff KVM-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Kim Daniel Arthur

Just cache the file into a byte array and read from it using a
bytearrayinputstream for mark to work

On 8/6/07 19:13, "Foo Shyn" wrote:

> Hi,
>
> After going through a few level of debugging, there were a few exception
> thrown along the way for the mark and reset method, as it is not
> supported on the device...
> So i think i have to use a JPEGDecoder to perform the resize, or modify
> the code to not using the stream and read from the array instead.
>
> Anyway, Thanx a lot for the help.... Still welcoming any suggestion and
> advice :)
>
> Thanx
> FooShyn
>
> Foo Shyn wrote:
>> It didn't throw any exception...juz hang there....
>>
>> The input stream is from a fileconnection input stream.....i use the
>> fileconnection to access the phone memory to grab the photo user took
>> with the phone's camera...
>>
>> Kim Daniel Arthur wrote:
>>> Does it hang or throw an excpetion? What is the source of inputstream
>>> that
>>> you are passing into the method?
>>>
>>>
>>> On 8/6/07 18:32, "Foo Shyn" wrote:
>>>
>>>
>>>> Hi,
>>>>
>>>> I'd tried the code, but it stuck at the readShort() in the
>>>> decodeJPEG.... i'm suppose to call that function to read the thumb
>>>> bytes
>>>> from the input stream into the thumb array right?
>>>>
>>>> Thanx
>>>> FooShyn
>>>>
>>>> Joe Bowbeer wrote:
>>>>
>>>>> On 6/8/07, Foo Shyn wrote:
>>>>>
>>>>>> Wow thanx man...will try it out....
>>>>>> still scratching my head over it....
>>>>>>
>>>>>> Kim Daniel Arthur wrote:
>>>>>>
>>>>>>> Most JPEGs captured with mobile cameras include a thumbnail of
>>>>>>> around
>>>>>>> 120x160 within the JPEG itself, the thumbnail format is actually
>>>>>>>
>>>>>> standard
>>>>>>
>>>>>>> JPEG so the thumbnail data can just be treated as a standalone jpeg
>>>>>>>
>>>>>> image
>>>>>>
>>>>>>> and instantiated through Image.createImage.
>>>>>>>
>>>>>>>
>>>>> Notes:
>>>>>
>>>>> If you're loading JPEGs captured by the native camera app, then
>>>>> chances are pretty good they'll contain a thumbnail. That's part of
>>>>> the DCIM (digital camera) standard. Older Nokia camera phones are an
>>>>> exception.
>>>>>
>>>>> If you're loading JPEGs captured by the MMAPI camera app, however,
>>>>> then a thumbnail is less likely.
>>>>>
>>>>> --
>>>>> Joe Bowbeer
>>>>>
>>>>>
==========================================================================>>>>>
=
>>>>>
>>>>>
>>>>> To unsubscribe, send email to listserv@java.sun.com and include in the
>>>>> body
>>>>> of the message "signoff KVM-INTEREST". For general help, send
>>>>> email to
>>>>> listserv@java.sun.com and include in the body of the message "help".
>>>>>
>>>>>
>>>>>
>>>>>
>>>> ===========================================================================
>>>>
>>>> To unsubscribe, send email to listserv@java.sun.com and include in
>>>> the body
>>>> of the message "signoff KVM-INTEREST". For general help, send email to
>>>> listserv@java.sun.com and include in the body of the message "help".
>>>>
>>>>
>>>
>>> ===========================================================================
>>>
>>> To unsubscribe, send email to listserv@java.sun.com and include in
>>> the body
>>> of the message "signoff KVM-INTEREST". For general help, send email to
>>> listserv@java.sun.com and include in the body of the message "help".
>>>
>>>
>>>
>>>
>>
>> ===========================================================================
>>
>> To unsubscribe, send email to listserv@java.sun.com and include in the
>> body
>> of the message "signoff KVM-INTEREST". For general help, send email to
>> listserv@java.sun.com and include in the body of the message "help".
>>
>>
>>
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff KVM-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff KVM-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Foo Shyn

OK my dumb mistake... forgot to add in the println in the catch block....

After adding in a printstacktrace there was an exception thrown....
EOFException

Kim Daniel Arthur wrote:
> Does it hang or throw an excpetion? What is the source of inputstream that
> you are passing into the method?
>
>
> On 8/6/07 18:32, "Foo Shyn" wrote:
>
>
>> Hi,
>>
>> I'd tried the code, but it stuck at the readShort() in the
>> decodeJPEG.... i'm suppose to call that function to read the thumb bytes
>> from the input stream into the thumb array right?
>>
>> Thanx
>> FooShyn
>>
>> Joe Bowbeer wrote:
>>
>>> On 6/8/07, Foo Shyn wrote:
>>>
>>>> Wow thanx man...will try it out....
>>>> still scratching my head over it....
>>>>
>>>> Kim Daniel Arthur wrote:
>>>>
>>>>> Most JPEGs captured with mobile cameras include a thumbnail of around
>>>>> 120x160 within the JPEG itself, the thumbnail format is actually
>>>>>
>>>> standard
>>>>
>>>>> JPEG so the thumbnail data can just be treated as a standalone jpeg
>>>>>
>>>> image
>>>>
>>>>> and instantiated through Image.createImage.
>>>>>
>>>>>
>>> Notes:
>>>
>>> If you're loading JPEGs captured by the native camera app, then
>>> chances are pretty good they'll contain a thumbnail. That's part of
>>> the DCIM (digital camera) standard. Older Nokia camera phones are an
>>> exception.
>>>
>>> If you're loading JPEGs captured by the MMAPI camera app, however,
>>> then a thumbnail is less likely.
>>>
>>> --
>>> Joe Bowbeer
>>>
>>> ===========================================================================
>>>
>>> To unsubscribe, send email to listserv@java.sun.com and include in the
>>> body
>>> of the message "signoff KVM-INTEREST". For general help, send email to
>>> listserv@java.sun.com and include in the body of the message "help".
>>>
>>>
>>>
>>>
>> ===========================================================================
>> To unsubscribe, send email to listserv@java.sun.com and include in the body
>> of the message "signoff KVM-INTEREST". For general help, send email to
>> listserv@java.sun.com and include in the body of the message "help".
>>
>>
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff KVM-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".
>
>
>
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff KVM-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

s_svane
Offline
Joined: 2007-06-14
Points: 0

Hi,
I have been following this post the past few days - hoping to get the perfect solution for loading "large" jpegs into the Image object. I thing J2ME has a serious lack in this area - which (according to several forums) are causing problems for a lot of developers. The suggested workaround in this post regarding fetching the embedded thumb from jpegs sounds like a good idear - but not sure it would work as a general solution.
Have any of you ever heard of a useable solution or workarround to this problem?

Adrian Valentin Dan

Yes unfortunately, it only works for phones that create the image, with
the thumbnail extension.
The best solution is to read the jpeg and scale it without loading in
the memory,

Here's how :

The jpeg image stores images by using 8x8 pixel image groups, which
makes scaling by powers of 2 very simple.

You just parse each group from the JPEG file, and store only the pixels
you need according to your scale ratio.

And if scaling by powers of 2 is not what you want, you can scale to the
closest power of 2 factor, and then use a normal scaling technique to
make the image your size.

Cheers.
Adrian

You can parse the whole image through an inputstream, and

meinterest@MOBILEANDEMBEDDED.ORG wrote:
> Hi,
> I have been following this post the past few days - hoping to get the perfect solution for loading "large" jpegs into the Image object. I thing J2ME has a serious lack in this area - which (according to several forums) are causing problems for a lot of developers. The suggested workaround in this post regarding fetching the embedded thumb from jpegs sounds like a good idear - but not sure it would work as a general solution.
> Have any of you ever heard of a useable solution or workarround to this problem?
> [Message sent by forum member 's_svane' (s_svane)]
>
> http://forums.java.net/jive/thread.jspa?messageID=222324
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff KVM-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".
>
>
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff KVM-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Kim Daniel Arthur

Does it hang or throw an excpetion? What is the source of inputstream that
you are passing into the method?

On 8/6/07 18:32, "Foo Shyn" wrote:

> Hi,
>
> I'd tried the code, but it stuck at the readShort() in the
> decodeJPEG.... i'm suppose to call that function to read the thumb bytes
> from the input stream into the thumb array right?
>
> Thanx
> FooShyn
>
> Joe Bowbeer wrote:
>> On 6/8/07, Foo Shyn wrote:
>>> Wow thanx man...will try it out....
>>> still scratching my head over it....
>>>
>>> Kim Daniel Arthur wrote:
>>>> Most JPEGs captured with mobile cameras include a thumbnail of around
>>>> 120x160 within the JPEG itself, the thumbnail format is actually
>>> standard
>>>> JPEG so the thumbnail data can just be treated as a standalone jpeg
>>> image
>>>> and instantiated through Image.createImage.
>>>>
>>
>> Notes:
>>
>> If you're loading JPEGs captured by the native camera app, then
>> chances are pretty good they'll contain a thumbnail. That's part of
>> the DCIM (digital camera) standard. Older Nokia camera phones are an
>> exception.
>>
>> If you're loading JPEGs captured by the MMAPI camera app, however,
>> then a thumbnail is less likely.
>>
>> --
>> Joe Bowbeer
>>
>> ===========================================================================
>>
>> To unsubscribe, send email to listserv@java.sun.com and include in the
>> body
>> of the message "signoff KVM-INTEREST". For general help, send email to
>> listserv@java.sun.com and include in the body of the message "help".
>>
>>
>>
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff KVM-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff KVM-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Foo Shyn

It didn't throw any exception...juz hang there....

The input stream is from a fileconnection input stream.....i use the
fileconnection to access the phone memory to grab the photo user took
with the phone's camera...

Kim Daniel Arthur wrote:
> Does it hang or throw an excpetion? What is the source of inputstream that
> you are passing into the method?
>
>
> On 8/6/07 18:32, "Foo Shyn" wrote:
>
>
>> Hi,
>>
>> I'd tried the code, but it stuck at the readShort() in the
>> decodeJPEG.... i'm suppose to call that function to read the thumb bytes
>> from the input stream into the thumb array right?
>>
>> Thanx
>> FooShyn
>>
>> Joe Bowbeer wrote:
>>
>>> On 6/8/07, Foo Shyn wrote:
>>>
>>>> Wow thanx man...will try it out....
>>>> still scratching my head over it....
>>>>
>>>> Kim Daniel Arthur wrote:
>>>>
>>>>> Most JPEGs captured with mobile cameras include a thumbnail of around
>>>>> 120x160 within the JPEG itself, the thumbnail format is actually
>>>>>
>>>> standard
>>>>
>>>>> JPEG so the thumbnail data can just be treated as a standalone jpeg
>>>>>
>>>> image
>>>>
>>>>> and instantiated through Image.createImage.
>>>>>
>>>>>
>>> Notes:
>>>
>>> If you're loading JPEGs captured by the native camera app, then
>>> chances are pretty good they'll contain a thumbnail. That's part of
>>> the DCIM (digital camera) standard. Older Nokia camera phones are an
>>> exception.
>>>
>>> If you're loading JPEGs captured by the MMAPI camera app, however,
>>> then a thumbnail is less likely.
>>>
>>> --
>>> Joe Bowbeer
>>>
>>> ===========================================================================
>>>
>>> To unsubscribe, send email to listserv@java.sun.com and include in the
>>> body
>>> of the message "signoff KVM-INTEREST". For general help, send email to
>>> listserv@java.sun.com and include in the body of the message "help".
>>>
>>>
>>>
>>>
>> ===========================================================================
>> To unsubscribe, send email to listserv@java.sun.com and include in the body
>> of the message "signoff KVM-INTEREST". For general help, send email to
>> listserv@java.sun.com and include in the body of the message "help".
>>
>>
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff KVM-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".
>
>
>
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff KVM-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Foo Shyn

Hi,

After going through a few level of debugging, there were a few exception
thrown along the way for the mark and reset method, as it is not
supported on the device...
So i think i have to use a JPEGDecoder to perform the resize, or modify
the code to not using the stream and read from the array instead.

Anyway, Thanx a lot for the help.... Still welcoming any suggestion and
advice :)

Thanx
FooShyn

Foo Shyn wrote:
> It didn't throw any exception...juz hang there....
>
> The input stream is from a fileconnection input stream.....i use the
> fileconnection to access the phone memory to grab the photo user took
> with the phone's camera...
>
> Kim Daniel Arthur wrote:
>> Does it hang or throw an excpetion? What is the source of inputstream
>> that
>> you are passing into the method?
>>
>>
>> On 8/6/07 18:32, "Foo Shyn" wrote:
>>
>>
>>> Hi,
>>>
>>> I'd tried the code, but it stuck at the readShort() in the
>>> decodeJPEG.... i'm suppose to call that function to read the thumb
>>> bytes
>>> from the input stream into the thumb array right?
>>>
>>> Thanx
>>> FooShyn
>>>
>>> Joe Bowbeer wrote:
>>>
>>>> On 6/8/07, Foo Shyn wrote:
>>>>
>>>>> Wow thanx man...will try it out....
>>>>> still scratching my head over it....
>>>>>
>>>>> Kim Daniel Arthur wrote:
>>>>>
>>>>>> Most JPEGs captured with mobile cameras include a thumbnail of
>>>>>> around
>>>>>> 120x160 within the JPEG itself, the thumbnail format is actually
>>>>>>
>>>>> standard
>>>>>
>>>>>> JPEG so the thumbnail data can just be treated as a standalone jpeg
>>>>>>
>>>>> image
>>>>>
>>>>>> and instantiated through Image.createImage.
>>>>>>
>>>>>>
>>>> Notes:
>>>>
>>>> If you're loading JPEGs captured by the native camera app, then
>>>> chances are pretty good they'll contain a thumbnail. That's part of
>>>> the DCIM (digital camera) standard. Older Nokia camera phones are an
>>>> exception.
>>>>
>>>> If you're loading JPEGs captured by the MMAPI camera app, however,
>>>> then a thumbnail is less likely.
>>>>
>>>> --
>>>> Joe Bowbeer
>>>>
>>>> ===========================================================================
>>>>
>>>>
>>>> To unsubscribe, send email to listserv@java.sun.com and include in the
>>>> body
>>>> of the message "signoff KVM-INTEREST". For general help, send
>>>> email to
>>>> listserv@java.sun.com and include in the body of the message "help".
>>>>
>>>>
>>>>
>>>>
>>> ===========================================================================
>>>
>>> To unsubscribe, send email to listserv@java.sun.com and include in
>>> the body
>>> of the message "signoff KVM-INTEREST". For general help, send email to
>>> listserv@java.sun.com and include in the body of the message "help".
>>>
>>>
>>
>> ===========================================================================
>>
>> To unsubscribe, send email to listserv@java.sun.com and include in
>> the body
>> of the message "signoff KVM-INTEREST". For general help, send email to
>> listserv@java.sun.com and include in the body of the message "help".
>>
>>
>>
>>
>
> ===========================================================================
>
> To unsubscribe, send email to listserv@java.sun.com and include in the
> body
> of the message "signoff KVM-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".
>
>
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff KVM-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Joe Bowbeer

On 6/8/07, Foo Shyn wrote:
>
> After going through a few level of debugging, there were a few exception
> thrown along the way for the mark and reset method, as it is not
> supported on the device...
> So i think i have to use a JPEGDecoder to perform the resize, or modify
> the code to not using the stream and read from the array instead.
>

If support for mark is all you're missing, you can wrap the
originating input stream with a buffering input stream that does
support marks. That should be easier to find or implement yourself.
If the file input stream isn't buffered, you'll want that anyway for
performance reasons alone.

--
Joe Bowbeer

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff KVM-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Kim Daniel Arthur

Most JPEGs captured with mobile cameras include a thumbnail of around
120x160 within the JPEG itself, the thumbnail format is actually standard
JPEG so the thumbnail data can just be treated as a standalone jpeg image
and instantiated through Image.createImage.

This way you don't have to do any huffman decoding or expensive stuff like
that...

Below is some really really dirty code I put together to find and extract
this JPEG thumbnail, works on images captures with most phones/digital
cameras:

public static byte[] thumbData;

public static int readIntelInt( DataInputStream dis )
throws Exception
{
int temp = dis.readInt();
return ( (temp&0xFF)<<24) | ( ((temp>>8)&0xFF)<<16)| (
((temp>>16)&0xFF)<<8)| ( ((temp>>24)&0xFF));
}

public static int readIntelShort( DataInputStream dis )
throws Exception
{
int temp = dis.readShort();
return ( ((temp)&0xFF)<<8)| ( ((temp>>8)&0xFF));
}

public static int thumbOffset;
public static int thumbSize;

public static void readIFD( DataInputStream dis )
throws Exception
{
int numDirectoryEntries = readIntelShort( dis );
for( int i = 0; i < numDirectoryEntries; i++ )
{
int entryTag = readIntelShort( dis );
int dataFormat = readIntelShort( dis );
int components = readIntelInt( dis );
int data = readIntelInt( dis );
switch( entryTag )
{
case 0x0201:
thumbOffset = data;
break;

case 0x0202:
thumbSize = data;
break;
}
}
int nextIFDOffset = readIntelInt( dis );
if( nextIFDOffset != 0 )
{
dis.reset();
dis.skip( nextIFDOffset );
readIFD( dis );
}
else
{
//this is the IFD1 block so its the thumbnail
dis.reset();
dis.skip( thumbOffset );
thumbData = new byte[ thumbSize ];
dis.readFully( thumbData );
}
}

public static void parseJPEG ( DataInputStream dis )
throws Exception
{
dis.readShort();
while (dis.read() == 0xFF)//marker start
{
int marker = dis.read();//marker type
int len = dis.readShort();//marker length
switch( marker )
{
case 0xE1://APP1 marker for EXIF format jpeg
dis.skip( 6 );//skip standard EXIF header

//TIFF HEADER
dis.mark( Integer.MAX_VALUE );//set mark here so we can skip
back to TIFF data easily later

int byteAlign = dis.readShort();//get the byte order
Inter/Motorola
dis.skip( 2 );//skip 0x2a00 which is always there

int IDF0offset = readIntelInt( dis );//position of the first
IFD, normally 8 this is relative to TIFF start
//in the Image file directory
readIFD( dis );

break;

default:
dis.skip(len - 2);//skip the rest of the chunk
break;
}
}
dis.close();
}

On 8/6/07 15:42, "Foo Shyn" wrote:

> Hi Adrin,
>
> Thanx for the info. I'm not really familiar with image processing so
> would need some extra info on the method.
> As i only have byte array, would that mean i'll need to remove some of
> the bytes in it before i use the createImage method to create the Image
> object?
>
> Thanx,
> FooShyn
>
> Adrian Valentin Dan wrote:
>> Hi Foo.
>>
>> I have faced the same problem when developing a personlized version of
>> game that allowed use of the personal gallery images (taken with the
>> phone camera) in a J2ME application.
>>
>> What i did was create a on the fly JPEG scaler, that can scale images
>> right from the byte array down to 176x208 (or other screen sizes), so
>> they can be loaded into memory.
>>
>> Cheers.
>> Adrian.
>>
>> Foo Shyn wrote:
>>> Hi,
>>>
>>> Recently i'd tried to load jpeg files and display it on a Canvas in
>>> MIDP2.0 environment. With low resolution photos the code works good.
>>> However when it comes to photo with higher resolution ( > 1.3MP) the
>>> application will hang.
>>>
>>> After a search on the web i found that the issue is about memory not
>>> enough to hold the whole jpeg photo. But if i'm not able to assign the
>>> picture to the Image object i can't perform a resize either. Currently i
>>> could load all the bytes of the picture into a byte array though.
>>>
>>> Wonder if anyone of you had face this problem before? Would like to know
>>> any suggestion (other than using PNG that is :p) or advice.
>>>
>>> Thanx
>>> FooShyn
>>>
>>> ===========================================================================
>>>
>>>
>>> To unsubscribe, send email to listserv@java.sun.com and include in the
>>> body
>>> of the message "signoff KVM-INTEREST". For general help, send email to
>>> listserv@java.sun.com and include in the body of the message "help".
>>>
>>>
>>
>> ===========================================================================
>>
>> To unsubscribe, send email to listserv@java.sun.com and include in the
>> body
>> of the message "signoff KVM-INTEREST". For general help, send email to
>> listserv@java.sun.com and include in the body of the message "help".
>>
>>
>>
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff KVM-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff KVM-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Foo Shyn

Wow thanx man...will try it out....
still scratching my head over it....

Kim Daniel Arthur wrote:
> Most JPEGs captured with mobile cameras include a thumbnail of around
> 120x160 within the JPEG itself, the thumbnail format is actually standard
> JPEG so the thumbnail data can just be treated as a standalone jpeg image
> and instantiated through Image.createImage.
>
> This way you don't have to do any huffman decoding or expensive stuff like
> that...
>
> Below is some really really dirty code I put together to find and extract
> this JPEG thumbnail, works on images captures with most phones/digital
> cameras:
>
>
> public static byte[] thumbData;
>
> public static int readIntelInt( DataInputStream dis )
> throws Exception
> {
> int temp = dis.readInt();
> return ( (temp&0xFF)<<24) | ( ((temp>>8)&0xFF)<<16)| (
> ((temp>>16)&0xFF)<<8)| ( ((temp>>24)&0xFF));
> }
>
> public static int readIntelShort( DataInputStream dis )
> throws Exception
> {
> int temp = dis.readShort();
> return ( ((temp)&0xFF)<<8)| ( ((temp>>8)&0xFF));
> }
>
> public static int thumbOffset;
> public static int thumbSize;
>
> public static void readIFD( DataInputStream dis )
> throws Exception
> {
> int numDirectoryEntries = readIntelShort( dis );
> for( int i = 0; i < numDirectoryEntries; i++ )
> {
> int entryTag = readIntelShort( dis );
> int dataFormat = readIntelShort( dis );
> int components = readIntelInt( dis );
> int data = readIntelInt( dis );
> switch( entryTag )
> {
> case 0x0201:
> thumbOffset = data;
> break;
>
> case 0x0202:
> thumbSize = data;
> break;
> }
> }
> int nextIFDOffset = readIntelInt( dis );
> if( nextIFDOffset != 0 )
> {
> dis.reset();
> dis.skip( nextIFDOffset );
> readIFD( dis );
> }
> else
> {
> //this is the IFD1 block so its the thumbnail
> dis.reset();
> dis.skip( thumbOffset );
> thumbData = new byte[ thumbSize ];
> dis.readFully( thumbData );
> }
> }
>
>
> public static void parseJPEG ( DataInputStream dis )
> throws Exception
> {
> dis.readShort();
> while (dis.read() == 0xFF)//marker start
> {
> int marker = dis.read();//marker type
> int len = dis.readShort();//marker length
> switch( marker )
> {
> case 0xE1://APP1 marker for EXIF format jpeg
> dis.skip( 6 );//skip standard EXIF header
>
> //TIFF HEADER
> dis.mark( Integer.MAX_VALUE );//set mark here so we can skip
> back to TIFF data easily later
>
> int byteAlign = dis.readShort();//get the byte order
> Inter/Motorola
> dis.skip( 2 );//skip 0x2a00 which is always there
>
> int IDF0offset = readIntelInt( dis );//position of the first
> IFD, normally 8 this is relative to TIFF start
> //in the Image file directory
> readIFD( dis );
>
> break;
>
> default:
> dis.skip(len - 2);//skip the rest of the chunk
> break;
> }
> }
> dis.close();
> }
>
>
> On 8/6/07 15:42, "Foo Shyn" wrote:
>
>
>> Hi Adrin,
>>
>> Thanx for the info. I'm not really familiar with image processing so
>> would need some extra info on the method.
>> As i only have byte array, would that mean i'll need to remove some of
>> the bytes in it before i use the createImage method to create the Image
>> object?
>>
>> Thanx,
>> FooShyn
>>
>> Adrian Valentin Dan wrote:
>>
>>> Hi Foo.
>>>
>>> I have faced the same problem when developing a personlized version of
>>> game that allowed use of the personal gallery images (taken with the
>>> phone camera) in a J2ME application.
>>>
>>> What i did was create a on the fly JPEG scaler, that can scale images
>>> right from the byte array down to 176x208 (or other screen sizes), so
>>> they can be loaded into memory.
>>>
>>> Cheers.
>>> Adrian.
>>>
>>> Foo Shyn wrote:
>>>
>>>> Hi,
>>>>
>>>> Recently i'd tried to load jpeg files and display it on a Canvas in
>>>> MIDP2.0 environment. With low resolution photos the code works good.
>>>> However when it comes to photo with higher resolution ( > 1.3MP) the
>>>> application will hang.
>>>>
>>>> After a search on the web i found that the issue is about memory not
>>>> enough to hold the whole jpeg photo. But if i'm not able to assign the
>>>> picture to the Image object i can't perform a resize either. Currently i
>>>> could load all the bytes of the picture into a byte array though.
>>>>
>>>> Wonder if anyone of you had face this problem before? Would like to know
>>>> any suggestion (other than using PNG that is :p) or advice.
>>>>
>>>> Thanx
>>>> FooShyn
>>>>
>>>> ===========================================================================
>>>>
>>>>
>>>> To unsubscribe, send email to listserv@java.sun.com and include in the
>>>> body
>>>> of the message "signoff KVM-INTEREST". For general help, send email to
>>>> listserv@java.sun.com and include in the body of the message "help".
>>>>
>>>>
>>>>
>>> ===========================================================================
>>>
>>> To unsubscribe, send email to listserv@java.sun.com and include in the
>>> body
>>> of the message "signoff KVM-INTEREST". For general help, send email to
>>> listserv@java.sun.com and include in the body of the message "help".
>>>
>>>
>>>
>>>
>> ===========================================================================
>> To unsubscribe, send email to listserv@java.sun.com and include in the body
>> of the message "signoff KVM-INTEREST". For general help, send email to
>> listserv@java.sun.com and include in the body of the message "help".
>>
>>
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff KVM-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".
>
>
>
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff KVM-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Joe Bowbeer

On 6/8/07, Foo Shyn wrote:
> Wow thanx man...will try it out....
> still scratching my head over it....
>
> Kim Daniel Arthur wrote:
> > Most JPEGs captured with mobile cameras include a thumbnail of around
> > 120x160 within the JPEG itself, the thumbnail format is actually standard
> > JPEG so the thumbnail data can just be treated as a standalone jpeg image
> > and instantiated through Image.createImage.
> >

Notes:

If you're loading JPEGs captured by the native camera app, then
chances are pretty good they'll contain a thumbnail. That's part of
the DCIM (digital camera) standard. Older Nokia camera phones are an
exception.

If you're loading JPEGs captured by the MMAPI camera app, however,
then a thumbnail is less likely.

--
Joe Bowbeer

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff KVM-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Foo Shyn

Hi,

I'd tried the code, but it stuck at the readShort() in the
decodeJPEG.... i'm suppose to call that function to read the thumb bytes
from the input stream into the thumb array right?

Thanx
FooShyn

Joe Bowbeer wrote:
> On 6/8/07, Foo Shyn wrote:
>> Wow thanx man...will try it out....
>> still scratching my head over it....
>>
>> Kim Daniel Arthur wrote:
>> > Most JPEGs captured with mobile cameras include a thumbnail of around
>> > 120x160 within the JPEG itself, the thumbnail format is actually
>> standard
>> > JPEG so the thumbnail data can just be treated as a standalone jpeg
>> image
>> > and instantiated through Image.createImage.
>> >
>
> Notes:
>
> If you're loading JPEGs captured by the native camera app, then
> chances are pretty good they'll contain a thumbnail. That's part of
> the DCIM (digital camera) standard. Older Nokia camera phones are an
> exception.
>
> If you're loading JPEGs captured by the MMAPI camera app, however,
> then a thumbnail is less likely.
>
> --
> Joe Bowbeer
>
> ===========================================================================
>
> To unsubscribe, send email to listserv@java.sun.com and include in the
> body
> of the message "signoff KVM-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".
>
>
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff KVM-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Foo Shyn

Yikes it's parseJPEG()....sorry typo

Foo Shyn wrote:
> Hi,
>
> I'd tried the code, but it stuck at the readShort() in the
> decodeJPEG.... i'm suppose to call that function to read the thumb
> bytes from the input stream into the thumb array right?
>
> Thanx
> FooShyn
>
> Joe Bowbeer wrote:
>> On 6/8/07, Foo Shyn wrote:
>>> Wow thanx man...will try it out....
>>> still scratching my head over it....
>>>
>>> Kim Daniel Arthur wrote:
>>> > Most JPEGs captured with mobile cameras include a thumbnail of around
>>> > 120x160 within the JPEG itself, the thumbnail format is actually
>>> standard
>>> > JPEG so the thumbnail data can just be treated as a standalone
>>> jpeg image
>>> > and instantiated through Image.createImage.
>>> >
>>
>> Notes:
>>
>> If you're loading JPEGs captured by the native camera app, then
>> chances are pretty good they'll contain a thumbnail. That's part of
>> the DCIM (digital camera) standard. Older Nokia camera phones are an
>> exception.
>>
>> If you're loading JPEGs captured by the MMAPI camera app, however,
>> then a thumbnail is less likely.
>>
>> --
>> Joe Bowbeer
>>
>> ===========================================================================
>>
>> To unsubscribe, send email to listserv@java.sun.com and include in
>> the body
>> of the message "signoff KVM-INTEREST". For general help, send email to
>> listserv@java.sun.com and include in the body of the message "help".
>>
>>
>>
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff KVM-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Joe Bowbeer

On 6/8/07, Foo Shyn wrote:
> Hi Adrin,
>
> Thanx for the info. I'm not really familiar with image processing so
> would need some extra info on the method.
> As i only have byte array, would that mean i'll need to remove some of
> the bytes in it before i use the createImage method to create the Image
> object?
>

All you need is a "baseline" JPEG decoder implemented in Java:-)

See:

http://answers.google.com/answers/threadview?id=28781

(don't give up before you scroll to the bottom)

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff KVM-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Foo Shyn

Hi Joe,

Thanx for the info. The source for that eclipse plugin is open to
public? We can use it?

Thanx
FooShyn

Joe Bowbeer wrote:
> On 6/8/07, Foo Shyn wrote:
>> Hi Adrin,
>>
>> Thanx for the info. I'm not really familiar with image processing so
>> would need some extra info on the method.
>> As i only have byte array, would that mean i'll need to remove some of
>> the bytes in it before i use the createImage method to create the Image
>> object?
>>
>
> All you need is a "baseline" JPEG decoder implemented in Java:-)
>
> See:
>
> http://answers.google.com/answers/threadview?id=28781
>
> (don't give up before you scroll to the bottom)
>
> ===========================================================================
>
> To unsubscribe, send email to listserv@java.sun.com and include in the
> body
> of the message "signoff KVM-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".
>
>
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff KVM-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Adrian Valentin Dan

Hi Foo.

I have faced the same problem when developing a personlized version of
game that allowed use of the personal gallery images (taken with the
phone camera) in a J2ME application.

What i did was create a on the fly JPEG scaler, that can scale images
right from the byte array down to 176x208 (or other screen sizes), so
they can be loaded into memory.

Cheers.
Adrian.

Foo Shyn wrote:
> Hi,
>
> Recently i'd tried to load jpeg files and display it on a Canvas in
> MIDP2.0 environment. With low resolution photos the code works good.
> However when it comes to photo with higher resolution ( > 1.3MP) the
> application will hang.
>
> After a search on the web i found that the issue is about memory not
> enough to hold the whole jpeg photo. But if i'm not able to assign the
> picture to the Image object i can't perform a resize either. Currently i
> could load all the bytes of the picture into a byte array though.
>
> Wonder if anyone of you had face this problem before? Would like to know
> any suggestion (other than using PNG that is :p) or advice.
>
> Thanx
> FooShyn
>
> ===========================================================================
>
> To unsubscribe, send email to listserv@java.sun.com and include in the
> body
> of the message "signoff KVM-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".
>
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff KVM-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Foo Shyn

Hi Adrin,

Thanx for the info. I'm not really familiar with image processing so
would need some extra info on the method.
As i only have byte array, would that mean i'll need to remove some of
the bytes in it before i use the createImage method to create the Image
object?

Thanx,
FooShyn

Adrian Valentin Dan wrote:
> Hi Foo.
>
> I have faced the same problem when developing a personlized version of
> game that allowed use of the personal gallery images (taken with the
> phone camera) in a J2ME application.
>
> What i did was create a on the fly JPEG scaler, that can scale images
> right from the byte array down to 176x208 (or other screen sizes), so
> they can be loaded into memory.
>
> Cheers.
> Adrian.
>
> Foo Shyn wrote:
>> Hi,
>>
>> Recently i'd tried to load jpeg files and display it on a Canvas in
>> MIDP2.0 environment. With low resolution photos the code works good.
>> However when it comes to photo with higher resolution ( > 1.3MP) the
>> application will hang.
>>
>> After a search on the web i found that the issue is about memory not
>> enough to hold the whole jpeg photo. But if i'm not able to assign the
>> picture to the Image object i can't perform a resize either. Currently i
>> could load all the bytes of the picture into a byte array though.
>>
>> Wonder if anyone of you had face this problem before? Would like to know
>> any suggestion (other than using PNG that is :p) or advice.
>>
>> Thanx
>> FooShyn
>>
>> ===========================================================================
>>
>>
>> To unsubscribe, send email to listserv@java.sun.com and include in the
>> body
>> of the message "signoff KVM-INTEREST". For general help, send email to
>> listserv@java.sun.com and include in the body of the message "help".
>>
>>
>
> ===========================================================================
>
> To unsubscribe, send email to listserv@java.sun.com and include in the
> body
> of the message "signoff KVM-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".
>
>
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff KVM-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Adrian Valentin Dan

You have to use a huffman decompressor on the stream to get the pixel
array, and then draw that onto a smaller image using a scale factor.

Here are some usefull links.

http://www.w3.org/Graphics/JPEG/jfif3.pdf

http://en.wikipedia.org/wiki/JPEG

Hope these help in writting your own image decoder.

Foo Shyn wrote:
> Hi Adrin,
>
> Thanx for the info. I'm not really familiar with image processing so
> would need some extra info on the method.
> As i only have byte array, would that mean i'll need to remove some of
> the bytes in it before i use the createImage method to create the Image
> object?
>
> Thanx,
> FooShyn
>
> Adrian Valentin Dan wrote:
>> Hi Foo.
>>
>> I have faced the same problem when developing a personlized version of
>> game that allowed use of the personal gallery images (taken with the
>> phone camera) in a J2ME application.
>>
>> What i did was create a on the fly JPEG scaler, that can scale images
>> right from the byte array down to 176x208 (or other screen sizes), so
>> they can be loaded into memory.
>>
>> Cheers.
>> Adrian.
>>
>> Foo Shyn wrote:
>>> Hi,
>>>
>>> Recently i'd tried to load jpeg files and display it on a Canvas in
>>> MIDP2.0 environment. With low resolution photos the code works good.
>>> However when it comes to photo with higher resolution ( > 1.3MP) the
>>> application will hang.
>>>
>>> After a search on the web i found that the issue is about memory not
>>> enough to hold the whole jpeg photo. But if i'm not able to assign the
>>> picture to the Image object i can't perform a resize either.
>>> Currently i
>>> could load all the bytes of the picture into a byte array though.
>>>
>>> Wonder if anyone of you had face this problem before? Would like to
>>> know
>>> any suggestion (other than using PNG that is :p) or advice.
>>>
>>> Thanx
>>> FooShyn
>>>
>>> ===========================================================================
>>>
>>>
>>>
>>> To unsubscribe, send email to listserv@java.sun.com and include in the
>>> body
>>> of the message "signoff KVM-INTEREST". For general help, send email to
>>> listserv@java.sun.com and include in the body of the message "help".
>>>
>>>
>>
>> ===========================================================================
>>
>>
>> To unsubscribe, send email to listserv@java.sun.com and include in the
>> body
>> of the message "signoff KVM-INTEREST". For general help, send email to
>> listserv@java.sun.com and include in the body of the message "help".
>>
>>
>>
>
> ===========================================================================
>
> To unsubscribe, send email to listserv@java.sun.com and include in the
> body
> of the message "signoff KVM-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".
>
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff KVM-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Foo Shyn

Hi Adrian,

Hmm ok, seems like i have no choice but to write myself a decoder.
Finally one question though, is it all JPEG photo taken by the phone
camera supported the huffman decompressor (sounds dumb but, i'm a rookie)?

Thanx,
FooShyn

Adrian Valentin Dan wrote:
> You have to use a huffman decompressor on the stream to get the pixel
> array, and then draw that onto a smaller image using a scale factor.
>
> Here are some usefull links.
>
> http://www.w3.org/Graphics/JPEG/jfif3.pdf
>
> http://en.wikipedia.org/wiki/JPEG
>
> Hope these help in writting your own image decoder.
>
> Foo Shyn wrote:
>> Hi Adrin,
>>
>> Thanx for the info. I'm not really familiar with image processing so
>> would need some extra info on the method.
>> As i only have byte array, would that mean i'll need to remove some of
>> the bytes in it before i use the createImage method to create the Image
>> object?
>>
>> Thanx,
>> FooShyn
>>
>> Adrian Valentin Dan wrote:
>>> Hi Foo.
>>>
>>> I have faced the same problem when developing a personlized version of
>>> game that allowed use of the personal gallery images (taken with the
>>> phone camera) in a J2ME application.
>>>
>>> What i did was create a on the fly JPEG scaler, that can scale images
>>> right from the byte array down to 176x208 (or other screen sizes), so
>>> they can be loaded into memory.
>>>
>>> Cheers.
>>> Adrian.
>>>
>>> Foo Shyn wrote:
>>>> Hi,
>>>>
>>>> Recently i'd tried to load jpeg files and display it on a Canvas in
>>>> MIDP2.0 environment. With low resolution photos the code works good.
>>>> However when it comes to photo with higher resolution ( > 1.3MP) the
>>>> application will hang.
>>>>
>>>> After a search on the web i found that the issue is about memory not
>>>> enough to hold the whole jpeg photo. But if i'm not able to assign the
>>>> picture to the Image object i can't perform a resize either.
>>>> Currently i
>>>> could load all the bytes of the picture into a byte array though.
>>>>
>>>> Wonder if anyone of you had face this problem before? Would like to
>>>> know
>>>> any suggestion (other than using PNG that is :p) or advice.
>>>>
>>>> Thanx
>>>> FooShyn
>>>>
>>>> ===========================================================================
>>>>
>>>>
>>>>
>>>>
>>>> To unsubscribe, send email to listserv@java.sun.com and include in the
>>>> body
>>>> of the message "signoff KVM-INTEREST". For general help, send
>>>> email to
>>>> listserv@java.sun.com and include in the body of the message "help".
>>>>
>>>>
>>>
>>> ===========================================================================
>>>
>>>
>>>
>>> To unsubscribe, send email to listserv@java.sun.com and include in the
>>> body
>>> of the message "signoff KVM-INTEREST". For general help, send email to
>>> listserv@java.sun.com and include in the body of the message "help".
>>>
>>>
>>>
>>
>> ===========================================================================
>>
>>
>> To unsubscribe, send email to listserv@java.sun.com and include in the
>> body
>> of the message "signoff KVM-INTEREST". For general help, send email to
>> listserv@java.sun.com and include in the body of the message "help".
>>
>>
>
> ===========================================================================
>
> To unsubscribe, send email to listserv@java.sun.com and include in the
> body
> of the message "signoff KVM-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".
>
>
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff KVM-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Joe Bowbeer

On 6/8/07, Foo Shyn wrote:
>
> Hmm ok, seems like i have no choice but to write myself a decoder.
> Finally one question though, is it all JPEG photo taken by the phone
> camera supported the huffman decompressor (sounds dumb but, i'm a rookie)?
>

Almost all camera phones shoot "DCIM" images, which are baseline JPEG.

Also see:

JPEG images on mobile
http://forum.java.sun.com/thread.jspa?threadID=335603&messageID=1372690

In particular:

http://webuser.fh-furtwangen.de/~dersch/

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff KVM-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".