473,394 Members | 1,773 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,394 software developers and data experts.

Read pixels from a PGM/PPM Image

Can some one help me to read PGM/PPM Images in C/C++. I am sure there
should be a library or a simple routine to read the pixels of an Image
and return a 2D array of pixel values...

Nov 14 '05 #1
2 13989
qu*****@gmail.com wrote:

Can some one help me to read PGM/PPM Images in C/C++. I am sure
there should be a library or a simple routine to read the pixels
of an Image and return a 2D array of pixel values...


Please tell us where you find any definition of PGM, PPM, pixel,
Image, or C++ in the C standard. In other words this is entirely
off topic for c.l.c, where we deal with the portable C language
(not C++) as defined in the C standard. You probably want a
newsgroup that deals with your particular system.

--
Some informative links:
news:news.announce.newusers
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html
Nov 14 '05 #2

<qu*****@gmail.com> wrote

Can some one help me to read PGM/PPM Images in C/C++. I am sure there
should be a library or a simple routine to read the pixels of an Image
and return a 2D array of pixel values...

It is so easy that you don't need a library routine.

First look up the format on wotsit.org. Basically it consists of width,
height, and raw pixel data, though there might be a few comments or colour
channel data in there.

I cannot remember offhand whether the width and height is big-endian or
little endian. Whichever, it may not match your machine. So write functions
that will read and write 16 and 32 bit integers in big or little endian
format, using the shift and AND and OR operators to construct the integer
portably.

Once you've done this, write a routine to load the header information, then
call malloc(), and then call fgetc() iteratively to read the pixel data.
The function should look something like this

unsigned char *readppm(const char *fname, int *width, int *height)

return NULL on any error, such as the file not being openable or there not
being enoguh memory.
Nov 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: baruch | last post by:
Hello! I'm using PHP Version 4.3.3RC5-dev with GD Version bundled (2.0.15 compatible) to generated some graphics based on mysql data and to my surprise when I use the GD function imageline($im,...
3
by: spleen | last post by:
Hiya, Im working on a project to read in a file (its a bitmap, but thats irrelevant) and I want to read in all the data after an offset, ive tried using - fread(bitmap_buffer, offset, 1, fp);...
1
by: Pierre | last post by:
Hi... again (it's a bad day) Here is the point, I draw ellipse on an image (a map) in order to map something. But what I really don't know is how to erase the ellipse if I don't want to map the...
6
by: VMI | last post by:
Is it possible to "look" at an image and "read" the letters inside of that image? For example, if I have several images of exactly the same size and each has two lines of letters (Name, telephone)...
4
by: Ma Xiaoguang | last post by:
Dear ladies and gentlemen: How to access all the pixels of a bitmap with C#? I am working with Delphi before. In Delphi, you can use TBitmap.Scanline property to access all the pixels of a...
2
by: Remync | last post by:
I am writing a program to store a ppm into one dimensional arrays in order to manipulate the data. The image that is being read is not correct. The code is as follows: if (strcmp (str, "P6") == 0) ...
4
Thekid
by: Thekid | last post by:
Hi, I know I need to use PIL, but how would I count all of the red pixels in a given image? The image is simply a vertical red line on a black background. import PIL im =...
2
by: n3ts3cur3 | last post by:
I have an array of int pixels in my c# program and i want to convert it into an image. The problem is i am converting java source code for a program into equivalent c# code. In java the line reads...
1
by: aznimah | last post by:
hi, i'm now doing a program to calculate the pixels for the comparison between two images. both image should have the same size, 16 x 16 pixels, and in a matrices representation. any suggestion that...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.