Module: Wiretap::PPM
- Defined in:
- ext/ppm.cpp
Class Method Summary collapse
-
.format(input) ⇒ Object
Extract Wiretap clip format from PPM file.
-
.to_sgi(input, output) ⇒ Object
Convert a PPM file to an SGI file.
Class Method Details
.format(input) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'ext/ppm.cpp', line 75
static VALUE wiretap_get_ppm_format(VALUE self, VALUE input) {
FILE* infile = fopen(CSTR(input), "r");
if(!infile) {
THROW("Couldn't open file %s for reading", CSTR(input));
}
WireTapClipFormat format;
if(!ppm_read_format(infile, &format)) {
fclose(infile);
return Qfalse;
}
fclose(infile);
VALUE clip_format = rb_funcall(cClipFormat, rb_intern("new"), 0);
DATA_PTR(clip_format) = new WireTapClipFormat(format);
return clip_format;
}
|
.to_sgi(input, output) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'ext/ppm.cpp', line 97
static VALUE wiretap_convert_ppm_to_sgi(VALUE self, VALUE input, VALUE output) {
Check_Type(input, T_STRING);
Check_Type(output, T_STRING);
FILE* infile = fopen(CSTR(input), "r");
if(!infile) {
THROW("Couldn't open file %s for read", CSTR(input));
}
WireTapClipFormat format;
if(!ppm_read_format(infile, &format)) {
fclose(infile);
rb_warn("Couldn't read PPM format from file %s", CSTR(input));
return Qfalse;
}
unsigned char frame[format.frameBufferSize()];
if(!ppm_read_image(infile, frame, format.width(), format.height(), format.bitsPerPixel())) {
fclose(infile);
rb_warn("Couldn't read PPM image data from file %s", CSTR(input));
return Qfalse;
}
fclose(infile);
if(!wiretap_write_image_frame(format.width(), format.height(), format.bitsPerPixel(), frame, CSTR(output))) {
rb_warn("Couldn't dump image to file %s", CSTR(output));
return Qfalse;
}
return Qtrue;
}
|