Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Image_t* filter2D_Parallel_1(Image_t* im, float* mask, int numMaxThreads)
- {
- //Crear imagen resultado
- Image_t* imOut = new Image_t;
- vector<thread> threads;
- (*imOut) = (*im); //Por qué entre paréntesis?
- imOut->row_pointers = (char**)malloc(sizeof(char*)*im->height);
- for (int i = 0; i < im->height; i++) {
- imOut->row_pointers[i] = (char*)malloc(sizeof(char)*im->width * 4);
- memset(imOut->row_pointers[i], 0, sizeof(char)*im->width * 4);
- }
- //Por cada pixel de “im”
- //Mirar número máximo de hilos
- //Calcular bucles. -> Si 40000 funciona no es necesario cambiar gran cosa
- //Llamada a thread.
- for (int i = 1; i < (im->height - 1); i++)
- {
- for (int j = 1; j < (im->width - 1); j++)
- {
- threads.push_back(thread(filter2D_Thread1, im, imOut, mask, j, i));
- //cout << "Pasando el hilo i= " << i << " j = " << j << "\n";
- }
- }
- for (auto& th : threads)th.join();
- //Esperar numMaxThreads threads
- //Avanzar numMaxThreads posiciones en “im”
- //Return imagen resultado
- return imOut;
- }
- void filter2D_Thread1(Image_t* im, Image_t* result, float* mask, int j, int i)
- {
- //Designar el pixel que me toca calcular
- //Pixel que calcular =
- pixel32bpp pixlIn;
- //pixlIn = *((pixel32bpp*)(&(im->row_pointers[i][(j) * 4]))); //Posible que posWidth y posHeight estén en orden inverso
- float a, r, g, b;
- a = r = g = b = 0;
- //Dar valor a dicho pixel en la imagen im
- //meter en thread el bucle que vemos en filtro2d
- //Aplicar el cálculo visto en filtro_2d para un sólo píxel.
- //for (int i = 1; i < (im->height - 1); i++)
- //for (int j = 1; j < (im->width - 1); j++)
- {
- for (int y = -1; y < 2; y++)
- for (int x = -1; x < 2; x++)
- { //Es posible que i y j estén al revés
- pixlIn = *((pixel32bpp*)(&(im->row_pointers[i + y][(j + x) * 4])));
- a += ((float)pixlIn.a)*mask[(y + 1) * 3 + x + 1];
- r += ((float)pixlIn.r)*mask[(y + 1) * 3 + x + 1];
- g += ((float)pixlIn.g)*mask[(y + 1) * 3 + x + 1];
- b += ((float)pixlIn.b)*mask[(y + 1) * 3 + x + 1];
- }
- result->row_pointers[i][j * 4] = (char)r;
- result->row_pointers[i][j * 4 + 1] = (char)g;
- result->row_pointers[i][j * 4 + 2] = (char)b;
- result->row_pointers[i][j * 4 + 3] = (char)a;
- }
- //Dar valor a result[PixelDelThread]
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement