Beispiel #1
0
/**
 * Program that converts an image to black and white
 * Usage: ./bw infile outfile
 * @author Alex Cole
 */
int main(int argc, char*argv[])
{
    simp_t image;

    if(argc != 3)
    {
        fprintf(stderr, "Usage: ./bw infile outfile\n");
        return 1;
    }

    /*reads simp file info and then converts the image to black and white*/
    if(read_simp_file(argv[1], &image) != 0) return 1;
    simp2bw(&image);
    write_simp_file(argv[2], &image);

    free_pixels(&image);
    return 0;
}
Beispiel #2
0
static void
gdk_pixbuf_finalize (GObject *object)
{
        GdkPixbuf *pixbuf = GDK_PIXBUF (object);

        switch (pixbuf->storage) {
        case STORAGE_PIXELS:
                free_pixels (pixbuf);
                break;

        case STORAGE_BYTES:
                free_bytes (pixbuf);
                break;

        default:
                g_assert_not_reached ();
        }
        
        G_OBJECT_CLASS (gdk_pixbuf_parent_class)->finalize (object);
}
/// Outputs texture data to a raw file containing the pixel data for each mip-
/// level of the texture, without any header information.
/// @param target_path A string specifying the path and filename of the file
/// to create and write with the raw pixel data.
/// @param target_format One of the values of the texture_format_e enumeration
/// specifying the target format for the texture pixel data.
/// @param levels A V8 array object to be populated with objects describing
/// each mip-level of the texture.
/// @param outputs An object specifying the outputs from the texture compiler.
/// @return undefined if the operation completes successfully; otherwise, an
/// exception object is returned.
static v8::Handle<v8::Value> v8_output_raw(
    char const                 *target_path,
    int32_t                     target_format,
    v8::Handle<v8::Array>       levels,
    texture_compiler_outputs_t *outputs)
{
    FILE  *file        = fopen(target_path, "wb");
    size_t level_count = outputs->level_count;
    size_t byte_offset = 0;
    size_t byte_size   = 0;
    v8::HandleScope  scope;

    // cache some property names so we don't create them repeatedly.
    v8::Handle<v8::String> prop_byteOffset = v8::String::New("byteOffset");
    v8::Handle<v8::String> prop_byteSize   = v8::String::New("byteSize");
    v8::Handle<v8::String> prop_height     = v8::String::New("height");
    v8::Handle<v8::String> prop_width      = v8::String::New("width");

    // open the target file to write the raw pixel data.
    if (NULL == file)
    {
        return scope.Close(ex("Cannot create file targetPath."));
    }
    // write the raw pixel data and build a descriptor for each level.
    for (size_t i = 0; i < level_count; ++i)
    {
        v8::Handle<v8::Object> desc   = v8::Object::New();
        image::buffer_t       *data   = &outputs->level_data[i];
        size_t                 width  = data->channel_width;
        size_t                 height = data->channel_height;
        size_t                 bpp    = 0;

        // get the raw pixel data and write it to the file.
        void *pixels = level_descriptor(data, target_format, &bpp, &byte_size);
        if   (pixels)
        {
            fwrite(pixels, byte_size, 1, file);
            free_pixels(pixels);
        }
        else
        {
            fclose(file); file = NULL;
            return scope.Close(ex("Cannot get pixel data for mip-level."));
        }

        // build an object describing the miplevel.
        // not happy about having to force byte_offset and byte_size
        // to 32-bit, but don't think it will be an issue in practice.
        desc->Set(prop_width,      v8::Integer::NewFromUnsigned((uint32_t) width));
        desc->Set(prop_height,     v8::Integer::NewFromUnsigned((uint32_t) height));
        desc->Set(prop_byteOffset, v8::Integer::NewFromUnsigned((uint32_t) byte_offset));
        desc->Set(prop_byteSize,   v8::Integer::NewFromUnsigned((uint32_t) byte_size));

        // add it to the back of the descriptor array.
        levels->Set((uint32_t)  i, desc);

        // update the byte offset for the next level.
        byte_offset += byte_size;
    }
    fclose(file); file = NULL;
    return scope.Close(v8::Undefined());
}