Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » [SOLVED] accessing pixels in JPEG created from memory buffer
[SOLVED] accessing pixels in JPEG created from memory buffer [message #21408] Mon, 18 May 2009 23:41 Go to next message
qwerty is currently offline  qwerty
Messages: 130
Registered: May 2006
Experienced Member
posting question in different way:

how can I create JPEG image in U++ from memory buffer data(where real JPEG image data lies (String - when I '<<' to FileOut, viewer shows it right)) and how can I access pixels(RGB ideally) or whole 'uncompressed' data array, to work with it in different application, to make from that BMP-like data other object.

I can't get through it many hours.


thank you

[Updated on: Tue, 19 May 2009 14:40]

Report message to a moderator

Re: accessing pixels in JPEG created from memory buffer [message #21414 is a reply to message #21408] Tue, 19 May 2009 09:00 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello qwerty

Please correct me if I am wrong. You are asking how:

1. Create a raw jpeg image directly in memory like if you would do
String str;
str = LoadFile("bitmap.jpg");

2. Load a bitmap from a file or create it in memory and access directly the pixels

Other thing to help us would be if you could give us a basic general view of your application.

Best regards
Koldo


Best regards
Iñaki
Re: accessing pixels in JPEG created from memory buffer [message #21416 is a reply to message #21414] Tue, 19 May 2009 10:02 Go to previous messageGo to next message
qwerty is currently offline  qwerty
Messages: 130
Registered: May 2006
Experienced Member
ok,

I have extracted JPEG image from MJPEG stream, code: <a href=" http://www.ultimatepp.org/forum/index.php?t=msg&th=4396& amp; amp; amp; amp;start=0&" target="_blank"></a> .

There is JPEG_data, which contains data. When I put them to file and add '.jpeg' extension, file is accepted by picture viewer.

I written it to file just to be sure, that data has right format.

now.

I want this data, JPEG_data convert somehow to a state, where I can manipulate with them, like I am manipulating with BMP-like data. uncompress somehow.

so, for example, I want to write something similar like MyPictureFromJPEG.pixels[x][y] = ColorRED; etc.

I have no code, I have just String of data and don't know, how to decompress and work with them, like I said.
(don't want to do it with external library, when I can do it in U++, for now)

I want to convert them to OpenCV library, but this I can handle, when I will be in THAT state.

thank you and sorry for my english, I am quite tired today.

[Updated on: Tue, 19 May 2009 10:05]

Report message to a moderator

Re: accessing pixels in JPEG created from memory buffer [message #21417 is a reply to message #21414] Tue, 19 May 2009 10:25 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
Make sure you add the package plugin/jpg to your project
// Load raw image into memory
FileIn fin(IMAGE_FILE_PATH);
if (!fin.IsOpen()) 
	{ Exclamation("Unable to open file"); return; }
String raw = fin.Get((dword)fin.GetSize());

// Convert String to uncompressed Image
Image img = StreamRaster::LoadStringAny(raw);
// If you know the image format you could also use:
// Image img = JPGRaster().LoadString(raw);
if (IsNull(img)) 
	{ Exclamation("Unknown/Bad image format"); return; }

// If you need to process the image use an ImageBuffer
ImageBuffer ib(img);
RGBA *q = ~ib;
RGBA *eoi = q + ib.GetLength();
while (q < eoi) {
	// Do something to *q
	++q;
}
Re: accessing pixels in JPEG created from memory buffer [message #21419 is a reply to message #21417] Tue, 19 May 2009 10:58 Go to previous messageGo to next message
qwerty is currently offline  qwerty
Messages: 130
Registered: May 2006
Experienced Member
ou... thank you.

still can't get U++ syntax, but it teached me something more.
compiled ok, seems logical, going to implement.

have a nice life Smile
Re: accessing pixels in JPEG created from memory buffer [message #21421 is a reply to message #21419] Tue, 19 May 2009 14:00 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello qwerty

The mrjt sample is perfect.

I inclose you a little change for you to see the rows and cols handling:

// Load raw image into memory
FileIn fin(IMAGE_FILE_PATH);
if (!fin.IsOpen()) 
	{ Exclamation("Unable to open file"); return; }
String raw = fin.Get((dword)fin.GetSize());

// Convert String to uncompressed Image
Image img = StreamRaster::LoadStringAny(raw);
// If you know the image format you could also use:
// Image img = JPGRaster().LoadString(raw);
if (IsNull(img)) 
	{ Exclamation("Unknown/Bad image format"); return; }

// If you need to modify the image use an ImageBuffer
ImageBuffer ib(img);
for (int row = 0; row < ib.GetHeight(); ++row) {
	RGBA *rowData = ib[row];
	for(int col = 0; col < ib.GetWidth(); col++) {
		rowData[col].red   = 255-rowData[col].red; // Inverting the colors
		rowData[col].green = 255-rowData[col].green;
		rowData[col].blue  = 255-rowData[col].blue;
	}
}
img = ib;


Here we are inverting the colors so for example red are converted to 255-red as the maximum value of a color is 255.

Best regards
Koldo


Best regards
Iñaki
accessing pixels in JPEG created from memory buffer [message #21422 is a reply to message #21421] Tue, 19 May 2009 14:40 Go to previous messageGo to next message
qwerty is currently offline  qwerty
Messages: 130
Registered: May 2006
Experienced Member
ohhhh yesss...

I am very thank you to both of you, because everything works perfeclty. what more, OpenCV likes native U++ format of low level data.

very thank you

mrjt shows me converting connections
koldo shows me, how to manipulate with individual elements

great, I am going to do some coffe and continue... :>


have a nice life moments...

[Updated on: Tue, 19 May 2009 14:44]

Report message to a moderator

Re: accessing pixels in JPEG created from memory buffer [message #21423 is a reply to message #21417] Tue, 19 May 2009 16:13 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
mrjt wrote on Tue, 19 May 2009 04:25

Make sure you add the package plugin/jpg to your project
[code]// Load raw image into memory
FileIn fin(IMAGE_FILE_PATH);
if (!fin.IsOpen())
{ Exclamation("Unable to open file"); return; }
String raw = fin.Get((dword)fin.GetSize());

// Convert String to uncompressed Image
Image img = StreamRaster::LoadStringAny(raw);
// If you know the image format you could also use:
// Image img = JPGRaster().LoadString(raw);



Or just:

Image img = StreamRaster::LoadFileAny(IMAGE_FILE_PATH);

Mirek
Re: accessing pixels in JPEG created from memory buffer [message #21426 is a reply to message #21423] Tue, 19 May 2009 18:33 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
luzr wrote on Tue, 19 May 2009 15:13

mrjt wrote on Tue, 19 May 2009 04:25

Make sure you add the package plugin/jpg to your project
[code]// Load raw image into memory
FileIn fin(IMAGE_FILE_PATH);
if (!fin.IsOpen())
{ Exclamation("Unable to open file"); return; }
String raw = fin.Get((dword)fin.GetSize());

// Convert String to uncompressed Image
Image img = StreamRaster::LoadStringAny(raw);
// If you know the image format you could also use:
// Image img = JPGRaster().LoadString(raw);



Or just:

Image img = StreamRaster::LoadFileAny(IMAGE_FILE_PATH);

Mirek

He already had the raw JPG in memory from an incoming MPEG stream. The first bit is merely illustative.

Incidentally, the first time I attempted to compile this the various image plugins were lised in TheIDE (SVN version compile two days ago), but weren't actually included in the build process. I had to add them to the project to compile it (which is what I would expect, but having them visible is misleading).
Re: [SOLVED] accessing pixels in JPEG created from memory buffer [message #21428 is a reply to message #21408] Tue, 19 May 2009 21:34 Go to previous message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello qwerty

If you have any question about image processing perhaps I may help you. Perhaps you know a lot but if you are stuck ask just in case.

Best regards
Koldo


Best regards
Iñaki
Previous Topic: Optimal ctrl refresh
Next Topic: Draw package and console app error
Goto Forum:
  


Current Time: Fri Mar 29 12:28:26 CET 2024

Total time taken to generate the page: 0.01407 seconds