Thread: Compilable image formats

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    58

    Compilable image formats

    I know that I can include xpm file format into code:
    Code:
    #include "image.xpm"
    and it will be included within the binary, adding on to the image size.

    However my issue is that xpm files aren't very optimized for size so if I want to add anything large, like a banner, It adds a very large size to my file

    I was wondering what other image formats can be included like a header file and can be added to the binary, preferably a format that can be compressed a good deal

    Thank you!

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by parad0x13 View Post
    I was wondering what other image formats can be included like a header file and can be added to the binary, preferably a format that can be compressed a good deal

    Thank you!
    Why do you want to include binary file in your source code? use resource files for adding binaries to the executable
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    58
    I'm embarrassed to say that I'm not familiar with this technique...

    Are you saying that formats such as .jpg can be included within the binary through use of resource files?!

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by parad0x13 View Post
    I'm embarrassed to say that I'm not familiar with this technique...

    Are you saying that formats such as .jpg can be included within the binary through use of resource files?!
    Any binary data could be included using resource files. How you'd like to manipulate them - it is another question. So what do you want to do with the picture file?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Hey I checked out theForger's information on using resources, but I was wondering if someone knows where more information on how resources files work? i.e. How/where the compiler lumps the resources into the executable, and how they're handled when loaded into memory on execution. Is there a standard on how resources work, or is the compiler able to freely implement this?

    Thanks
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  6. #6
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by neandrake View Post
    Hey I checked out theForger's information on using resources, but I was wondering if someone knows where more information on how resources files work? i.e. How/where the compiler lumps the resources into the executable, and how they're handled when loaded into memory on execution. Is there a standard on how resources work, or is the compiler able to freely implement this?

    Thanks
    "Resources" are a Windows concept. Windows has a specific way of embedding resources into binary files (.exe's) and then retrieving them.

    The idea of embedding program resources into a binary is not Windows-specific, but usually when people mention "resources" they are talking about Windows. If you're on Windows, you should be using the resource system. On other systems, there may be equivalents, or you may have to roll your own.

    EDIT: Embedding resources may not be the right way to go. If you might want to change the resource, it's better to have it in an external file, so that you don't have to modify your program binary when you change the resource. On Windows, resource editors can do this for you, but it becomes problematic when you combine it with code-signing, since if the file changes, the signature becomes invalidated.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Remember that #include just copies and pastes the contents of a file, so you can include anything you want anywhere so long as it's compilable code or the compiler will bark.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Elysia View Post
    Remember that #include just copies and pastes the contents of a file, so you can include anything you want anywhere so long as it's compilable code or the compiler will bark.
    Yes, and you can certainly include a file which defines an array of byte values, which is basically what an XPM file is -- but accessing this data will be specific to your own code. The Windows resource system helps by abstracting the idea of embedding and accessing resources, in a way that other programs can handle. It's good to have a standard way of doing this, even if it's platform-specific.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Oh yes, I was meant to answer that there is no "compilable" files that can be included, because the contents is just copied and pasted.
    Embedding files into an executable is not done via includes (well, at least not directly).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Registered User
    Join Date
    Jul 2008
    Posts
    58
    I want to include an image banner inside the executable, so its easy to include xpm format for this purpose, however like I stated before it is very bulky.

    If its true that I can include any bitmap format, then I guess I'm looking for a compressible bitmap format...

    Just wondering if anyone has any background on this topic

  11. #11
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Quote Originally Posted by brewbuck View Post
    "Resources" are a Windows concept. Windows has a specific way of embedding resources into binary files (.exe's) and then retrieving them.

    The idea of embedding program resources into a binary is not Windows-specific, but usually when people mention "resources" they are talking about Windows. If you're on Windows, you should be using the resource system. On other systems, there may be equivalents, or you may have to roll your own.
    Is this information stored in with the Portable Executable Header -- Windows takes care of discovering this information in the compiled binary, and loads it into memory when the program starts?
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    If it's loaded into memory after it starts, I don't know. But I do know that you can load the resources (and thus if they aren't already loaded into memory, they are now), and then fool around with it.
    That's pretty much what resources are.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    Registered User
    Join Date
    Jul 2008
    Posts
    58
    My goal is to add the file directly in the binary at compile time, like you can with an xpm. I don't want the image to be loaded as a resource...

    It's unfortunate that I can't include the image in any other format other than xpm, xbm

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It is part of the binary, and yes, it is embedded at compile time.
    But you can choose to load and use it at runtime.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #15
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Quote Originally Posted by parad0x13 View Post
    It's unfortunate that I can't include the image in any other format other than xpm, xbm
    Well, what do you expect? #include is a text replacement system; it literally includes the text of the target file in the source. What is a compiler supposed to do with binary data? XPM and XBM are just weird formats specifically designed to be included in C code.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem reading tiff image files?
    By compz in forum C++ Programming
    Replies: 9
    Last Post: 10-30-2009, 04:17 AM
  2. Replies: 1
    Last Post: 05-27-2009, 12:46 PM
  3. Simple Image Processing
    By ejohns85 in forum C++ Programming
    Replies: 4
    Last Post: 03-19-2009, 12:10 PM
  4. Custom image file formats..
    By IKG in forum C++ Programming
    Replies: 2
    Last Post: 01-01-2007, 08:56 PM
  5. Replies: 4
    Last Post: 03-02-2003, 09:12 AM