sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Jpg textures in *.skp

    Scheduled Pinned Locked Moved Developers' Forum
    34 Posts 5 Posters 2.4k Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S Offline
      soldatino
      last edited by

      I am confused about the structure of the *.skp files.
      I wrote a code using my preferred programming language that saves all the jpg files of the skp, but I have a problem, because the jpg has not a true header that I can use like a pointer with all the file's informations.
      So I saved all the jpg files, (searching some typical start strings), but also a lot of garbage (I think that the presence of garbage in the file is due the overwriting of the editor of SketchUp).
      So I recognize if it is a valid file if it has a termination block including the string of the jpg filename or his url. But it is really a very inelegant trick.
      Some suggestion?
      Thanks in advance!

      r3nDer tools

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        hmm... I wrote a PNG extractor once, and all I had to do was look for the PNG signature. Doing a quick look at a .skp file with two JPG textures I searched for the SOI (0xFF, 0xD8) and found both.

        As for the structure of the .skp files - no one knows. No public records. I have spent some time looking at it but there is so many variables that reading it reliable is difficult.

        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • S Offline
          soldatino
          last edited by

          @thomthom said:

          SOI (0xFF, 0xD8) and found both.

          Yes, 0xFF, 0xD9 and (transforming always in lowcase) "tp:","j" and "if" in the range of the following bytes...
          Thanks, at this time one problem seems to be unsolvable.The start point of the name of the default textures, because it have not "" before. I must to write a filenames table...
          But due the garbage the scan has not 100% certainty.
          Thanks!

          r3nDer tools

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            Aren't you going about it the hard way?
            The Ruby API already has ' texturewriter' tools which let you export all of the model's materials textures as correct image files - jpg, png etc.
            There are several examples of ' texturewriter' use on the forum...
            You can also extract an Image's 'image' as that part of an image-file in a a material that's applied to a face in a special kind of 'uneditable' definition...
            You will have great difficulty extracting images otherwise as a material is in a skm which is a compressed file format.

            TIG

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              @soldatino said:

              Yes, 0xFF, 0xD9

              D9 ? - from what I find ont he JPEG format it's D8... ??

              @soldatino said:

              and (transforming always in lowcase) "tp:","j" and

              what are you transforming to lower case? Isn't this something you should compare on a byte level?

              @soldatino said:

              The start point of the name of the default textures, because it have not "" before. I must to write a filenames table...
              But due the garbage the scan has not 100% certainty.

              Are you looking for more than just the JPEG data? Are you also trying to get the texture filename?
              Getting just the JPEG data extracted should be possible to reliably do - but if you're trying to get other meta data out of the .skp, that might be more troublesome - depending on what you try to extract.

              Thomas Thomassen — SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

              1 Reply Last reply Reply Quote 0
              • thomthomT Offline
                thomthom
                last edited by

                @tig said:

                The Ruby API already has ' texturewriter' tools which let you export all of the model's materials textures as correct image files - jpg, png etc.

                This only works on the currently open model.

                @soldatino said:

                I wrote a code using my preferred programming language that saves all the jpg files of the skp

                From this I gathered that he was trying to extract the JPEG data from an external application.

                Saying that though, there is an SDK to read and write .skp files: http://code.google.com/apis/sketchup/docs/downloadsdksubmit.html

                Thomas Thomassen — SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                1 Reply Last reply Reply Quote 0
                • S Offline
                  soldatino
                  last edited by

                  @thomthom said:

                  @soldatino said:

                  Yes, 0xFF, 0xD9

                  D9 ? - from what I find ont he JPEG format it's D8... ??

                  @soldatino said:

                  and (transforming always in lowcase) "tp:","j" and

                  what are you transforming to lower case? Isn't this something you should compare on a byte level?

                  @soldatino said:

                  The start point of the name of the default textures, because it have not "" before. I must to write a filenames table...
                  But due the garbage the scan has not 100% certainty.

                  Are you looking for more than just the JPEG data? Are you also trying to get the texture filename?
                  Getting just the JPEG data extracted should be possible to reliably do - but if you're trying to get other meta data out of the .skp, that might be more troublesome - depending on what you try to extract.

                  I apologize, my english is bad.
                  0xFF, 0xD8 are the bytes at the start of the file, that continues with some bytes including "j" and "if" for sure, but h-l case depending by the editor that generated the jpg.
                  0xFF, 0xD9 are the last bytes of the file and are important because I don't know the filesize.
                  After these bytes, SU writes a information block, where the presence of slashes and ".jpg" string means that the jpg original file was in the PC of the creator, differently, if they are not and you find "tp:" the file was downloaded from the web, and there is a url instead of a filename. If you find nothing and only ".jpg", the file is a SU texture in his folder.
                  Warning : the "name" is written n+chr$(0)+a+chr$(0)+m+chr$(0)+e+chr$(0)+. ......etc
                  Thank Tig and ThomThom for the infos, I will search for the API also.

                  r3nDer tools

                  1 Reply Last reply Reply Quote 0
                  • AdamBA Offline
                    AdamB
                    last edited by

                    Perhaps you're getting confused by the fact that the strings are widechars (2 bytes per character).

                    Developer of LightUp Click for website

                    1 Reply Last reply Reply Quote 0
                    • thomthomT Offline
                      thomthom
                      last edited by

                      @soldatino said:

                      0xFF, 0xD9 are the last bytes of the file and are important because I don't know the filesize.

                      There is an signed/unsigned integer in the four bytes immediately before SOI that gives you the size of the image.

                      (which is lucky as the .skp format often don't give any indication of the various sizes of its blocks.)

                      @soldatino said:

                      Warning : the "name" is written n+chr$(0)+a+chr$(0)+m+chr$(0)+e+chr$(0)+. ......etc

                      This is because part of the .skp format is in Unicode format. (Though not all strings.)

                      I've attached my notes on the .skp format. It's far from complete, and is in some places wrong. (I think I found some new info last time I looked which I haven't written down in these notes yet.)
                      Also attached is a 010 template I use when poking around in the .skp format.


                      .skp file format information

                      Thomas Thomassen — SketchUp Monkey & Coding addict
                      List of my plugins and link to the CookieWare fund

                      1 Reply Last reply Reply Quote 0
                      • S Offline
                        soldatino
                        last edited by

                        @thomthom said:

                        @soldatino said:

                        0xFF, 0xD9 are the last bytes of the file and are important because I don't know the filesize.

                        There is an signed/unsigned integer in the four bytes immediately before SOI that gives you the size of the image.

                        The size of image or the offset of the end of jpg file?

                        @thomthom said:

                        I've attached my notes on the .skp format. It's far from complete, and is in some places wrong. (I think I found some new info last time I looked which I haven't written down in these notes yet.)
                        Also attached is a 010 template I use when poking around in the .skp format.

                        Really interesting! I am finishing the first version (a couple of hours for interface) of my jpg extractor then I will study it!

                        r3nDer tools

                        1 Reply Last reply Reply Quote 0
                        • jeff hammondJ Offline
                          jeff hammond
                          last edited by

                          fwiw, you might want to check out file juicer for ideas:
                          http://echoone.com/filejuicer/

                          that apps extracts all image files from a .skp (file thumbnails, scene thumbnails, textures, images etc.) [and it will extract other file types if they happen to be in the .skp]

                          i made a post about this before in which i posted a sample output from a juiced .skp:
                          http://forums.sketchucation.com/viewtopic.php?p=276979#p276979

                          [edit] hmm.. maybe it's osx only.. surely there's something similar for windows?

                          dotdotdot

                          1 Reply Last reply Reply Quote 0
                          • thomthomT Offline
                            thomthom
                            last edited by

                            @soldatino said:

                            The size of image or the offset of the end of jpg file?

                            The size. After that 4 byte int, just read the next immediate chunk given that size and you should have your image.

                            Thomas Thomassen — SketchUp Monkey & Coding addict
                            List of my plugins and link to the CookieWare fund

                            1 Reply Last reply Reply Quote 0
                            • S Offline
                              soldatino
                              last edited by

                              @unknownuser said:

                              fwiw, you might want to check out file juicer for ideas:
                              http://echoone.com/filejuicer/

                              that apps extracts all image files from a .skp (file thumbnails, scene thumbnails, textures, images etc.) [and it will extract other file types if they happen to be in the .skp]

                              Thaks, I think to add other types of files also. Usually they have the header that it is more legible than the JPG...

                              r3nDer tools

                              1 Reply Last reply Reply Quote 0
                              • S Offline
                                soldatino
                                last edited by

                                ok, it'is working
                                http://www.imitidicthulhu.it/skp2jpg.zip
                                probably a lot of bugs ...
                                very slow on large file (I will improve the scan using blocks-buffer...)
                                and the filenames of jpg supplied by SketchUp have to clean from some starting characters (it need a table of SU files)

                                ps: at the end of each jpg there is garbage (SU notes)... but usefull for the debug, and it does not corrupt the file...

                                update 002 extract fast!
                                update 003 SU default Materials filenames fixed

                                r3nDer tools

                                1 Reply Last reply Reply Quote 0
                                • S Offline
                                  soldatino
                                  last edited by

                                  require 'sketchup.rb'
                                  if( not file_loaded?("skp2jpg.rb") )
                                  UI.menu("Plugins").add_item("skp2jpg execute"){UI.openURL("skp2jpg.exe")}
                                  end
                                  file_loaded("skp2jpg.rb")
                                  

                                  this plugin run skp2jpg.exe in the drawing session (checked on XP)
                                  skp2jpg.exe and 3Drgb.dll have to be in system32 or windows

                                  r3nDer tools

                                  1 Reply Last reply Reply Quote 0
                                  • S Offline
                                    soldatino
                                    last edited by

                                    Current skp2jpg.exe version 5, same link
                                    http://www.imitidicthulhu.it/skp2jpg.zip
                                    allows you to extract PNG files also (checked with few SU models...)

                                    EDIT version 5b (large PNGs slow fixed) 😳

                                    r3nDer tools

                                    1 Reply Last reply Reply Quote 0
                                    • S Offline
                                      soldatino
                                      last edited by

                                      skp2jpg Updated at version 7a
                                      Some lost jpg now are succesfully extracted
                                      All jpg filenames are saved, instead of xxx_num.jpg

                                      r3nDer tools

                                      1 Reply Last reply Reply Quote 0
                                      • S Offline
                                        soldatino
                                        last edited by

                                        bug found! 😕
                                        if the model has two files primarily stored by the autor in two different folders but with the same filename the program is confused and fails attempting to save the two files ... I am working about it to fix this unusual but possible recurrence..

                                        [EDIT] fixed in vers 0.0.8


                                        Clipboard01.jpg

                                        r3nDer tools

                                        1 Reply Last reply Reply Quote 0
                                        • S Offline
                                          soldatino
                                          last edited by

                                          Added in the zip the stand alone utility T-Magnifier.
                                          You can see better the selected picture that you study and/or edit.
                                          This is the v.0, next I will add the Extract button about the current picture.
                                          This trick requires SU 8, English or Italian languages
                                          (skp2jpg.exe extracts actually only all the files of the SKP)
                                          NOTE: not checked with SU version 8 Pro.


                                          T-Magnifier000.jpg

                                          r3nDer tools

                                          1 Reply Last reply Reply Quote 0
                                          • S Offline
                                            soldatino
                                            last edited by

                                            another FIX in vers 0.0.8a http://www.imitidicthulhu.it/skp2jpg.zip

                                            case : missing path, jpg file found in SU RootDir(?)
                                            no slashes found, possible prefix to filename (at end of SU file block) = &FF &FE [&??] [&??]
                                            it seems working, anyway a possible error involves only the exact filename...

                                            r3nDer tools

                                            1 Reply Last reply Reply Quote 0
                                            • 1
                                            • 2
                                            • 1 / 2
                                            • First post
                                              Last post
                                            Buy SketchPlus
                                            Buy SUbD
                                            Buy WrapR
                                            Buy eBook
                                            Buy Modelur
                                            Buy Vertex Tools
                                            Buy SketchCuisine
                                            Buy FormFonts

                                            Advertisement