/* * Copyright 2018 Pedro Melgueira * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "sobel.h" #include #include #include #include #include "macros.h" /* * Transforms the rgb information of an image stored in buffer to it's gray * representation */ int rgbToGray(byte *rgb, byte **gray, int buffer_size) { // Take size for gray image and allocate memory int gray_size = buffer_size / 3; *gray = malloc(sizeof(byte) * gray_size); // Make pointers for iteration int curr_addr = 0xfffc0000; int grayscale[128][128]; byte *p_rgb = rgb; byte *p_gray = *gray; // Calculate the value for every pixel in gray for(int i=0; i= buffer_size; int left = cindex % width == 0; int right = (cindex+1) % width == 0; op_mem[0] = !bottom && !left ? buffer[cindex-width-1] : 0; op_mem[1] = !bottom ? buffer[cindex-width] : 0; op_mem[2] = !bottom && !right ? buffer[cindex-width+1] : 0; op_mem[3] = !left ? buffer[cindex-1] : 0; op_mem[4] = buffer[cindex]; op_mem[5] = !right ? buffer[cindex+1] : 0; op_mem[6] = !top && !left ? buffer[cindex+width-1] : 0; op_mem[7] = !top ? buffer[cindex+width] : 0; op_mem[8] = !top && !right ? buffer[cindex+width+1] : 0; } /* * Performs convolution between first two arguments */ int convolution(byte *X, int *Y, int c_size) { int sum = 0; for(int i=0; i