Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include lodepng.h #include unsigned char imageArray[1000]; //each thread slots in a value to the array struct sVars { int start; int finish; unsigned

#include

#include

#include "lodepng.h"

#include

unsigned char imageArray[1000]; //each thread slots in a value to the array

struct sVars

{

int start;

int finish;

unsigned char * structImage;

};

void * NegativeFilter(void * args)

{

struct sVars *tStruct = (struct sVars*) args;

int start = tStruct->start;

int end = tStruct->finish; //limit to how many structs the thread follows essentially how many numbers in the pixel

for(int i = start; i

{

if((i+1)%4 == 0)

{

imageArray[i] = 255;

}

else

{

imageArray[i] = 255 - tStruct->structImage[i];

}

}

}

//each pixel has 4 values (Red, Green, Blue, Transparency(alpha))

//4x4 picture has 16 pixels at least 4x one pixel

//each value for RGB is between 0-255 (transparency 0 is see through and 255 is not transparent for example on Mario colour is 255 on the red transparent part of Mario is 0)

//lodepng_encode32_file(char *filename, image, width, height)

void main(int argc, char**argv)

{

if(argc != 4)

{

printf("Invalid number of arguments. ");

return;

}

unsigned int error; //var to hold error value

unsigned char * image; // var to hold image information

unsigned int width, height;

char * filename1 = argv[1];

char * filename2 = argv[2];

lodepng_decode32_file(&image, &width, &height, filename1);

int totalVals = width * height * 4; //is the computational count how many values are in the pixel total values

int threadCount = atoi(argv[3]);

int sliceList[threadCount];

int remainder = totalVals%threadCount; // slicing is when priority is given to specific objects in a class which has priority which doesn't in

for(int i = 0; i

{

sliceList[i] = totalVals/threadCount;

}

for(int j = 0; j

{

sliceList[j] = sliceList[j] + 1;

}

int startList[threadCount];

int finishList[threadCount];

for(int k = 0; k

{

if (k == 0)

{

startList[k] = 0;

finishList[k] = startList[k] + sliceList[k] - 1;

}

else

{

startList[k] = finishList[k-1] + 1;

finishList[k] = startList[k] + sliceList[k] - 1;

}

}

pthread_t threadIDs[threadCount];

struct sVars mainStruct[threadCount];

for(int e = 0; e

{

mainStruct[e].structImage = image;

mainStruct[e].start = startList[e];

mainStruct[e].finish = finishList[e];

}

pthread_attr_t attr;

pthread_attr_init(&attr);

for(int t = 0; t

{

pthread_create(&threadIDs[t], &attr, NegativeFilter, &mainStruct[t]);

}

for(int t = 0; t

{

pthread_join(threadIDs[t], NULL);

}

if(error)

{

printf("error %d: %s ", error, lodepng_error_text(error)); //print text if there is an error

}

unsigned char image2D[height][width * 4];

for(int row = 0; row

{

for(int col = 0; col

{

image2D[row][col] = image[row * width * 3] + col;

image2D[row][col + 1] = image[row * width * 3] + col + 1;

image2D[row][col + 2] = image[row * width * 3] + col + 2;

image2D[row][col + 3] = image[row * width * 3] + col + 3;

}

}

for (int row = 0; row

{

for (int col = 0; col

{

printf("%d ", image2D[row][col]);

if ((col + 1) % 4 == 0)

{

printf("| ");

}

}

printf(" ");

}

// Blur image

void blur(int height, int width, RGBTRIPLE image[height][width])

{

RGBTRIPLE temp[height][width];

for (int row = 0; row

{

for (int col = 0; col

{

//initialize sums

int red = 0;

int green = 0;

int blue = 0;

int count = 0;

//sum surrounding pixels

for (int i = -1; i

{

for (int j = -1; j

{

//check for out of bounds

if (row + i >= 0 && row + i = 0 && col + j

{

red += image[row + i][col + j].rgbtRed;

green += image[row + i][col + j].rgbtGreen;

blue += image[row + i][col + j].rgbtBlue;

count++;

}

}

}

//average

temp[row][col].rgbtRed = round(red / count);

temp[row][col].rgbtGreen = round(green / count);

temp[row][col].rgbtBlue = round(blue / count);

}

}

for (int i = 0; i

{

for (int j = 0; j

{

//copy to original

image[i][j] = temp[i][j];

}

}

} }

hi can you change my code so it works please my program wont compile below is the is a screenshot of my directory file with an arrow pointing at the library's that i am using in my program plus the png file i want to implement in it can you sort my code out importing the file name in please.

image text in transcribed

Libary

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning ASP.NET 4.5 Databases

Authors: Sandeep Chanda, Damien Foggon

3rd Edition

1430243805, 978-1430243809

More Books

Students also viewed these Databases questions