convert.h
来自「这是符合Linux操作系统标准的POIXS 的pixops-2.0.5源程序」· C头文件 代码 · 共 164 行
H
164 行
/* Copyright (C) 2004 VMware, Inc. * This file is part of the Pixops Library. * * The pixops library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as published * by the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * The pixops library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public * License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; if not, write to the Free Software Foundation, * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *//* * convert.h -- * * Pixel conversion macros. */#ifndef _CONVERT_H_#define _CONVERT_H_#define REDMASK_BGR233 0x07#define GREENMASK_BGR233 0x38#define BLUEMASK_BGR233 0xc0#define REDMASK_15 0x7c00#define GREENMASK_15 0x03e0#define BLUEMASK_15 0x001f#define GREEN_HIBIT_15 0x0200#define GREEN_HILOSHIFT_15 4#define REDMASK_16 0xf800#define GREENMASK_16 0x07e0#define BLUEMASK_16 0x001f#define REDMASK_24 0x00ff0000#define GREENMASK_24 0x0000ff00#define BLUEMASK_24 0x000000ff#define REDMASK_32 0x00ff0000#define GREENMASK_32 0x0000ff00#define BLUEMASK_32 0x000000ff#define CONVERT_LONG_TO_SHORT(pix, \ redMask, greenMask, blueMask, \ redShift, greenShift, blueShift) \ (((redMask) & ((pix) >> (redShift))) | \ ((greenMask) & ((pix) >> (greenShift))) | \ ((blueMask) & ((pix) >> (blueShift))))#define CONVERT_SHORT_TO_LONG(pix, \ redMask, greenMask, blueMask, \ redShift1, redShift2, \ greenShift1, greenShift2, \ blueShift1, blueShift2) \ ((REDMASK_32 & \ (((((pix) & (redMask)) >> (redShift1)) | \ (((pix) & (redMask)) >> (redShift2))) << 16)) | \ (GREENMASK_32 & \ (((((pix) & (greenMask)) >> (greenShift1)) | \ (((pix) & (greenMask)) >> (greenShift2))) << 8)) | \ (BLUEMASK_32 & \ ((((pix) & (blueMask)) << (blueShift1)) | \ (((pix) & (blueMask)) >> (blueShift2)))))#define CONVERT_LONG_TO_8BGR(pix, \ redMask, greenMask, blueMask, \ redShift, greenShift, blueShift) \ (((redMask) & ((pix) >> (redShift))) | \ ((greenMask) & ((pix) >> (greenShift))) | \ ((blueMask) & ((pix) << (blueShift))))#define CONVERT_15_TO_8BGR(pix) \ (CONVERT_LONG_TO_8BGR(pix, \ REDMASK_BGR233, GREENMASK_BGR233, BLUEMASK_BGR233, \ 12, 4, 3))#define CONVERT_15_TO_16(pix) \ (((pix & (REDMASK_15 | GREENMASK_15)) << 1) | \ ((pix & GREEN_HIBIT_15) >> GREEN_HILOSHIFT_15) | \ (pix & BLUEMASK_16))#define CONVERT_15_TO_24(pix) \ (CONVERT_SHORT_TO_LONG(pix, REDMASK_15, GREENMASK_15, BLUEMASK_15, \ 7, 12, 2, 7, 3, 2))#define CONVERT_16_TO_8BGR(pix) \ (CONVERT_LONG_TO_8BGR(pix, \ REDMASK_BGR233, GREENMASK_BGR233, BLUEMASK_BGR233, \ 13, 5, 3))#define CONVERT_16_TO_15(pix) \ (((pix >> 1) & (REDMASK_15 | GREENMASK_15)) | (pix & BLUEMASK_15))#define CONVERT_16_TO_24(pix) \ (CONVERT_SHORT_TO_LONG(pix, REDMASK_16, GREENMASK_16, BLUEMASK_16, \ 8, 13, 3, 9, 3, 2))#define CONVERT_24_TO_8BGR(pix) \ (CONVERT_LONG_TO_8BGR(pix, \ REDMASK_BGR233, GREENMASK_BGR233, BLUEMASK_BGR233, \ 21, 10, 0))#define CONVERT_24_TO_15(pix) \ (CONVERT_LONG_TO_SHORT(pix, REDMASK_15, GREENMASK_15, BLUEMASK_15, 9, 6, 3))#define CONVERT_24_TO_16(pix) \ (CONVERT_LONG_TO_SHORT(pix, REDMASK_16, GREENMASK_16, BLUEMASK_16, 8, 5, 3))#define CONVERT_NOP(pix) (pix)#define BPPDEPTH(bpp, depth) ((depth == 24 && bpp == 32) ? 32 : depth)inline static uint32load_pixel (uint8 *src, int src_bytes_per_pixel, int src_depth, uint32 *src_colormap){ switch (BPPDEPTH(src_bytes_per_pixel << 3, src_depth)) { case 8: return src_colormap[*src]; case 15: return CONVERT_15_TO_24(*((uint16 *) (src))); case 16: return CONVERT_16_TO_24(*((uint16 *) (src))); default: return *((uint32 *) (src)); }}inline static voidstore_pixel (uint8 *dest, int dest_bytes_per_pixel, int dest_depth, uint32 pixel){ switch (BPPDEPTH(dest_bytes_per_pixel << 3, dest_depth)) { case 8: *dest = CONVERT_24_TO_8BGR(pixel); break; case 15: *((uint16 *) dest) = CONVERT_24_TO_15(pixel); break; case 16: *((uint16 *) dest) = CONVERT_24_TO_16(pixel); break; default: *((uint32 *) dest) = pixel; }}#endif // _CONVERT_H_
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?