cscg24-guacamole

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

color.c (2537B)


      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 "settings.h"
     22
     23#include <freerdp/codec/color.h>
     24#include <freerdp/freerdp.h>
     25#include <freerdp/gdi/gdi.h>
     26#include <winpr/wtypes.h>
     27
     28#include <stdint.h>
     29#include <string.h>
     30
     31UINT32 guac_rdp_get_native_pixel_format(BOOL alpha) {
     32
     33    uint32_t int_value;
     34    uint8_t raw_bytes[4] = { 0x0A, 0x0B, 0x0C, 0x0D };
     35
     36    memcpy(&int_value, raw_bytes, sizeof(raw_bytes));
     37
     38    /* Local platform stores bytes in decreasing order of significance
     39     * (big-endian) */
     40    if (int_value == 0x0A0B0C0D)
     41        return alpha ? PIXEL_FORMAT_ARGB32 : PIXEL_FORMAT_XRGB32;
     42
     43    /* Local platform stores bytes in increasing order of significance
     44     * (little-endian) */
     45    else
     46        return alpha ? PIXEL_FORMAT_BGRA32 : PIXEL_FORMAT_BGRX32;
     47
     48}
     49
     50UINT32 guac_rdp_convert_color(rdpContext* context, UINT32 color) {
     51
     52    int depth = guac_rdp_get_depth(context->instance);
     53    int src_format = gdi_get_pixel_format(depth);
     54    int dst_format = guac_rdp_get_native_pixel_format(TRUE);
     55    rdpGdi* gdi = context->gdi;
     56
     57    /* Convert provided color into the intermediate representation expected by
     58     * FreeRDPConvertColor() */
     59    UINT32 intermed = ReadColor((BYTE*) &color, src_format);
     60
     61    /* Convert color from RDP source format to the native format used by Cairo,
     62     * still maintaining intermediate representation */
     63#ifdef HAVE_FREERDPCONVERTCOLOR
     64    intermed = FreeRDPConvertColor(intermed, src_format, dst_format,
     65            &gdi->palette);
     66#else
     67    intermed = ConvertColor(intermed, src_format, dst_format, &gdi->palette);
     68#endif
     69
     70    /* Convert color from intermediate representation to the actual desired
     71     * format */
     72    WriteColor((BYTE*) &color, dst_format, intermed);
     73    return color;
     74
     75}
     76