Image *Image_newWithPath_(char *path) { Image *self = Image_new(); Image_path_(self, path); Image_load(self); return self; }
int main (int argc, char ** argv) { int ret = EXIT_SUCCESS; // unless otherwise noted const char * in_filename = argv[1]; const char * out_filename = argv[2]; // Read the file Image * im = Image_load(in_filename); if(im == NULL) { fprintf(stderr, "Error: failed to read '%s'\n", in_filename); return EXIT_FAILURE; } // Invert pixel intensity int n_pixels = im->width * im->height; int ind; for(ind = 0; ind < n_pixels; ++ind) im->data[ind] = 255 - im->data[ind]; // Write out a new file if(!Image_save(out_filename, im)) { fprintf(stderr, "Error attempting to write '%s'\n", out_filename); ret = EXIT_FAILURE; } Image_free(im); // a memory leak until you write this function return ret; }
IoObject *IoImage_open(IoImage *self, IoObject *locals, IoMessage *m) { /*doc Image open(optionalPathString) Sets the path to optionalPathString if provided and opens the image file. Returns self on success, Nil on failure. */ /*printf("opening Image %p %s\n", self, Image_path(DATA(self)->image));*/ if (IoMessage_argCount(m) > 0) { IoSymbol *path = IoMessage_locals_symbolArgAt_(m, locals, 0); Image_path_(DATA(self)->image, CSTRING(path)); } Image_load(DATA(self)->image); IoImage_checkError(self, locals, m); return self; }