Skip to content
Snippets Groups Projects
Commit 0d043bd4 authored by Milo Craun's avatar Milo Craun
Browse files

Added code samples

parent 83eff10f
No related branches found
No related tags found
No related merge requests found
/**
* A very basic (and abstracted) image processing filter that
* converts an RBG image (represented as 3 matrices) into a
* grayscale image using the CIE 1931 color space
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define num 64
void convert(float ** R, float ** G, float ** B, float ** lum)
{
// Formula: Y = 0.2126*R + 0.7152*G + 0.0722*B
for (int y = 0; y < num; y++) {
for (int x = 0; x < num; x++) {
//float r = 0.2126*R[y][x];
//float g = 0.7152*G[y][x];
//float b = 0.0722*B[y][x];
//lum[y][x] = r + g + b;
lum[y][x] = 0.2126*R[y][x] + 0.7152*G[y][x] + 0.0722*B[y][x];
//lum[y][x] = R[y][x] + G[y][x] + B[y][x];
}
}
}
int main() {
float ** R = (float **)malloc(num * sizeof(float *));
float ** G = (float **)malloc(num * sizeof(float *));
float ** B = (float **)malloc(num * sizeof(float *));
float ** lum = (float **)malloc(num * sizeof(float *));
for (int i = 0; i < num; i++) {
R[i] = (float *)malloc(num * sizeof(float));
G[i] = (float *)malloc(num * sizeof(float));
B[i] = (float *)malloc(num * sizeof(float));
lum[i] = (float *)malloc(num * sizeof(float));
}
for (int y = 0; y < num; y++) {
for (int x = 0; x < num; x++) {
R[y][x] = x * 0.2;
G[y][x] = x * 0.3;
B[y][x] = x * 0.4;
lum[y][x] = 0.0;
}
}
convert(R, G, B, lum);
printf("Success!\n");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
/*
* Modified kernel 1 -- hydro fragment from livermore loops
*/
void compute(int loop, int n, double * x, double * y, double * z, double q, double t, double r) {
for (int l = 1; l <= loop; l++ ) {
for (int k = 0; k < n; k++ ) {
x[k] = q + y[k]*(r*z[k+10] + t*z[k+11]);
}
}
}
int main() {
int n = 1000; // 1000 element vector
double * x = calloc(n, sizeof(double));
double * y = calloc(n, sizeof(double));
double * z = calloc(n, sizeof(double));
double t = 0.5;
double r = 0.5;
double q = 0.5;
compute(1000, n, x, y, z, q, t, r);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment