By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,533 Members | 896 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,533 IT Pros & Developers. It's quick & easy.

Different data types when working with JPEG image buffers (beginner)

P: n/a
Dear all,

I guess this is a basic question with an easy answer but I am a
beginner and I would much apreciate your feedbacks.

Let's say I have a library with some functionality to perform some
image processing on jpeg images.
One of functions in the library is similar to this:

myfunction_effect (&out_instance, &mysettings, I8 *buf_in, I32
size_in_buffer, I32 *progress_status);

where I8 is char data type (1 byte), I32 is int data type (4 bytes),
buf_in is the JPEG image buffer and size_in_buffer is the size of the
JPEG buffer.

Then I want to use this function in some other source code, let's call
it mycode, but mycode uses something like this

typedef struct

{ u16 *jpegImage;

u32 jpegLength;

} MY_JPEG_STRUCT;

Where u16 is unsigned short (2 bytes) and u32 is unsigned int

The problem is that the data types for the JPEG buffer pointer are
different from myfunctions_effect() and mycode where this library will
be used. Also, I cannot change the definition for MY_JPEG_STRUCT in
mycode.

Do you have any suggestion on what is the easiest way to solve this
problem? (either at the library side (provided I have access to the
library sources) or in mycode?

I hope I have explained clearly enough.
I would really apreciate your help.
Thank you in advance.

Regards,

R.

Dec 28 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a

<Ra******@gmail.comwrote in message
news:11**********************@h40g2000cwb.googlegr oups.com...
Dear all,

I guess this is a basic question with an easy answer but I am a
beginner and I would much apreciate your feedbacks.

Let's say I have a library with some functionality to perform some
image processing on jpeg images.
One of functions in the library is similar to this:

myfunction_effect (&out_instance, &mysettings, I8 *buf_in, I32
size_in_buffer, I32 *progress_status);

where I8 is char data type (1 byte), I32 is int data type (4 bytes),
buf_in is the JPEG image buffer and size_in_buffer is the size of the
JPEG buffer.

Then I want to use this function in some other source code, let's call
it mycode, but mycode uses something like this

typedef struct

{ u16 *jpegImage;

u32 jpegLength;

} MY_JPEG_STRUCT;

Where u16 is unsigned short (2 bytes) and u32 is unsigned int

The problem is that the data types for the JPEG buffer pointer are
different from myfunctions_effect() and mycode where this library will
be used. Also, I cannot change the definition for MY_JPEG_STRUCT in
mycode.

Do you have any suggestion on what is the easiest way to solve this
problem? (either at the library side (provided I have access to the
library sources) or in mycode?

I hope I have explained clearly enough.
I would really apreciate your help.
Thank you in advance.

Regards,

R.
The c++ newsgroup is down the hall.
Dec 28 '06 #2

P: n/a

Ra******@gmail.com ΓΡΣαΚ:
Dear all,

I guess this is a basic question with an easy answer but I am a
beginner and I would much apreciate your feedbacks.

Let's say I have a library with some functionality to perform some
image processing on jpeg images.
One of functions in the library is similar to this:

myfunction_effect (&out_instance, &mysettings, I8 *buf_in, I32
size_in_buffer, I32 *progress_status);

where I8 is char data type (1 byte), I32 is int data type (4 bytes),
buf_in is the JPEG image buffer and size_in_buffer is the size of the
JPEG buffer.

Then I want to use this function in some other source code, let's call
it mycode, but mycode uses something like this

typedef struct

{ u16 *jpegImage;

u32 jpegLength;

} MY_JPEG_STRUCT;

Where u16 is unsigned short (2 bytes) and u32 is unsigned int

The problem is that the data types for the JPEG buffer pointer are
different from myfunctions_effect() and mycode where this library will
be used. Also, I cannot change the definition for MY_JPEG_STRUCT in
mycode.

Do you have any suggestion on what is the easiest way to solve this
problem? (either at the library side (provided I have access to the
library sources) or in mycode?

I hope I have explained clearly enough.
I would really apreciate your help.
Thank you in advance.

Regards,

R.
Provided th u32 array have the same raw data that an I8 array
understands, and the same endianess, then it is only a matter of a
cast. Otherwise, I think you should convert the format in another
buffer.

Dec 28 '06 #3

P: n/a
Ra******@gmail.com wrote:
# Dear all,
#
# I guess this is a basic question with an easy answer but I am a
# beginner and I would much apreciate your feedbacks.
#
# Let's say I have a library with some functionality to perform some
# image processing on jpeg images.
# One of functions in the library is similar to this:
#
# myfunction_effect (&out_instance, &mysettings, I8 *buf_in, I32
# size_in_buffer, I32 *progress_status);
#
# where I8 is char data type (1 byte), I32 is int data type (4 bytes),
# buf_in is the JPEG image buffer and size_in_buffer is the size of the
# JPEG buffer.
#
# Then I want to use this function in some other source code, let's call
# it mycode, but mycode uses something like this
#
# typedef struct
#
# { u16 *jpegImage;
#
# u32 jpegLength;
#
# } MY_JPEG_STRUCT;
#
# Where u16 is unsigned short (2 bytes) and u32 is unsigned int

If you've got different typed values, you generally have to
convert them. (You can sometimes get away with trickery, if
you know what the data sizes and/or how memory is laid out.)

If you got 16 bit value you need to pass in as 8 bit values,
you have to do something like
u16 *jpegImage16; u32 jpegLengthUnsigned;

i32 jpegLengthSigned = jpegLengthUnsigned;
u8 jpegImage8[jpegLengthSigned];
int i; for (i=0; i<jpegLengthSigned; i++) {
jpegImage8[i] = CONVERT(jpegImage16[i]);
}
A straight assignment
jpegImage8[i] = jpegImage16[i];
will transfer the low eight bits of the 16 bit value to the 8 bit value.
From what I know of image processing, it's more likely you want the
the upper eight bits, which means CONVERT(x) is x>>8. However the
actually conversuib depends on what the image data actually means,
which you have to determine from your libraries's documentation.

You can convert between u32 and i32 by straight assignment or cast.
You might want to check that the u32 value is less or equal INT_MAX
or the i32 value is nonnegative, but if the application context
guarentees that, you don't need an explicit check.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Leave it to the Catholics to destroy existence.
Dec 28 '06 #4

P: n/a
On 27 Dec 2006 20:19:29 -0800, Ra******@gmail.com wrote:
>Dear all,

I guess this is a basic question with an easy answer but I am a
beginner and I would much apreciate your feedbacks.

Let's say I have a library with some functionality to perform some
image processing on jpeg images.
One of functions in the library is similar to this:

myfunction_effect (&out_instance, &mysettings, I8 *buf_in, I32
size_in_buffer, I32 *progress_status);
This function is going to process a sequence of size_in_buffer bytes
starting at the address contained in buf_in.
>
where I8 is char data type (1 byte), I32 is int data type (4 bytes),
On my system, the Inn types are signed. Is char signed or unsigned on
yours?
>buf_in is the JPEG image buffer and size_in_buffer is the size of the
JPEG buffer.

Then I want to use this function in some other source code, let's call
it mycode, but mycode uses something like this

typedef struct

{ u16 *jpegImage;
You have a sequence of double-bytes starting at the address contained
in jpegImage. What are these double bytes (how do they relate to the
single bytes the function expects)?

Does each double-byte contain a value between CHAR_MIN and
CHAR_MAX? If so, you can build the char array containing these values
that the function expects..

Does each double-byte contain the "combined" value of two single
bytes? If so, in which order (is your system little- or big-endian)?
If the bytes are in the correct order (as defined by the function),
you can pass to the function the value in jpegImage cast to a char*).
If not, you will need to construct a char array with each pair of
bytes swapped. What will you do if the code gets moved to a different
system (think Linux on a Sun vs Linux on a PC vs Linux on an IBM
mainframe)? What if you change compilers and char changes from
unsigned to signed?

I don't know anything about jpeg but if the format is defined in terms
of single bytes, why are you building double-bytes? If the format is
defined in terms of double bytes, why are you using a function that
uses a different format definition?
>
u32 jpegLength;
Is this the length in bytes or double-bytes? It makes a difference
what you pass to the function.
>
} MY_JPEG_STRUCT;

Where u16 is unsigned short (2 bytes) and u32 is unsigned int

The problem is that the data types for the JPEG buffer pointer are
different from myfunctions_effect() and mycode where this library will
be used. Also, I cannot change the definition for MY_JPEG_STRUCT in
mycode.

Do you have any suggestion on what is the easiest way to solve this
problem? (either at the library side (provided I have access to the
library sources) or in mycode?

Remove del for email
Dec 28 '06 #5

P: n/a
Yes you are right.
I appreciate your answer. It has been very useful.
Regards,

R.
mo**************@gmail.com wrote:
Ra******@gmail.com ΓΡΣαΚ:
Dear all,

I guess this is a basic question with an easy answer but I am a
beginner and I would much apreciate your feedbacks.

Let's say I have a library with some functionality to perform some
image processing on jpeg images.
One of functions in the library is similar to this:

myfunction_effect (&out_instance, &mysettings, I8 *buf_in, I32
size_in_buffer, I32 *progress_status);

where I8 is char data type (1 byte), I32 is int data type (4 bytes),
buf_in is the JPEG image buffer and size_in_buffer is the size of the
JPEG buffer.

Then I want to use this function in some other source code, let's call
it mycode, but mycode uses something like this

typedef struct

{ u16 *jpegImage;

u32 jpegLength;

} MY_JPEG_STRUCT;

Where u16 is unsigned short (2 bytes) and u32 is unsigned int

The problem is that the data types for the JPEG buffer pointer are
different from myfunctions_effect() and mycode where this library will
be used. Also, I cannot change the definition for MY_JPEG_STRUCT in
mycode.

Do you have any suggestion on what is the easiest way to solve this
problem? (either at the library side (provided I have access to the
library sources) or in mycode?

I hope I have explained clearly enough.
I would really apreciate your help.
Thank you in advance.

Regards,

R.

Provided th u32 array have the same raw data that an I8 array
understands, and the same endianess, then it is only a matter of a
cast. Otherwise, I think you should convert the format in another
buffer.
Jan 3 '07 #6

P: n/a
Ryan,

Thank you for your answer.
It is more than what I expected and it has been really useful as well.
As it is a JPEG buffer it is only a matter of "casting" as you said.

Thank you again.

R.

SM Ryan wrote:
Ra******@gmail.com wrote:
# Dear all,
#
# I guess this is a basic question with an easy answer but I am a
# beginner and I would much apreciate your feedbacks.
#
# Let's say I have a library with some functionality to perform some
# image processing on jpeg images.
# One of functions in the library is similar to this:
#
# myfunction_effect (&out_instance, &mysettings, I8 *buf_in, I32
# size_in_buffer, I32 *progress_status);
#
# where I8 is char data type (1 byte), I32 is int data type (4 bytes),
# buf_in is the JPEG image buffer and size_in_buffer is the size of the
# JPEG buffer.
#
# Then I want to use this function in some other source code, let's call
# it mycode, but mycode uses something like this
#
# typedef struct
#
# { u16 *jpegImage;
#
# u32 jpegLength;
#
# } MY_JPEG_STRUCT;
#
# Where u16 is unsigned short (2 bytes) and u32 is unsigned int

If you've got different typed values, you generally have to
convert them. (You can sometimes get away with trickery, if
you know what the data sizes and/or how memory is laid out.)

If you got 16 bit value you need to pass in as 8 bit values,
you have to do something like
u16 *jpegImage16; u32 jpegLengthUnsigned;

i32 jpegLengthSigned = jpegLengthUnsigned;
u8 jpegImage8[jpegLengthSigned];
int i; for (i=0; i<jpegLengthSigned; i++) {
jpegImage8[i] = CONVERT(jpegImage16[i]);
}
A straight assignment
jpegImage8[i] = jpegImage16[i];
will transfer the low eight bits of the 16 bit value to the 8 bit value.
From what I know of image processing, it's more likely you want the
the upper eight bits, which means CONVERT(x) is x>>8. However the
actually conversuib depends on what the image data actually means,
which you have to determine from your libraries's documentation.

You can convert between u32 and i32 by straight assignment or cast.
You might want to check that the u32 value is less or equal INT_MAX
or the i32 value is nonnegative, but if the application context
guarentees that, you don't need an explicit check.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Leave it to the Catholics to destroy existence.
Jan 3 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.