SketchUp / api-issue-tracker

Public issue tracker for the SketchUp and LayOut's APIs
https://developer.sketchup.com/
38 stars 10 forks source link

Read/extract *.skp files thumbnails. #65

Open jiminy-billy-bob opened 6 years ago

jiminy-billy-bob commented 6 years ago

Feature request : a method to read/extract *.skp files thumbnails. I think it would make most sense in the C API, but could also be very useful in the Ruby API.

thomthom commented 6 years ago

@jiminy-billy-bob - the returned object would be an ImageRep? (This can easily be saved to file if needed.)

jiminy-billy-bob commented 6 years ago

An ImageRep seems to be the logical way to go, yes.

prachtan commented 6 years ago

Imho, it should be separated set of light-weight methods. (For thumbnails, file info, model GUID etc)

For example, if you'll have a 500MB skp file, SUModelCreateFromFile can take tens of seconds to extract only thumbnail (this will require full "read&parse" which may be pointless in most cases).

thomthom commented 6 years ago

That's a good point Piotr.

DanRathbun commented 6 years ago

I think it would make most sense in the C API, but could also be very useful in the Ruby API.

@thomthom, @jiminy-billy-bob : The API already has an extract to file method ...

Sketchup::save_thumbnail( skpfilepath, imgfilepath )

_The savethumbnail method is used to generate a thumbnail for any SKP file - not necessarily the loaded model.

... from that you should be able to load an Sketchup::ImageRep object.

Should the Sketchup::ImageRep class' constructor method be extended to allow specifying an SKP file as a load argument (that uses a model file's thumbnail image) ?

DanRathbun commented 6 years ago

... and I see no C API equivalent.

thomthom commented 6 years ago

Huh! I never noticed there was a Sketchup::save_thumbnail( skpfilepath, imgfilepath ) in the API...

The doc description says it generates a thumbnail, I wonder if that is the case - or whether it simply extract the only that already exist...

DanRathbun commented 6 years ago

I always thought it was the latter, but now that you mention it, and I reread the doc, it seems to imply the former.


This could be significant if the user has manually switched OFF the "Redefine thumbnail on save" option in Model Info > File. (Ref Issue: https://github.com/SketchUp/api-issue-tracker/issues/14)

One coder might want the internal thumbnail even if it has not been updated (recently) as they may want what the user wants as the thumbnail.

Another coder may instead want a thumbnail of the current (latest) model view regardless of what the internal thumbnail image is. (The Ruby API has the Sketchup::Model#save_thumbnail which can work for this scenario if the scene is first changed to the desired scene. But again I could not find an equivalent C API function.)

jiminy-billy-bob commented 6 years ago

From my initial tests, the thumbnail seems to be extracted, not generated. When switching of "Redefine thumbnail on save", the thumbnail is always the same.

In most cases, this is good news, as extracting is probably much faster than generating when dealing with very large files.

DanRathbun commented 6 years ago

In most cases, this is good news, as extracting is probably much faster than generating when dealing with very large files.

I'd agree. It is a simple thing to extract raw existing data from a file, but quite a complex thing to render a view (or scene.)

And then (from what I can tell of the C API documentation,) the file access APIs never had any rendering capability, nor access to a "view" object like the live internal application API. (Otherwise ppl would have been trying to create their own SketchUp clone applications using the C SDKs. Over the years quite a few "hackers" have asked how to do it, or run SketchUp in "headless" mode.)

thomthom commented 6 years ago

Logged as SU-40217

prachtan commented 5 years ago

@thomthom - regarding to #225

Maybe you could shed some light (as in the case of GUID) and share information on how to read a thumbnail manually? :)

I see that there is 'CDib' tag, followed by (DWORD) 0x4 (what's this?) then (DWORD) and the thumbnail PNG...

thomthom commented 5 years ago

You're in luck, I'd been reverse engineering this for a .SKP template for 010 Editor:

It's a value to indicate filetype

image

tiffjh63 commented 4 years ago

@thomthom - could you share the template or a description of the SKP format in some other form.

thomthom commented 4 years ago

There is no formal description of the SKP format. What are you looking for?

tiffjh63 commented 4 years ago

The information in the parts of your template that aren't in that screenshot.

pjdixit commented 3 years ago

I am working on improving SketchUp import/export functionality of an Architectural CAD software, DataCAD.

In SketchUp import dialog, we want to provide a preview image of the SketchUp file to be imported. Extracting embedded thumbnail of the SketchUp file is the only way we can get the preview quickly without parsing entire SketchUp file with C SDK and rendering the file to an offscreen buffer to generate the image.

This functionality has very real uses case and I hope the SkethcUP's API team prioritizes it.

DanRathbun commented 3 years ago

Is the import dialog running within DataCAD ? (Because SketchUp's import dialog does not currently support preview.)

If so, I wonder if 3rd party applications can leverage the "ThumbsUp.DLL" that is used to get thumbnails for the Windows File Explorer ?

jiminy-billy-bob commented 3 years ago

If so, I wonder if 3rd party applications can leverage the "ThumbsUp.DLL" that is used to get thumbnails for the Windows File Explorer ?

Interesting idea! Do we know anything about the methods exposed by this dll? Is there an equivalent on MacOS?

pjdixit commented 3 years ago

Is the import dialog running within DataCAD ? (Because SketchUp's import dialog does not currently support preview.)

If so, I wonder if 3rd party applications can leverage the "ThumbsUp.DLL" that is used to get thumbnails for the Windows File Explorer ?

Yes, it is the SketchUp Import dialog of DataCAD.

To generate the thumbnail image, you will need an OpenGL/DirectX surface to render to, that means file must be opened and rendered at least once in an GUI application with OpenGL/DirectX to generate the thumnail image. So, for example, a SKP file created purely using C SDK might not be able to embed thumbnail in it.

So a C api that queries if thumbnail is embedded in the file and if so a function to extract that thumbnail will be super useful.

DanRathbun commented 3 years ago

So a C api that queries if thumbnail is embedded in the file and if so a function to extract that thumbnail will be super useful.

Right, we agree, hence this request thread.

There is another thread here that has info about the old format's file header and the thumbnail location. However, the last version overhauled the format into a compressed archive (zip I think) and the thumbnail may be "hackable" within this archive.

But doing either "hacks" is unsupported.

Interesting idea! Do we know anything about the methods exposed by this dll?

No, it is not open source, but on Windows it would follow rules for a file preview handler. There is a C function to query a DLL for it's public exported functions, but I'm not sure if it returns information on function parameters.

As @pjdixit notes, even with this DLL, a user would have had to open the folder in Windows File Explorer in order for the skp files to have their thumbnail images added to that folder's "thumbs.db" file. (Although there may be a function to ask the DLL to return an image from a specific skp file. I don't know. It's just a thought I've long wondered about.)

Coders could lobby for a little command line utility to get_skp_thumbnail so they wouldn't need the whole SDK. (See @prachtan comments above.)

Is there an equivalent on MacOS?

I know nothing of MacOS and prefer to keep it this way. ;)

I don't even know if Mac shows file previews in it's file browser like Windows can.

prachtan commented 3 years ago

Using of "ThumbsUp.DLL":

https://github.com/microsoft/Windows-classic-samples/tree/master/Samples/Win7Samples/winui/shell/appplatform/UsingThumbnailProviders

@jiminy-billy-bob

ThumsUp.DLL is the standard Windows shell extension handler that provides IThumbnailProvider to generate thumbnails in Windows Explorer. The only downside to the above approach is that SketchUp must be installed on the target computer (and the shell thumbnail provider registered on it).

Still the best solution would be to have a little CAPI for extracting thumbnails.