
Can any one please help he how to compile a C program on the ARM processor ??
Thank you very much in advance,
Regards,
Timothy
Hi Timothy,
Can you please expand on your question.
compile a C program on the ARM processor ??
Are we talking about Natively Compiling a C program directly on an ARM processor, or Cross-Compiling a C program from an x86/etc and copying the ARM binary to the ARM processor.
Are we talking bare-metal or os (linux/qnx) based system?
What processor are you currently targeting with your design? (with or without mmu/etc)
Regards,
Hi Robert .
Thanks for your interest in assisting me..
My project first requires me to compile a C program on the Ubuntu ( which was sucessful.. )
Secondly, I have to compile the same program to run on the ARM processor..
How do you think I can do this, Robert ??
Thanks for your reply in advance ![]()
Regards,
Timothy
Hi Timothy,
What your describing is actually pretty straight forward to do if done carefully... Take Debian for example, the same base OS source built on 8 different architectures including ARM in the current stable release.
But there are still small subtle differences that you must watch out for. So for starters of the many "ARM" processor's which one are you actually targeting? (LPCxx/SAMxx/OMAPxx)? Also is it already running an OS (such as Linux) or just a bare-metal application?
Regards,
Hi Timothy,
Since your using the Hawkboard, I'm going to assume your either running Angstrom, Debian or the old Ubuntu Jaunty release.
To build your C program for ARM, you going to need a Cross Compiler..
If your running Angstrom, did you build Angstrom from their git tree? (it builds it's own Cross Compiler).
Otherwise download and install Code Soucery's gcc for arm: http://www.codesourcery.com/sgpp/lite/arm/portal/release1600
Next, in your makefile edit the gcc/ld/as calls with a new prefix: "CROSS_COMPILE=arm-linux-gnueabi-" making sure to include the path where apprioprate.
Assuming your Makefile has Something like this:
AS = $(CROSS_COMPILE)as
LD = $(CROSS_COMPILE)ld
CC = $(CROSS_COMPILE)gcc
CPP = $(CC) -E
AR = $(CROSS_COMPILE)ar
NM = $(CROSS_COMPILE)nm
STRIP = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
Regards,
Hi Timothy,
The gcc compiler in Ubuntu is targeted for x86.. You need a Cross Compiler to build an ARM binary, please follow the link in the previous message to download a ARM cross compiler. Once downloaded and installed, you'll need to edit your Makefile like shown in the previous message.
Regards,
Hello Robert !
I finished installing the IA32 GNU/Linux Installer .
It asks me "This link needs to be opened with an Application and it asks me to choose an application..
Which application should I choose ?
And what next should I do ??
Please help..
Regards,
Timothy
Hi Timothy,
It's a shell script, it just needs to be set as excutable (sudo chmod +x *filename*) and run, there is no application to open it.
But like I mentioned in my previous message, I don't recommend the binary installer. It modifies the system path and therefore makes it hard to run mutliple versions of any other Cross Comipler. Use the tar package: IA32 GNU/Linux TAR...
From your home directory:
voodoo@voodoo-e6400:~$ tar xjf Downloads/arm-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
voodoo@voodoo-e6400:~$ export CROSS_COMPILE=/home/voodoo/arm-2010.09/bin/arm-none-linux-gnueabi-
voodoo@voodoo-e6400:~$ ${CROSS_COMPILE}gcc -v
Using built-in specs.
COLLECT_GCC=/home/voodoo/arm-2010.09/bin/arm-none-linux-gnueabi-gcc
COLLECT_LTO_WRAPPER=/home/voodoo/arm-2010.09/bin/../libexec/gcc/arm-none-linux-gnueabi/4.5.1/lto-wrapper
Target: arm-none-linux-gnueabi
Configured with: /scratch/nathan/arm-lite/src/gcc-4.5-2010.09/configure --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=arm-none-linux-gnueabi --enable-threads --disable-libmudflap --disable-libssp --disable-libstdcxx-pch --enable-extra-sgxxlite-multilibs --with-arch=armv5te --with-gnu-as --with-gnu-ld --with-specs='%{save-temps: -fverbose-asm} %{funwind-tables|fno-unwind-tables|mabi=*|ffreestanding|nostdlib:;:-funwind-tables} -D__CS_SOURCERYGXX_MAJ__=2010 -D__CS_SOURCERYGXX_MIN__=9 -D__CS_SOURCERYGXX_REV__=50 %{O2:%{!fno-remove-local-statics: -fremove-local-statics}} %{O*:%{O|O0|O1|O2|Os:;:%{!fno-remove-local-statics: -fremove-local-statics}}}' --enable-languages=c,c++ --enable-shared --enable-lto --enable-symvers=gnu --enable-__cxa_atexit --with-pkgversion='Sourcery G++ Lite 2010.09-50' --with-bugurl=https://support.codesourcery.com/GNUToolchain/ --disable-nls --prefix=/opt/codesourcery --with-sysroot=/opt/codesourcery/arm-none-linux-gnueabi/libc --with-build-sysroot=/scratch/nathan/arm-lite/install/arm-none-linux-gnueabi/libc --with-gmp=/scratch/nathan/arm-lite/obj/host-libs-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --with-mpfr=/scratch/nathan/arm-lite/obj/host-libs-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --with-mpc=/scratch/nathan/arm-lite/obj/host-libs-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --with-ppl=/scratch/nathan/arm-lite/obj/host-libs-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-cloog=/scratch/nathan/arm-lite/obj/host-libs-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --with-libelf=/scratch/nathan/arm-lite/obj/host-libs-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --disable-libgomp --enable-poison-system-directories --with-build-time-tools=/scratch/nathan/arm-lite/install/arm-none-linux-gnueabi/bin --with-build-time-tools=/scratch/nathan/arm-lite/install/arm-none-linux-gnueabi/bin
Thread model: posix
gcc version 4.5.1 (Sourcery G++ Lite 2010.09-50)
Regards,
Rebert, I get this error message:
timothy@ubuntu:~$ tar xjf Downloads/arm-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
tar (child): Downloads/arm-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
Timothy
SUCCESS ROBERT !!! ![]()
I was able to do ALL THE STEPS uptill....
timothy@ubuntu:~$ export CROSS_COMPILE=/home/timothy/arm-2010.09/bin/arm-none-linux-gnueabi-
timothy@ubuntu:~$ ${CROSS_COMPILE}gcc -v
Using built-in specs.
COLLECT_GCC=/home/timothy/arm-2010.09/bin/arm-none-linux-gnueabi-gcc
COLLECT_LTO_WRAPPER=/home/timothy/arm-2010.09/bin/../libexec/gcc/arm-none-linux-gnueabi/4.5.1/lto-wrapper
Target: arm-none-linux-gnueabi
Configured with: /scratch/nathan/arm-lite/src/gcc-4.5-2010.09/configure --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=arm-none-linux-gnueabi --enable-threads --disable-libmudflap --disable-libssp --disable-libstdcxx-pch --enable-extra-sgxxlite-multilibs --with-arch=armv5te --with-gnu-as --with-gnu-ld --with-specs='%{save-temps: -fverbose-asm} %{funwind-tables|fno-unwind-tables|mabi=*|ffreestanding|nostdlib:;:-funwind-tables} -D__CS_SOURCERYGXX_MAJ__=2010 -D__CS_SOURCERYGXX_MIN__=9 -D__CS_SOURCERYGXX_REV__=50 %{O2:%{!fno-remove-local-statics: -fremove-local-statics}} %{O*:%{O|O0|O1|O2|Os:;:%{!fno-remove-local-statics: -fremove-local-statics}}}' --enable-languages=c,c++ --enable-shared --enable-lto --enable-symvers=gnu --enable-__cxa_atexit --with-pkgversion='Sourcery G++ Lite 2010.09-50' --with-bugurl=https://support.codesourcery.com/GNUToolchain/ --disable-nls --prefix=/opt/codesourcery --with-sysroot=/opt/codesourcery/arm-none-linux-gnueabi/libc --with-build-sysroot=/scratch/nathan/arm-lite/install/arm-none-linux-gnueabi/libc --with-gmp=/scratch/nathan/arm-lite/obj/host-libs-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --with-mpfr=/scratch/nathan/arm-lite/obj/host-libs-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --with-mpc=/scratch/nathan/arm-lite/obj/host-libs-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --with-ppl=/scratch/nathan/arm-lite/obj/host-libs-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-cloog=/scratch/nathan/arm-lite/obj/host-libs-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --with-libelf=/scratch/nathan/arm-lite/obj/host-libs-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --disable-libgomp --enable-poison-system-directories --with-build-time-tools=/scratch/nathan/arm-lite/install/arm-none-linux-gnueabi/bin --with-build-time-tools=/scratch/nathan/arm-lite/install/arm-none-linux-gnueabi/bin
Thread model: posix
gcc version 4.5.1 (Sourcery G++ Lite 2010.09-50)
What should I do next, Robert ??
Regards,
Timothy
Well, you have your ARM Cross Compiler now, so I would build the project...
Where you using a Makefile (easist) or calling gcc directly?
Modify your Makefile like shown:
AS = $(CROSS_COMPILE)as
LD = $(CROSS_COMPILE)ld
CC = $(CROSS_COMPILE)gcc
CPP = $(CC) -E
AR = $(CROSS_COMPILE)ar
NM = $(CROSS_COMPILE)nm
STRIP = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
Regards,
Hi Timothy,
A Makefile, is a simple file to control compilation of a program. It's as old as unix..
http://en.wikipedia.org/wiki/Make_(software)
Since you don't know what a makefile is, then how did you compile your C program previously in ubuntu? Did you call gcc directly or what?
Regards,
Hi Timothy,
Then add the ${CROSS_COMPILE} prefix and run gcc.
voodoo@work-p4:~$ ${CROSS_COMPILE}gcc -o test test.c
Test with file:
voodoo@work-p4:~$ file test
test: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16, not stripped
^^^ That file is now built for arm... ^^^
As a makefile:
CC = ${CROSS_COMPILE}gcc
CFLAGS = -g
all: test
test: test.o
# Commands start with TAB not spaces
$(CC) $(LDFLAGS) -o $@ $^
test.o: test.c
$(CC) $(CFLAGS) -c -o $@ $<
clean:
rm -f test test.o
# This is GNU makefile extension to notify that roughly means: 'clean' does
# not depend on any files in order to call it.
.PHONY: clean
Robert,
I was sucessful to an extent...
This is what I finished doing....
timothy@ubuntu:~/Desktop$ gcc -o sums sums.c -lm
timothy@ubuntu:~/Desktop$ ./sums
Enter the no. of intensities
2
Enter the intsities
2.3
3.2
15.530001
1.011341timothy@ubuntu:~/Desktop$ ${CROSS_COMPILE}gcc -o sums sums.c -lm
timothy@ubuntu:~/Desktop$ file sums
sums: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped
----------------------------------------
I was able to do it till here, Robert...
How to proceed for...
As a makefile:
CC = ${CROSS_COMPILE}gcc
CFLAGS = -g.
.
.
Do we type this at the terminal, after file sums command???
Timothy
Hi Timothy,
timothy@ubuntu:~/Desktop$ ${CROSS_COMPILE}gcc -o sums sums.c -lmtimothy@ubuntu:~/Desktop$ file sums
sums: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped
Make sure "CROSS_COMPILE" is actually set.. "export CROSS_COMPILE=/path/to/arm/gcc" echo ${CROSS_COMPILE} will show the current path..
As a makefile:
CC = ${CROSS_COMPILE}gcc
CFLAGS = -g.
.
.
Do we type this at the terminal, after file sums command???
With the makefile, use "make all" to build everything, and "make clean" to cleanup files.
Regards,
Hi Timothy,
Can you please be more specific about your question.
What in the Makefile are you trying to modify? (it's an actual file called "Makefile" in the same directory as your *.c files) You can open it in any editor, just make sure that command lines start with "TAB"'s not "spaces"..
Otherwise with atleast CROSS_COMPILE defined it should work exactly the same way as when you called gcc from the command line..
CROSS_COMPILE = /path/to/your/arm/cross/arm-none-linux-gnueabi-
CC = ${CROSS_COMPILE}gcc
Regards,
Hi Timothy,
Well you can use any editor from the terminal, nano/vim/gedit/kate/etc...
But in this case i'll use nano:
nano Makefile
CROSS_COMPILE = arm-linux-gnueabi-
CC = ${CROSS_COMPILE}gcc
CFLAGS = -g
all: test
test: test.o
# Commands start with TAB not spaces
$(CC) $(LDFLAGS) -o $@ $^
test.o: test.c
# Commands start with TAB not spaces
$(CC) $(CFLAGS) -c -o $@ $<
clean:
# Commands start with TAB not spaces
rm -f test test.o
.PHONY: clean
Note: "TABS" don't work in this forum interface, so everything that's a command needs to be one "TAB" and use your own CROSS_COMPILER define, that one is for my install...
Hit "ctrl-x" -> "y" -> "Enter" to save and exit..
"make all" will build test.c
"make clean" will cleanup everything..
Regards,
Robert, this is how my Makefile looks like:
CROSS_COMPILE=/home/timothy/arm-2010.09/bin/arm-none-linux-gnueabi-
CC = ${CROSS_COMPILE}gcc -o sums sums.c -lm
CFLAGS = -g
all: sums
sums: sums.o
$(CC) $(LDFLAGS) -o $@ $^
sums.o: sums.c
$(CC) $(CFLAGS) -c -o $@ $<
clean:
rm -f sums sums.o
.PHONY: clean
-----------------------------------------------------------
When i save and exit, and say
timothy@ubuntu:~$ make all
make: *** No rule to make target `sums.c', needed by `sums.o'. Stop.
What do you think is wrong ?
Regards,
Timothy
Hi Timothy,
CC = ${CROSS_COMPILE}gcc -o sums sums.c -lm
That's definitely not a good place to add "-o sums sums.c -lm"
First add "-lm" too:
CC = ${CROSS_COMPILE}gcc
CFLAGS = -g
LDFLAGS = -lm
the "-o sums sums.c" is already taken care of by:
sums: sums.o
$(CC) $(LDFLAGS) -o $@ $^
Make sure sums.c actually exists...
timothy@ubuntu:~$ make all
make: *** No rule to make target `sums.c', needed by `sums.o'. Stop.
voodoo@work-p4:~/sums$ ls
Makefile sums.c
voodoo@work-p4:~/sums$ make all
arm-linux-gnueabi-gcc -g -c -o sums.o sums.c
arm-linux-gnueabi-gcc -lm -o sums sums.o
voodoo@work-p4:~/sums$ ls -lh
total 20K
-rw-r--r-- 1 voodoo voodoo 232 2011-05-02 16:56 Makefile
-rwxr-xr-x 1 voodoo voodoo 6.0K 2011-05-02 17:02 sums
-rw-r--r-- 1 voodoo voodoo 80 2011-05-02 16:53 sums.c
-rw-r--r-- 1 voodoo voodoo 2.8K 2011-05-02 17:02 sums.o
voodoo@work-p4:~/sums$ file sums
sums: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16, not stripped
Regards,
SUCCESS , Robert !! ![]()
I was able to do all these...
timothy@ubuntu:~/Desktop$
timothy@ubuntu:~/Desktop$ Makefile sums
Makefile: command not found
timothy@ubuntu:~/Desktop$ nano Makefile
timothy@ubuntu:~/Desktop$ make all
/home/timothy/arm-2010.09/bin/arm-none-linux-gnueabi-gcc -g -c -o sums.o sums.c
/home/timothy/arm-2010.09/bin/arm-none-linux-gnueabi-gcc -lm -o sums sums.o
timothy@ubuntu:~/Desktop$ ls -lh
total 508K
-rwxr-xr-x 1 timothy timothy 8.4K 2011-05-02 13:53 a.out
-rwxr-xr-x 1 timothy timothy 477 2011-03-31 05:34 gnome-terminal.desktop
drwxr-xr-x 2 timothy timothy 4.0K 2011-05-02 13:36 IISC project
-rw-r--r-- 1 timothy timothy 271 2011-05-02 18:34 Makefile
-rw-r--r-- 1 timothy timothy 9.9K 2011-05-02 13:56 steps.odt
-rwxr-xr-x 1 timothy timothy 12K 2011-05-02 18:37 sums
-rw-r--r-- 1 timothy timothy 431 2011-05-02 16:34 sums.c
-rw-r--r-- 1 timothy timothy 4.5K 2011-05-02 18:37 sums.o
-rw-r--r-- 1 timothy timothy 434K 2011-05-02 15:05 TIM4_IEEE.pdf
-rw-r--r-- 1 timothy timothy 8.9K 2011-05-02 10:09 Untitled 1.odt
timothy@ubuntu:~/Desktop$ file sums
sums: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16, not stripped
timothy@ubuntu:~/Desktop$
Thank you very much
Regards,
Timothy
Good Morning Robert,
In a previous mail, you asked me, saying...
" Well, do you still have that OMAP L138 platform around from your previous posts and is it still working?
I'd power the L138 back up and copy the "sums" arm binary to it that you just built and try to run the program.. "
Can you please explain, what it means??
What do you mean by, powering the L138 back up ?
How do we copy the "Sums" arm binary to it?
Regards,
Timothy
Hi Timothy,
In one of your first messages you said:
"The ARM processor that I am targetting is the ARM processor from the OMAP L138 platform. ( It recides on the Hawkboard - a microcomputer)"
I'm assuming you actually have this device?
I'm also been assuming it's running an OS based on linux as you never answered this question either. "Are we talking bare-metal or os (linux/qnx) based system?"
So right now you have an ARM binary "sums" that is ready to be run on your platform (OMAP L138 running Linux). So either copy the "sums" binary to the sd/mmc card, or over a usb flash drive, or over a network, etc.. (there's 1000's of ways..) Once you do that, you should be able to run your "sums" binary right on the OMAP L138..
Regards,
Hi Robert..
Thanks for your reply...
To be honest, I still haven't purchased it yet.. I'll buy it now...
Well, the answer to that question is that, since I haven't purchased it yet, I don't know whether it is running based on an OS..
I'm assuming that when I but it, it will be like an embedded hardware..
Any tips for buying the Hawkboard?
Should I specify any requirements while purchasing it?
Regards,
Hi Timothy,
Honestly I'd stay away from the Hawkboard till the redesign comes out..
http://groups.google.com/group/hawkboard/browse_frm/thread/62bc07fde4c9447c
Take a look at either the BeagleBoard or PandaBoard, both are currently well supported. They are both in high demand so tend to fly off the shelf pretty quickly..
http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=296-25798-ND
http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=UEVM4430F-01-00-00-ND
Regards,
Hi Timothy,
Yeah, make sure you show your professor the current topics in the hawkboard google group. There is a redesigned version coming, we just don't know when it'll be available, but I can't recommend any of the current Hawkboards that are for sale due to the instabilty problems seen with them.
Another thing to consider, current linux distribution support... The Hawkboard is an older ARM9 core, whereas the Beagle/Panda are Cortex-A devices (Beagle is an A8, Panda is an A9(dual core)).. (ARM9 -> ARM11 -> Cortex Ax) All the current development going forward with the main arm linux distributions: Linaro/Ubuntu/Debian (armhf) /Fedora (armhf) is to support only Cortex-A+ devices... (Of course Angstrom is updated and will support the Hawkboards as is..)
Regards,
Hi Robert ..
Nice to write to you again...
Well, I met my professor today..
The thing is that he had a Hawkboard, and permitted me to use it..
But first, now a new problem has surfaced....
The C code that I've written isn't all that right..
Can you please help me to write a C code to " Read a .jpeg file into memory"
Regards,
Timothy
Hi Timothy,
Well as long as it's the first revision of the hawkboard you should be fine...
I'd use the function "fopen" to achieve that.
http://linux.die.net/man/3/fopen
Regards,
Hi Timothy,
Here's a better example on wikipedia, they go thru the general cases of fopen/fwrite...
http://en.wikipedia.org/wiki/C_file_input/output
Regards,
I don't quiet get it, Robert..
Suppose we consider our example as shown...
#include <stdio.h> #include <stdlib.h> int main(void) { char buffer[5] = {0}; /* initialized to zeroes */ int i, rc; FILE *fp = fopen("myfile", "rb"); if (fp == NULL) { perror("Failed to open file \"myfile\""); return EXIT_FAILURE; } for (i = 0; (rc = getc(fp)) != EOF && i < 5; buffer[i++] = rc) ; fclose(fp); if (i == 5) { puts("The bytes read were..."); printf("%x %x %x %x %x\n", buffer[0], buffer[1], buffer[2], buffer[3], buffer[4]); } else fputs("There was an error reading the file.\n", stderr); return EXIT_SUCCESS; }
How do we modify this code , so that a .jpeg image can be read ?
Hi Timothy,
FILE *fp = fopen("myfile", "rb");
if (fp == NULL) {
perror("Failed to open file \"myfile\"");
return EXIT_FAILURE;
}
You've just opened "myfile"..
for (i = 0; (rc = getc(fp)) != EOF && i < 5; buffer[i++] = rc) ; fclose(fp);
You've now just copied the first 5 bytes from "myfile", copied it to the array "buffer" and then closed the "myfile"..
puts("The bytes read were...");
printf("%x %x %x %x %x\n", buffer[0], buffer[1], buffer[2], buffer[3], buffer[4]);
Now you've printed the contents of "buffer" to the console, which were the first 5 bytes you've read from "myfile".
So if all you do is change "myfile" -> "horse.jpg" in the code block, it'll read the first 5 bytes of your file and print them to the console.
Regards,
Hi Timothy,
A ".jpeg" file is actually a compressed image format, you can not directly read the 256x256 pixel data from the file without first running the data/image thru a jpeg decompression routine.
Such as: http://www.ijg.org/
For your first pass on this project you really should switch to a "*.bmp" image, which is a very simple image format, it's just made up of a simple header followed by the raw pixel data.
Have you been successful in loading the whole image file into memory?
Regards,
Hi Timothy,
Can you please be more specific with your question? Where are you having issues?
With the above example code, you should now able to open the file, pull the first 5 bytes from it and display to the terminal?
How much C Programming experience do you have? (if you don't already have a copy I highly recommend getting a copy of K & R's C programming book.. http://en.wikipedia.org/wiki/The_C_Programming_Language )
Couple other good examples of fopen uses's..
http://www.learn-programming.za.net/programming_c_learn10.html
I also found an excellent you tube video tutorial.
Regards,
Hi Timothy,
The "Pixels" are encoded into the Bit stream of the file... JPEG's is a compressed image format, all the pixels are there in a compressed form, you just need to run a decompression program on it (such as: libjpeg)... After conversion the end result is a "bmp" image, which is a very simple format: http://en.wikipedia.org/wiki/BMP_file_format that essentially puts all raw pixels in a big array...
So back to the JPEG file, open the file in a hex editor, you should see this sequence at the start..
FF D8 FF E0 ** ** 4A 46 49 46 00 (** two bytes ignored)
These first 5 bytes should also be dumpted to the terminal with your program, you just found the JPEG header..
Next take a look at "File Details": http://www.fileformat.info/format/jpeg/egff.htm
Using a stock JPEG photo:
FF D8 -> SOI
FF E0 -> APP0
00 10 -> Length of APP0
4A 46 49 -> JFIF
46 00 -> JFIF Format Revision
01 -> Units
01 00 -> X density
<...>
The rest is for you to decode and figure out.
Another example to look at is: http://paulbourke.net/libraries/ (jpeg.h/jpeg.c routines)
Regards,
Privacy Statement | Terms & Conditions | Careers | webmaster@digikey.com |
|
701 Brooks Avenue South, Thief River Falls, MN 56701 USA Phone: 1-800-344-4539 or 218-681-6674 or Fax: 218-681-3380 |
|||||||||

Quick Links:














