cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

layer.c (2009B)


      1/*
      2 * Licensed to the Apache Software Foundation (ASF) under one
      3 * or more contributor license agreements.  See the NOTICE file
      4 * distributed with this work for additional information
      5 * regarding copyright ownership.  The ASF licenses this file
      6 * to you under the Apache License, Version 2.0 (the
      7 * "License"); you may not use this file except in compliance
      8 * with the License.  You may obtain a copy of the License at
      9 *
     10 *   http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing,
     13 * software distributed under the License is distributed on an
     14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     15 * KIND, either express or implied.  See the License for the
     16 * specific language governing permissions and limitations
     17 * under the License.
     18 */
     19
     20#include "config.h"
     21#include "buffer.h"
     22#include "layer.h"
     23
     24#include <guacamole/mem.h>
     25
     26#include <stdlib.h>
     27
     28guacenc_layer* guacenc_layer_alloc() {
     29
     30    /* Allocate new layer */
     31    guacenc_layer* layer = (guacenc_layer*) guac_mem_zalloc(sizeof(guacenc_layer));
     32    if (layer == NULL)
     33        return NULL;
     34
     35    /* Allocate associated buffer (width, height, and image storage) */
     36    layer->buffer = guacenc_buffer_alloc();
     37    if (layer->buffer == NULL) {
     38        guac_mem_free(layer);
     39        return NULL;
     40    }
     41
     42    /* Allocate buffer for frame rendering */
     43    layer->frame = guacenc_buffer_alloc();
     44    if (layer->frame== NULL) {
     45        guacenc_buffer_free(layer->buffer);
     46        guac_mem_free(layer);
     47        return NULL;
     48    }
     49
     50    /* Layers default to fully opaque */
     51    layer->opacity = 0xFF;
     52
     53    /* Default parented to default layer */
     54    layer->parent_index = 0;
     55
     56    return layer;
     57
     58}
     59
     60void guacenc_layer_free(guacenc_layer* layer) {
     61
     62    /* Ignore NULL layers */
     63    if (layer == NULL)
     64        return;
     65
     66    /* Free internal frame buffer */
     67    guacenc_buffer_free(layer->frame);
     68
     69    /* Free underlying buffer */
     70    guacenc_buffer_free(layer->buffer);
     71
     72    guac_mem_free(layer);
     73
     74}
     75