473,387 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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
6 3385

<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

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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: J. Campbell | last post by:
I have a feeling that I'm doing things all ass-backwards (again ;-), and would like some advice. What I want to do is: put some data to memory and then access that memory space as an array of...
2
by: Mitch Mooney | last post by:
Subject line says it all. For example: //base class class foo{ public: foo(); ~foo(); virtual ??? GetValue()=0; };
7
by: smith4894 | last post by:
Hello, I have a question regarding storage locations for different data types. For example, dynamically created objects (using "new") are created on the heap. local objects ( foo() {int x;} )...
4
by: troloo | last post by:
Hello, I hope you can help me :)) The story goes as follows: I have a class with different methods and member variables. I store pointers to objects of this class inside a vector. Now, I would like...
3
by: zaphod | last post by:
I want to use MS Accesss as a front end for an existing MySQL database. Since Acceess doesn't have the same data types, eg. ENUM, am I tied to the smaller subset of types supported by Access? I'm...
1
by: John Smith | last post by:
How do I use two different data types with a conditional operator ? I want to cout either a character or an integer depending on a certain condition. cout << ((IsThisTrue? char:integer) The...
2
by: Schnogge | last post by:
Hi! it is possible to generate an multiple-dimensional array with different data types? Or is it possible to combine a one-dimensional array with an other which has an other data type? How...
4
by: WuJianWei | last post by:
Is there a way(function) to distingusih between different data types? if u can, provide me with the code... thank u...
4
by: herath | last post by:
Is there a way to join 2 tables where the 2 fields on which the tables joined are of different data types(char and varchar)?I tried with CONVERT but is does not give the desired output. My...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.