need help in building an algorithm

Johan Schoeman

Expert
Licensed User
Longtime User
XWhat about reading the pixels. Four lines horizontal and 4 lines vertical. Check the colors of the pixels for each of the 8 lines to determine the top, width, left and right of the pixels that lay at the most extreme positions (i.e. Furthest left and right and well as furthest top and bottom.
 

emexes

Expert
Licensed User
the problem in b4x that i cannot put folders inside DirAssets folder so i cannot put all images in the FILES folder. it can be around 500 images so i preffer to pack them in atlas images and like this i will have less then 50 images in the files folder. this is much more simple to handle later if you want do updates.
Hang on, so you just want to pack a number of files into one file? Why don't you just do that, with a header at the start of the combined file that points to the starts of the subfiles contained within?

Or use an existing archive library?

Or use an image format that can hold multiple layers eg TIFF or GIF? Although support for this is a bit haphazard. My fax-to-email service gives me multi-page faxes as multi-image TIFFs - with different X and Y resolutions just to make sure I'm paying attention - and it is a pain in the donkey. A handmade library format would probably be simpler.

Sure, you have to preprocess your images to pack them up ready for DirAssets, but you're doing that already anyway when you make your atlas images.

edit: removed PNG from multiple layers formats (I thought PNG did everything GIF did, but... apparently not)
 
Last edited:

Sandman

Expert
Licensed User
Longtime User
Hang on, so you just want to pack a number of files into one file? Why don't you just do that, with a header at the start of the combined file that points to the starts of the subfiles contained within?
That seems to me to be the correct solution, probably by using something like zip. Apparently the framing of the initial question in this thread made me blind to other strategies. :rolleyes:

just to make sure I'm paying attention
:D
 

ilan

Expert
Licensed User
Longtime User
I was working on a similar problem back when Trump won his first election. If you get stuck, I could dig up the code, work out wtf I did, and translate any bits that might be useful to you (from PowerBasic to B4X).


wow this looks amazing. can you share the logic or code?

XWhat about reading the pixels. Four lines horizontal and 4 lines vertical. Check the colors of the pixels for each of the 8 lines to determine the top, width, left and right of the pixels that lay at the most extreme positions (i.e. Furthest left and right and well as furthest top and bottom.

the idea is not just put the square without overlapping each other. for this problem i have already a solution. the idea is to calculate correctly the minimum needed space for all squares together and return the outer square dimension.

Hang on, so you just want to pack a number of files into one file? Why don't you just do that, with a header at the start of the combined file that points to the starts of the subfiles contained within?

Or use an existing archive library?

Or use an image format that can hold multiple layers eg TIFF or GIF? Although support for this is a bit haphazard. My fax-to-email service gives me multi-page faxes as multi-image TIFFs - with different X and Y resolutions just to make sure I'm paying attention - and it is a pain in the donkey. A handmade library format would probably be simpler.

Sure, you have to preprocess your images to pack them up ready for DirAssets, but you're doing that already anyway when you make your atlas images.

edit: removed PNG from multiple layers formats (I thought PNG did everything GIF did, but... apparently not)

no no no, i dont want to put files in one single file i want to create an Atlas Image that is a single image of several images together and then you just pick the image u need and use it in a game. i have a solution for that already as posted here:https://www.b4x.com/android/forum/threads/need-help-in-building-an-algorithm.123188/post-769480

i just wanted to create my own library (b4x) that can do it. i like to deal with coding problems and find solutions for that. i tried several options but still get not the BEST solution i would like to get.

this is an atlas image file:



bearatlas.png


and this is the Atlas.pack file with all data inside:

bearatlas.png
format: RGBA8888
filter: Nearest,Nearest
repeat: none
main
rotate: false
xy: 1, 56
size: 116, 185
orig: 116, 185
offset: 0, 0
index: -1
2
rotate: false
xy: 119, 150
size: 92, 91
orig: 92, 91
offset: 0, 0
index: -1
8
rotate: false
xy: 119, 58
size: 92, 90
orig: 92, 90
offset: 0, 0
index: -1
3
rotate: false
xy: 1, 1
size: 54, 53
orig: 54, 53
offset: 0, 0
index: -1
4
rotate: false
xy: 57, 13
size: 49, 41
orig: 49, 41
offset: 0, 0
index: -1
1
rotate: false
xy: 213, 196
size: 31, 45
orig: 31, 45
offset: 0, 0
index: -1
6
rotate: false
xy: 213, 153
size: 30, 41
orig: 30, 41
offset: 0, 0
index: -1
7
rotate: false
xy: 213, 110
size: 30, 41
orig: 30, 41
offset: 0, 0
index: -1
0
rotate: false
xy: 213, 71
size: 34, 37
orig: 34, 37
offset: 0, 0
index: -1
5
rotate: false
xy: 108, 19
size: 32, 35
orig: 32, 35
offset: 0, 0
index: -1
9
rotate: false
xy: 213, 56
size: 27, 13
orig: 27, 13
offset: 0, 0
index: -1


now you just have 1 single image in your file.dirassets folder and getting a specific bitmap from the Atlas image file is very simple.

9
rotate: false
xy: 213, 56
size: 27, 13
orig: 27, 13
offset: 0, 0
index: -1

9 = is the name of the image
rotate = check if the image is rotated on the atlas file (the GDX texture packer rotates the images to win more space and make the image size as small as possible)
xy = is the position of the image in the atlas file
size = is the width and height of the image in the atlas file
orig = ?
offset= ?
index = ?

so now i can crop the specific image from the atlas file and use it as a bitmap object in my app.
like this you can store lot of images in a very nice and clean way.

i build a class to read from the atlas.pack file that is b4x compatible and now i use the GDX texture packer in my apps but wanted to try to make my own app via B4J

just a challange for my self not something that prevent me from keep working on my project ;)

so thanx a lot for all your replies. makes me happy to see the willingness from you guys to help me (and each other in this forum) i am happy to be part of b4x.com :)
 

udg

Expert
Licensed User
Longtime User
i want to create for a new app i am building a library that creates from several images a sprite sheet.
At first I thought you were looking for a way to optimize luggages in a trunk (boot, luggage compartment..I don't know the right term), so I was ready to reply "just don't ask my wife" :D

Anyway, it's intriguing..hmmm (should I study the already existing code or "invent" a solution myself?)
BTW, Emexes' video looks really promising. ?
 

ilan

Expert
Licensed User
Longtime User
Anyway, it's intriguing..hmmm (should I study the already existing code or "invent" a solution myself?)

to tell you the truth after making a lot of apps I try to not only make apps today but also to learn new stuff when i work on a project.
i don't try to invent something new, the great thing about making your own tools that will help you in your project is that you can modify them. its not a tool that is just a tool for a specific purpose. own made tools can make your app development much easier when it comes to "repeating" processes.

examples:


and there are much more
 
  • Like
Reactions: udg

rabbitBUSH

Well-Known Member
Licensed User
i agree, but still no reply on:
I guess he's gone into the outback to find the code. ? suggested here.

EDIT come to think of it, this sounds like the sort of thing the guys who code for CNC / plasma cutters and pattern cutters know all about. That software 'parks' parts to maximize the use of a sheet of material / minimise the wastage.
 

rabbitBUSH

Well-Known Member
Licensed User
Top