COLOR24函数:将将8位RGB值转为24为颜色索引值

本文介绍了一个名为COLOR24的功能,该功能用于将RGB颜色三文组转换为等效的24位整数表示形式。通过示例展示了如何使用此功能进行颜色转换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

;+
; NAME:
;       COLOR24
;
; PURPOSE:
;       The purpose of this function is to convert a RGB color triple
;       into the equivalent 24-big long integer. 
;
; CATEGORY:
;       Graphics, Color Specification.
;
; CALLING SEQUENCE:
;       color = COLOR24(rgb_triple)
;
; INPUTS:
;       RGB_TRIPLE: A three-element column or row array representing 
;       a color triple. The values of the elements must be between 
;       0 and 255.
;
; KEYWORD PARAMETERS:
;       None. 
;
; COMMON BLOCKS:
;       None.
;
; SIDE EFFECTS:
;       None.
;
; RESTRICTIONS:
;       None.
;
; EXAMPLE:
;       To convert the color triple for the color YELLOW, 
;       (255, 255, 0), to the hexadecimal value '00FFFF'x 
;       or the decimal number 65535, type:
;
;       color = COLOR24([255, 255, 0])
;       
;       This routine was written to be used with routines like 
;       COLORS or GETCOLOR
;
; MODIFICATION HISTORY:
;       Written by: David Fanning, 3 February 96.
;-


FUNCTION COLOR24, number

   ; This FUNCTION accepts a [red, green, blue] triple that
   ; describes a particular color and returns a 24-bit long
   ; integer that is equivalent to that color. The color is
   ; described in terms of a hexidecimal number (e.g., FF206A)
   ; where the left two digits represent the blue color, the 
   ; middle two digits represent the green color, and the right 
   ; two digits represent the red color.
   ;
   ; The triple can be either a row or column vector of 3 elements.
   
ON_ERROR, 1

IF N_ELEMENTS(number) NE 3 THEN $
   MESSAGE, 'Augument must be a three-element vector.'

IF MAX(number) GT 255 OR MIN(number) LT 0 THEN $
   MESSAGE, 'Argument values must be in range of 0-255'

base16 = [[1L, 16L], [256L, 4096L], [65536L, 1048576L]]

num24bit = 0L

FOR j=0,2 DO num24bit = num24bit + ((number(j) MOD 16) * base16(0,j)) + $
   (Fix(number(j)/16) * base16(1,j))
   
RETURN, num24bit
END 
; ******************************  of COLOR24  **************************


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值