Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.

API Design #1

Open
Southclaws opened this issue Dec 31, 2017 · 2 comments
Open

API Design #1

Southclaws opened this issue Dec 31, 2017 · 2 comments

Comments

@Southclaws
Copy link
Owner

So the primary goal of this plugin is not to simply read bitmaps and provide an API to access the pixel values. It's to facilitate things like this http://forum.sa-mp.com/showthread.php?t=516560 and the API should provide a simple and optimised way to do that leaving Pawn to do as little work as possible.

I'm thinking there should be the standard open and close functions that allocate and free a bitmap.

While it's in memory, the plugin should process the data in some way (off thread probably?) to build something akin to an index so picking pixels based on colour is fast. The kinds of images this plugin will work well with are flat images of the world map with very few colours (like on the link above). So I'm thinking of a pixel sorter style algorithm with buckets for each colour that map to XY coordinates.

Possible API:

  • PointFromColour(int colour)
  • PointsFromColour(int colour, int dest[], int max)

If these operations do turn out to be slow, I'm thinking of a streaming asynchronous API that uses Pawn callbacks when data is available:

  • PointsFromColour(int colour, string callback)
    • which would call callback either for each pixel or a group of pixels of a predefined size

Still needs ironing out, feedback appreciated!

@Hual
Copy link

Hual commented Dec 31, 2017

I suggest having the open function end with varargs for the colours whose data (position) you want to extract, like open(filename [[[, colour1], colour2], ...]) to make caching more efficient.

@Southclaws
Copy link
Owner Author

Yes that would make sense, and no args would result in all colours being cached I guess.

I say that because I have an image that literally only has 4 colours in it, white and 3 shades of green for 3 different types of trees. I know the colours already so I wouldn't need to specify them again.

This could also be used to assert if the colours actually exist in the image. If I specify Red Green and Blue but there are no Blue pixels, the open function could return some nonzero code.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants