CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Common/Data/Convert/ColorConv.h
Views: 1401
// Copyright (c) 2015- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#pragma once1819#include "ppsspp_config.h"20#include "Common/CommonTypes.h"2122inline u8 Convert4To8(u8 v) {23// Swizzle bits: 00001234 -> 1234123424return (v << 4) | (v);25}2627inline u8 Convert5To8(u8 v) {28// Swizzle bits: 00012345 -> 1234512329return (v << 3) | (v >> 2);30}3132inline u8 Convert6To8(u8 v) {33// Swizzle bits: 00123456 -> 1234561234return (v << 2) | (v >> 4);35}3637inline u16 RGBA8888toRGB565(u32 px) {38return ((px >> 3) & 0x001F) | ((px >> 5) & 0x07E0) | ((px >> 8) & 0xF800);39}4041inline u16 RGBA8888toRGBA4444(u32 px) {42return ((px >> 4) & 0x000F) | ((px >> 8) & 0x00F0) | ((px >> 12) & 0x0F00) | ((px >> 16) & 0xF000);43}4445inline u16 BGRA8888toRGB565(u32 px) {46return ((px >> 19) & 0x001F) | ((px >> 5) & 0x07E0) | ((px << 8) & 0xF800);47}4849inline u16 BGRA8888toRGBA4444(u32 px) {50return ((px >> 20) & 0x000F) | ((px >> 8) & 0x00F0) | ((px << 4) & 0x0F00) | ((px >> 16) & 0xF000);51}5253inline u16 BGRA8888toRGBA5551(u32 px) {54return ((px >> 19) & 0x001F) | ((px >> 6) & 0x03E0) | ((px << 7) & 0x7C00) | ((px >> 16) & 0x8000);55}5657inline u16 RGBA8888toRGBA5551(u32 px) {58return ((px >> 3) & 0x001F) | ((px >> 6) & 0x03E0) | ((px >> 9) & 0x7C00) | ((px >> 16) & 0x8000);59}6061inline u32 RGBA4444ToRGBA8888(u16 src) {62const u32 r = (src & 0x000F) << 0;63const u32 g = (src & 0x00F0) << 4;64const u32 b = (src & 0x0F00) << 8;65const u32 a = (src & 0xF000) << 12;66const u32 c = r | g | b | a;67return c | (c << 4);68}6970inline u32 RGBA5551ToRGBA8888(u16 src) {71u32 dark = ((src & 0x1F) << 3) | ((src & 0x3E0) << 6) | ((src & 0x7C00) << 9);72// Replicate the top 3 upper bits into the missing lower bits.73u32 full = (dark | ((dark >> 5) & 0x070707));74if (src >> 15) {75full |= 0xFF000000;76}77return full;78}7980inline u32 RGB565ToRGBA8888(u16 src) {81u32 dark_rb = ((src & 0x1F) << 3) | ((src & 0xF800) << 8);82// Replicate the top 3 upper bits into the missing lower bits.83u32 full_rb = (dark_rb | ((dark_rb >> 5) & 0x070007));84// Add in green (6 bits instead of 5).85u32 dark_g = ((src & 0x7E0) << 5);86u32 full_g = dark_g | ((dark_g >> 6) & 0x300);87return full_rb | full_g | 0xFF000000;88}8990inline u16 RGBA8888ToRGB565(u32 value) {91u32 r = (value >> 3) & 0x1F;92u32 g = (value >> 5) & (0x3F << 5);93u32 b = (value >> 8) & (0x1F << 11);94return (u16)(r | g | b);95}9697inline u16 RGBA8888ToRGBA5551(u32 value) {98u32 r = (value >> 3) & 0x1F;99u32 g = (value >> 6) & (0x1F << 5);100u32 b = (value >> 9) & (0x1F << 10);101u32 a = (value >> 16) & 0x8000;102return (u16)(r | g | b | a);103}104105// Used in fast sprite path.106inline u16 RGBA8888ToRGBA555X(u32 value) {107u32 r = (value >> 3) & 0x1F;108u32 g = (value >> 6) & (0x1F << 5);109u32 b = (value >> 9) & (0x1F << 10);110return (u16)(r | g | b);111}112113inline u16 RGBA8888ToRGBA4444(u32 value) {114const u32 c = value >> 4;115const u16 r = (c >> 0) & 0x000F;116const u16 g = (c >> 4) & 0x00F0;117const u16 b = (c >> 8) & 0x0F00;118const u16 a = (c >> 12) & 0xF000;119return r | g | b | a;120}121122inline u16 RGBA8888ToRGBA444X(u32 value) {123const u32 c = value >> 4;124const u16 r = (c >> 0) & 0x000F;125const u16 g = (c >> 4) & 0x00F0;126const u16 b = (c >> 8) & 0x0F00;127return r | g | b;128}129130// "Complete" set of color conversion functions between the usual formats.131132// TODO: Need to revisit the naming convention of these. Seems totally backwards133// now that we've standardized on Draw::DataFormat.134//135// The functions that have the same bit width of input and output can generally136// tolerate being called with src == dst, which is used a lot for ReverseColors137// in the GLES backend.138139void ConvertBGRA8888ToRGBA8888(u32 *dst, const u32 *src, u32 numPixels);140#define ConvertRGBA8888ToBGRA8888 ConvertBGRA8888ToRGBA8888141void ConvertBGRA8888ToRGB888(u8 *dst, const u32 *src, u32 numPixels);142143void ConvertRGBA8888ToRGBA5551(u16 *dst, const u32 *src, u32 numPixels);144void ConvertRGBA8888ToRGB565(u16 *dst, const u32 *src, u32 numPixels);145void ConvertRGBA8888ToRGBA4444(u16 *dst, const u32 *src, u32 numPixels);146void ConvertRGBA8888ToRGB888(u8 *dst, const u32 *src, u32 numPixels);147148void ConvertBGRA8888ToRGBA5551(u16 *dst, const u32 *src, u32 numPixels);149void ConvertBGRA8888ToRGB565(u16 *dst, const u32 *src, u32 numPixels);150void ConvertBGRA8888ToRGBA4444(u16 *dst, const u32 *src, u32 numPixels);151152void ConvertRGB565ToRGBA8888(u32 *dst, const u16 *src, u32 numPixels);153void ConvertRGBA5551ToRGBA8888(u32 *dst, const u16 *src, u32 numPixels);154void ConvertRGBA4444ToRGBA8888(u32 *dst, const u16 *src, u32 numPixels);155156void ConvertBGR565ToRGBA8888(u32 *dst, const u16 *src, u32 numPixels);157void ConvertABGR1555ToRGBA8888(u32 *dst, const u16 *src, u32 numPixels);158void ConvertABGR4444ToRGBA8888(u32 *dst, const u16 *src, u32 numPixels);159160void ConvertRGBA4444ToBGRA8888(u32 *dst, const u16 *src, u32 numPixels);161void ConvertRGBA5551ToBGRA8888(u32 *dst, const u16 *src, u32 numPixels);162void ConvertRGB565ToBGRA8888(u32 *dst, const u16 *src, u32 numPixels);163164void ConvertRGBA4444ToABGR4444(u16 *dst, const u16 *src, u32 numPixels);165void ConvertRGBA5551ToABGR1555(u16 *dst, const u16 *src, u32 numPixels);166void ConvertRGB565ToBGR565(u16 *dst, const u16 *src, u32 numPixels);167void ConvertBGRA5551ToABGR1555(u16 *dst, const u16 *src, u32 numPixels);168169170