Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Algorithm help!  (Read 2588 times)

0 Members and 1 Guest are viewing this topic.

delio

  • Newbie
  • *
  • Posts: 49
    • View Profile
    • Email
Algorithm help!
« on: April 15, 2014, 05:38:16 pm »
Hi,
I want to import bmp file to Tilemap.
but My tile map has only 40 colors.

This is my algorithm
1.Use SFML to convert color of bitmap to My Tilemap color.
2.read pixel of bitmap and store in array.
3.display Tilemap

Question is
1.How can I read pixel color in SFML?
2.How can I convert bmp color to nearest tilemap color by using SFML?

Sorry for bad explanation
Thanks,
delio

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10846
    • View Profile
    • development blog
    • Email
Re: Algorithm help!
« Reply #1 on: April 15, 2014, 05:52:27 pm »
Sorry for bad explanation
Well the "sorry" is on you, since I don't understand what you're trying to do... ;D

I want to import bmp file to Tilemap.
but My tile map has only 40 colors.
What is your "tilemap"?

1.How can I read pixel color in SFML?
You load things into an sf::Image and then use getPixel().

2.How can I convert bmp color to nearest tilemap color by using SFML?
I don't understand what you mean exactly, but you can iterate over all the pixels and change them with some simple math.

Why is there such a color limit?
Why don't you save the *.bmp directly with these colors, so you don't have to do it at runtime? ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

delio

  • Newbie
  • *
  • Posts: 49
    • View Profile
    • Email
Re: Algorithm help!
« Reply #2 on: April 15, 2014, 05:58:17 pm »
Tile map mean this : http://www.sfml-dev.org/tutorials/2.1/graphics-vertex-array.php#example-tile-map

I use tileset as a index of colors, and have only 40 colors.
but bitmap 32 bits have more than 40 colors.

I want to convert a bitmap picture to display in Tilemap by convert colors and store in array.


I don't understand what you mean exactly, but you can iterate over all the pixels and change them with some simple math.
Simple math is something about Hue or saturation?

Why is there such a color limit?
Why don't you save the *.bmp directly with these colors, so you don't have to do it at runtime? ;)
All of this is an argument of my school project :)
« Last Edit: April 15, 2014, 06:02:46 pm by delio »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10846
    • View Profile
    • development blog
    • Email
AW: Re: Algorithm help!
« Reply #3 on: April 15, 2014, 06:57:23 pm »
I use tileset as a index of colors, and have only 40 colors.
but bitmap 32 bits have more than 40 colors.
What 40 colors do you have then? I mean how do they define these 40 colors?

I want to convert a bitmap picture to display in Tilemap by convert colors and store in array.
Not sure if I'm starting to understand you, do you want to convert each pixel and then draw each pixel with a vertex array/tile map?

Simple math is something about Hue or saturation?
I don't know, bit converting some colors from the 32bit color space to your 40 color space shouldn't be so hard, if the 40 colors are logically choosen (while ignoring the uselessness of a 40 color limit).

All of this is an argument of my school project :)
Why don't you ask your assistant/prof/teacher first then? Because they (usually) get payed for their teaching/assistance, plus they probably speak your lanuage. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

delio

  • Newbie
  • *
  • Posts: 49
    • View Profile
    • Email
Re: Algorithm help!
« Reply #4 on: April 15, 2014, 07:24:44 pm »
What 40 colors do you have then? I mean how do they define these 40 colors?
40 colors is colors that my teacher define.

Not sure if I'm starting to understand you, do you want to convert each pixel and then draw each pixel with a vertex array/tile map?
Yes!!

So SFML can't do this
I'll find another library
Thanks for answer :)

I don't know, bit converting some colors from the 32bit color space to your 40 color space shouldn't be so hard, if the 40 colors are logically choosen (while ignoring the uselessness of a 40 color limit).
40 colors isn't chosen by logically :(.

Why don't you ask your assistant/prof/teacher first then? Because they (usually) get payed for their teaching/assistance, plus they probably speak your lanuage.
This is project, I do by myself. No teacher can teach me :) .

like to do this in Photoshop
http://graphicdesign.stackexchange.com/questions/654/convert-a-pattern-photo-to-a-given-palette
« Last Edit: April 15, 2014, 07:33:23 pm by delio »

StormWingDelta

  • Sr. Member
  • ****
  • Posts: 365
    • View Profile
Re: Algorithm help!
« Reply #5 on: April 16, 2014, 09:05:44 pm »
SFML can do tile maps but it helps if we know more about what you are up to. :)


I'm guessing you could have tiles that were 1 pixel in size for 1 color but still not sure what you are up to at that point since you could store them in an array.


Also are you trying to convert from a BMP resource file in visual studio to an SFML image/texture?  If so I had this issue a while ago.  The only issue would be a C# to C++ change.
« Last Edit: April 16, 2014, 09:08:39 pm by StormWingDelta »
I have many ideas but need the help of others to find way to make use of them.