Delete Putpixel lines from a txt file based on pixel color

The Partridge Family were neither partridges nor a family. Discuss.
egizz983
Posts: 311
Joined: August 27th, 2016, 12:30 pm

Delete Putpixel lines from a txt file based on pixel color

Post by egizz983 » September 1st, 2016, 2:02 pm

So i am using tristan "image to putpixel generator app" and face a problem example i want to convert image witch a black or what ever background but you dont want to draw black background because Chili framework winapi window already have background so that would be unnecessary , and you could make it png type , so witch a code i write you could delete those putpixel lines that you dont need for example all black color pixels or what ever other color you dont want in 5k-50k pupixel lines you could spend about 3h our more , with this code you could do that in a few seconds .
At first i made this program just for the black pixel but later i think about maybe some1 else will need so make it like you could delete what ever color you want , not you can read files with a 100k lines if you need more you have to edit main.cpp file const variable maxlines.
So just download main.rar and open main.cpp (any compiler) i cout everything how to use it
Attachments
main.rar
New version Witch vectors
(711 Bytes) Downloaded 112 times
Last edited by egizz983 on September 2nd, 2016, 9:20 am, edited 5 times in total.

freebattie
Posts: 197
Joined: August 4th, 2016, 10:05 am

Re: Help with For Loop

Post by freebattie » September 1st, 2016, 2:16 pm

Hmm unsure but can it have something to do whit how much memory your "stack" or what he called it is given inside your program? feel like he was explaining this in one off the videos i was watching around 18 to 20 in the old begginers videos. where you have to use dynamic memory ? i might be wrong thou

egizz983
Posts: 311
Joined: August 27th, 2016, 12:30 pm

Re: Help with For Loop

Post by egizz983 » September 1st, 2016, 2:49 pm

okay somehow there was an empty lines inside a file i was reading and that's the reason program crashed i believe that is because of size() function ones he try to size an empty string . now i solve this and will post a full code after i do some changes maybe some1 will needs

User avatar
Peregrin_Tuk
Posts: 9
Joined: June 23rd, 2016, 7:09 pm

Re: Help with For Loop

Post by Peregrin_Tuk » September 1st, 2016, 2:54 pm

I think the problem is that you are passing the argument by value (I think that is the correct word), then you are creating an array of n elements "in run time"... you need to pass arguments by reference or the memory adress (pointers):

try this:

Code: Select all

const string file = "putpixel.txt";
const string rez = "rez.txt";
const int maxlines = 60000;
void fileRead(const string fn,string line[]);
void deleteBlack(string * line);

int main()
{
    string lines[maxlines];
    fileRead(file,lines);
    deleteBlack(lines);
    return 0;
}

void fileRead(const string fn,string line[]){
    int index = 0;
    ifstream fin(fn.c_str());
    while(!fin.eof()){
        getline(fin,line[index]);
        index++;
    }
    fin.close();
}

void deleteBlack(string *  line){
    string text= "0, 0, 0);";
    string text2;
    for(int a = 0; a < maxlines;a++){
        text2 = (*(line))[a].substr((*(line))[a].size() -9);
        if(text2 == text){
            cout << (*(line))[a] << " " << a << endl;
        }
    }
}

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Help with For Loop

Post by chili » September 1st, 2016, 3:02 pm

I don't personally use the syntax 'string lines[]' for function parameters (I use 'string* pLines'), but I think 'string lines[]' *should* work fine (too lazy to test right now, time for bed, sorry if talking out of ass :lol:).
Chili

egizz983
Posts: 311
Joined: August 27th, 2016, 12:30 pm

Re: Help with For Loop

Post by egizz983 » September 1st, 2016, 4:02 pm

chili wrote:I don't personally use the syntax 'string lines[]' for function parameters (I use 'string* pLines'), but I think 'string lines[]' *should* work fine (too lazy to test right now, time for bed, sorry if talking out of ass :lol:).
pLines ? first time heard i know pointer * but never heard of expression pLines

trybane@gmail.com
Posts: 109
Joined: August 11th, 2016, 11:17 am

Re: Help with For Loop

Post by trybane@gmail.com » September 1st, 2016, 4:53 pm

That's just what he'd name the pointer. p being a designation to help people understand its a pointer. He uses the p such as pInteger or pString so it's easy to see.

egizz983
Posts: 311
Joined: August 27th, 2016, 12:30 pm

Re: Delete Back Putpixel from a txt file

Post by egizz983 » September 1st, 2016, 4:58 pm

okay its seems there is some kind of bug , cuz not all lines are deleted its delete about 6k lines but there is still tones of them ones u check the result file , does anybody see any mistake there ?

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Delete Putpixel lines from a txt file based on pixel col

Post by albinopapa » September 1st, 2016, 9:43 pm

Your findBlack function you have declared a static array, using a function parameter instead of a constant literal

Code: Select all

 string text[allcombo];
You have to use integral literals; for example 27, 200 or 420. You can use const int SomeValue but the value has to be known at compile time, so const int count = 95, would work, but you can't pass this value to a function because then it isn't known until runtime.

Aside from that, it does appear, 100,000 string elements is a bit too much for the stack to handle.

If you want dynamic allocation you should look into std::vector.

You can declare a vector of strings
std::vector<std::string> line( maxlines );

This allocates dynamically without having to know the inner workings of how to manage dynamic memory.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

egizz983
Posts: 311
Joined: August 27th, 2016, 12:30 pm

Re: Delete Putpixel lines from a txt file based on pixel col

Post by egizz983 » September 2nd, 2016, 6:31 am

albinopapa wrote:Your findBlack function you have declared a static array, using a function parameter instead of a constant literal

Code: Select all

 string text[allcombo];
You have to use integral literals; for example 27, 200 or 420. You can use const int SomeValue but the value has to be known at compile time, so const int count = 95, would work, but you can't pass this value to a function because then it isn't known until runtime.

Aside from that, it does appear, 100,000 string elements is a bit too much for the stack to handle.

If you want dynamic allocation you should look into std::vector.

You can declare a vector of strings
std::vector<std::string> line( maxlines );

This allocates dynamically without having to know the inner workings of how to manage dynamic memory.
so you saying i cant pass allcombos into find function and use as a size of array if i get this right , then how to know how big array will be ? i mean now i make array size based on combo , witch determinate by user input . And its not a 100k thats are maximum allowed from file i read about 56k lines , and i have tried to read small files with a 2k lines its still deletes just part of a black lines and there is still alot of left

Post Reply