C and texture files

This is a discussion on C and texture files within the Linux Programming forums, part of the Platform Specific Boards category; Hi. I'm quit new in this and i'm wondering how can be the easyest way to see it some file ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    2

    C and texture files

    Hi.

    I'm quit new in this and i'm wondering how can be the easyest way to see it some file is texture or not.

    I have read man file and man magic but i realy can not understand how to use.

    So i hope that someone can help me.

    Tnx

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    1,199
    Do you mean texture as in if its an image file or? Then you would need to read up on the different file-formats you want to be able to recognize and see what they contain as marker for that specific kind of filetype. For instance a BMP file will have 2 bytes at the very start filled with BM to make you recognize it as a BMP file.

  3. #3
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Well if you are just trying to pick out image files, file will do what you need:
    Code:
    jeff@jeff-gate:~$ file ./iltb.jpg 
    ./iltb.jpg: JPEG image data, JFIF standard 1.01, comment: "Created with GIMP\377"
    jeff@jeff-gate:~$
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  4. #4
    Registered User
    Join Date
    Apr 2010
    Posts
    2
    Hi.

    I mean, that i whant to check all kinda files and use proper one, texture type.

    I try something very similar that jeffcob write.

    In shell i use:

    file -i something
    something: application/x-executable; charset=binary


    or

    file -i Unsaved.txt
    Unsaved.txt: text/plain; charset=us-ascii

    So i want this kinda command for shell use in my C application.

    So i did with example:
    system("file -i Unsaved.txt") or system("file -i something") and return me result.

    So i got another problem, And i'm having a new question.

    If is possible when i use in my C application system("file -i Unsaved.txt"); and when return me some result i want use in my if statement only the files which are texture type like in my example for Unsaved. So if return me that is text kinda file i want this texture file rename.

    But still, how can i retreave and use it in my if statement.

    Otherwise i read somewhere that maybe i can do semeting with glib mime.

    I hope that u understand what i write.

    Tnx for help.

  5. #5
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Not sure I am following your problem correctly so if this is wrong I am sorry but I would look into the popen command described here: popen

    I use this for called command line apps and getting the results to use in an application. Still not sure what you meant by texture though -- example?
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21