Image read and write operations in turbo C

Reply

Join Date: Oct 2004
Posts: 31
Reputation: dalaharp is an unknown quantity at this point 
Solved Threads: 0
dalaharp dalaharp is offline Offline
Light Poster

Image read and write operations in turbo C

 
0
  #1
Oct 28th, 2004
hi,
i have to do image read and write in Turbo C.
i am very new to C.
so please help me out as to how to do these operations and provide some sample code if you have any..
i have a vague idea that it can be read as .dat file and stored in a 2d array.


thanks..
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,959
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 918
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Image read and write operations in turbo C

 
0
  #2
Oct 28th, 2004
Turbo C?

I didn't know anybody still used this old horse!
Anyway, I found something in my archives and removed the dust! This reads a character file, you want to read a binary file. The end of file marker will be different. Well partner, it's a start!
[PHP]/******************************* fgetc.c ********************************
**
** Experiments with disk file I/O:
** int fgetc(FILE *stream)
** Get a character from the device indicated by stream ( set by fopen() ).
** Written in Turbo C by vegaseat 6/23/88
**
****************************************************************************/

#include <stdio.h> /* defines FILE and EOF */

#define AMOUNT 5 /* amount of data items */
#define FALSE 0
#define TRUE 1

int display_file(void);

void main(void)
{
if (display_file() == FALSE)
puts("\n Couldn't open data file!");
printf("\n\n Press any key to go on .... ");
getchar(); /* wait */
}

int display_file(void) /* read an ASCII file and display on screen */
{
int ch; /* use int since EOF = -1 */
char filename[25];
FILE *fptr;

clrscr();
printf("\n Enter name of ASCII file : ");
gets(filename);
fptr = fopen(filename,"r"); /* open file for disk reading */

if (fptr == 0)
return (FALSE); /* file opening unsuccessful */

while ((ch = fgetc(fptr)) != EOF) /* read entire file and display */
putch(ch); /* it on the screen */

fclose(fptr); /* don't forget to close the file! */
return (TRUE); /* file succesfully scanned */
}
[/PHP]
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,596
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 712
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Image read and write operations in turbo C

 
0
  #3
Oct 28th, 2004
>Well partner, it's a start!
If by start you mean poor quality code that doesn't address the problem at all, yes.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 31
Reputation: dalaharp is an unknown quantity at this point 
Solved Threads: 0
dalaharp dalaharp is offline Offline
Light Poster

Re: Image read and write operations in turbo C

 
0
  #4
Nov 2nd, 2004
thanks a lot vegaseat..
ur code is working great..

i am actually reading a gray scale image, which has 0-255 levels of gray intensities.
so each pixel in the image or each character represents a level of gray intensity(eight bits in binary).
but as far as characters are concerned, there are only 128 ascii chars, so how can 128 ascii chars represent 256 levels of image intensities??

guess i made my question clear enough..
can anyone clear it for me???
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 11
Reputation: mr_mooz is an unknown quantity at this point 
Solved Threads: 0
mr_mooz mr_mooz is offline Offline
Newbie Poster

Re: Image read and write operations in turbo C

 
0
  #5
Nov 2nd, 2004
what u need to do is to find out the header and pixel structures for the type of file ur reading and then declare them as structs at the start of ur code. Then u can read in chunks of data from your binary file using fwrite and fread and cast it into ur structs and edit it.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 31
Reputation: dalaharp is an unknown quantity at this point 
Solved Threads: 0
dalaharp dalaharp is offline Offline
Light Poster

Re: Image read and write operations in turbo C

 
0
  #6
Nov 2nd, 2004
sounds kinda simple, but i am a C novice, so looks very complicated for my understanding.

if some example codes are there, it will help me understand it.
please..anybody......

if i am asking too much, i cant help it..:-)
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,959
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 918
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Image read and write operations in turbo C

 
0
  #7
Nov 2nd, 2004
You got me stomped, which is easy to do.
Looking through the dusty old code I noticed that I assigned the incoming character to type integer to trap the End Of File marker (-1). It makes me suspicious that in Turbo C type char was unsigned 8bit (0 to 255).
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 31
Reputation: dalaharp is an unknown quantity at this point 
Solved Threads: 0
dalaharp dalaharp is offline Offline
Light Poster

Re: Image read and write operations in turbo C

 
0
  #8
Nov 3rd, 2004
yes vegaseat, char stores 1byte.
but with 128 characters, how will it represent 256 levels????

or am i overlooking a simple fact..i dono...
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 220
Reputation: frrossk is an unknown quantity at this point 
Solved Threads: 9
frrossk's Avatar
frrossk frrossk is offline Offline
Posting Whiz in Training

Re: Image read and write operations in turbo C

 
0
  #9
Nov 3rd, 2004
Originally Posted by dalaharp
yes vegaseat, char stores 1byte.
but with 128 characters, how will it represent 256 levels????

or am i overlooking a simple fact..i dono...
In fact, 1 byte = 8 bits; so a char variable can have 2^8 = 256 values; this have nothing to do with ASCII chars...
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 31
Reputation: dalaharp is an unknown quantity at this point 
Solved Threads: 0
dalaharp dalaharp is offline Offline
Light Poster

Re: Image read and write operations in turbo C

 
0
  #10
Nov 4th, 2004
Originally Posted by frrossk
In fact, 1 byte = 8 bits; so a char variable can have 2^8 = 256 values; this have nothing to do with ASCII chars...
i have an 256x256 grayscale image in .dat format.
i am reading the file in turbo C in an 2d char array and comparing with another similar picture to check if they are the same..
and i am doing some enhancement of the original image,
and to view the enhanced image, am changing .dat to .raw format and viewing in adobe photoshop.

well is this process right?
in the sense that getting an gray scale image in 2d char array.
will it be exactly reproduced.
will the 2d char array handle a gray scale image?
thats my basic doubt..
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC