Haydenmango Posted June 5, 2015 Share Posted June 5, 2015 I would like to use the thumbnail images created for my model assets. Is there a way to save/open/edit model thumbnails? Quote Check out my game Rogue Snowboarding- https://haydenmango.itch.io/roguesnowboarding Link to comment Share on other sites More sharing options...
Josh Posted June 5, 2015 Share Posted June 5, 2015 SuperStrict Import "FileAttributes.bmx" Import brl.stream Import brl.pixmap Import brl.map Import brl.filesystem 'Import BRL.StandardIO Type TMetafile Field path:String Field thumbnail:TPixmap[9] Field keys:TMap=New TMap Method Save:Int() Local i:Int Local stream:TStream Local key:String Local countthumbs:Int 'If path="C:/Leadwerks/Projects/DarknessAwaits/Materials/tree_branch.tex.meta" ' DebugStop 'EndIf 'Print "saving meta file "+path If FileType(ExtractDir(path))=0 CreateDir(ExtractDir(path),True) ShowFile path stream=WriteFile(path) If Not stream Return False stream.WriteString("META") stream.WriteInt 1'version Local keycount:Int=0 For key=EachIn keys.keys() keycount:+1 Next stream.WriteInt keycount For key=EachIn keys.keys() stream.WriteLine key 'Print key+": "+String(keys.ValueForKey(key)) stream.WriteLine String(keys.ValueForKey(key)) Next For i=0 To thumbnail.length-1 If thumbnail[i] countthumbs:+1 EndIf Next 'Print countthumbs+" thumbnails saved to file" stream.WriteInt countthumbs For i=0 To thumbnail.length-1 If thumbnail[i] stream.WriteInt i stream.writebytes thumbnail[i].pixels,thumbnail[i].width*thumbnail[i].height*4 EndIf Next stream.Close() HideFile path Return True EndMethod Function LoadThumbnail:TPixmap(path:String,thumbsize:Int) Local stream:TStream Local metafile:TMetafile Local keycount:Int Local thumbcount:Int Local i:Int Local size:Int Local width:Int Local key:String Local value:String Local pixmap:TPixmap ShowFile path stream=ReadFile(path) If Not stream Return Null If stream.Eof() stream.Close() Return Null EndIf 'File tag If stream.ReadString(4)<>"META" stream.Close() HideFile path Return Null EndIf 'Version Select stream.ReadInt() Case 1 Default stream.Close() HideFile path Return Null EndSelect keycount=stream.ReadInt() For i=0 To keycount-1 key=stream.ReadLine() value=stream.ReadLine() Next thumbcount:Int=stream.ReadInt() ?debug 'Print thumbcount+" thumbnails in file." ? For i=0 To thumbcount-1 size=stream.ReadInt() ?debug 'Print size+", "+thumbsize ? width=2^size If size=thumbsize pixmap=CreatePixmap(width,width,PF_RGBA8888) stream.readbytes pixmap.pixels,width*width*4 stream.Close() HideFile path Return pixmap Else stream.Seek stream.Pos()+width*width*4 EndIf Next stream.Close() HideFile path Return Null EndFunction Function Load:TMetaFile(path:String,thumbs:Int=True) Local stream:TStream Local metafile:TMetafile Local keycount:Int Local thumbcount:Int Local i:Int Local size:Int Local width:Int Local key:String Local value:String 'Print "Loading metafile "+path showfile path stream=ReadFile(path) If Not stream Return Null If stream.Eof() stream.Close() HideFile path Return Null EndIf If stream.ReadString(4)<>"META" stream.Close() HideFile path Return Null EndIf Select stream.ReadInt() Case 1 Default stream.Close() HideFile path Return Null EndSelect metafile=New TMetafile metafile.path=path keycount=stream.ReadInt() 'Print keycount+" keys" For i=0 To keycount-1 key=stream.ReadLine() value=stream.ReadLine() metafile.keys.Insert key,value 'Print key+": "+value Next If thumbs thumbcount:Int=stream.ReadInt() For i=0 To thumbcount-1 size=stream.ReadInt() width=2^size metafile.thumbnail[size]=CreatePixmap(width,width,PF_RGBA8888) stream.readbytes metafile.thumbnail[size].pixels,width*width*4 Next EndIf stream.Close() HideFile path Return metafile EndFunction EndType 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Haydenmango Posted June 5, 2015 Author Share Posted June 5, 2015 Thanks for the reply and that sure looks interesting but I honestly don't know what it means/how I can use it. haha Does this mean that the .meta files contain the thumbnail? How would I go about using this? 1 Quote Check out my game Rogue Snowboarding- https://haydenmango.itch.io/roguesnowboarding Link to comment Share on other sites More sharing options...
Josh Posted June 5, 2015 Share Posted June 5, 2015 That's the code that loads them. There's a file version, then a list of string keys / values, then all stored thumbnails. The size you want is not guaranteed to be in the file, but most of the time the 64x64 thumbnail will be there. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
cassius Posted June 5, 2015 Share Posted June 5, 2015 blitzmax eh! Takes me back. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
Haydenmango Posted June 8, 2015 Author Share Posted June 8, 2015 I'm probably missing something obvious but how do I open the file that contains the thumbnails? Quote Check out my game Rogue Snowboarding- https://haydenmango.itch.io/roguesnowboarding Link to comment Share on other sites More sharing options...
nick.ace Posted June 8, 2015 Share Posted June 8, 2015 It's in the meta file that is autogenerated, so you open them just like any other file (like you did with your save files for HFF). It looks like each color channel is one byte in this case, so you would just use ReadUChar() for that: http://www.leadwerks.com/werkspace/page/api-reference/_/stream/streamreaduchar-r272 Basically follow this order of commands: --This sequence avoids all error checking, so implement that if you want file=FileSystem:ReadFile(path_to_file) file:ReadString(4) file:ReadInt() keycount=ReadInt() for x=0,keycount-1 do file:ReadLine() end thumbcount=file:ReadInt() for x=0, thumbcount-1 do size=file:ReadInt() width=2^size for x1=0,width-1 do for y1=0,width-1 do red=file:ReadUChar() green=file:ReadUChar() blue=file:ReadUChar() alpha=file:ReadUChar() --Do something with these colors end end end 1 Quote Link to comment Share on other sites More sharing options...
nick.ace Posted June 8, 2015 Share Posted June 8, 2015 Edit: This code is untested, but should work based off of Josh's code. Quote Link to comment Share on other sites More sharing options...
macklebee Posted June 8, 2015 Share Posted June 8, 2015 Here is a quick and dirty thumbnail extractor program. Just drag and drop the meta file onto the canvas and it will show the last saved thumbnail in the meta file. Click File-->Save and it will save a *.PNG file into the meta file's directory. thumbnail_extractor.zip 3 Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Haydenmango Posted June 8, 2015 Author Share Posted June 8, 2015 Thanks for the responses guys! I don't understand file handling very much so I've been pretty clueless. @nick.ace - Ahhh this is possibly what Josh was getting at. I was just trying to open the .meta files by clicking on them... lol Loading them through code makes a lot of sense and now I know! @macklebee - That is just what I needed and it works great! Thank you very much for making that. Now I have some code to learn from and instant gratification from macklebees app! Thanks again! 1 Quote Check out my game Rogue Snowboarding- https://haydenmango.itch.io/roguesnowboarding Link to comment Share on other sites More sharing options...
macklebee Posted June 8, 2015 Share Posted June 8, 2015 It was fun dusting off my copy of blitzmax and playing around with that. even tho it took a couple cups of coffee to remember how to do anything, i remembered how nice it was to use this software. Makes me wish Josh would post the leadwerks module that he is using so I can make a LE3 game with it. Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Josh Posted June 8, 2015 Share Posted June 8, 2015 That's why BlitzMax is so great. You can hammer out a quick little utility in a few minutes. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
macklebee Posted June 8, 2015 Share Posted June 8, 2015 That's why BlitzMax is so great. You can hammer out a quick little utility in a few minutes. agree. Makes me hopeful about the rumors of bmax2. Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.