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

R

RaulAbHK

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

Barry

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

mohammad.nabil.h

(e-mail address removed) ÃÑÓáÊ:
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.
 
S

SM Ryan

(e-mail address removed) 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 = CONVERT(jpegImage16);
}
A straight assignment
jpegImage8 = jpegImage16;
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.
 
B

Barry Schwarz

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
 
R

RaulAbHK

Yes you are right.
I appreciate your answer. It has been very useful.
Regards,

R.
 
R

RaulAbHK

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top