|
Booth, Here's sample service program RGB with procedure GetColorComponent which will return to the caller a 3-byte zero filled character field containing the color component when provided with the color string (e.g., 12.7.143 or any variant thereof) and the ordinal of the component to retrieve. The service program presumes everything is valid. Namely: 1. The color string is of the form xxx.xxx.xxx where xxx is 1 to 3 bytes in length and contains only digits. 2. The ordinal is a number in the range of 1 - 3. To view the color component as a number, simply retrieve the component into a data structure that has a numeric subfield defined as 3S 0. I'm not sure what hex form you need or I would include that as well. Tell me the hex requirements and I'll help you with that if you wish. I also include sample program RGBEx that shows how to use procedure GetColorComponent. It demonstrates the numeric view, also. Run this program and op-code Dsply shows you the retrieved and formatted data. Gary Guthrie // ***************************************************************** // * Service program... RGB * // * Description....... RGB color routines * // ***************************************************************** H NoMain // ----------------------------------------------------------------- // - GetColorComponent - Get color component by ordinal position - // - - // - Parameters: Usage Description - // - - // - Input String containing color components - // - Input Ordinal component to extract - // - - // - Return value: 3-byte zero-filled character color component - // ----------------------------------------------------------------- D GetColorComponent... D Pr 3 D ParameterIn 11 Varying D Options( *VarSize ) D Const D ParameterIn 3I 0 Value // ***************************************************************** // * Procedure..... GetColorComponent * // * Description... Get color component by ordinal position * // ***************************************************************** P GetColorComponent... P B Export D GetColorComponent... D PI 3 D StringIn 11 Varying D Options( *VarSize ) D Const D Ordinal 3I 0 Value // ================================================================= // = Definitions = // ================================================================= // ----------------------------------------------------------------- // - Work variables - // ----------------------------------------------------------------- D String S 13 Varying D Counter S 3I 0 D Pos S 3I 0 D BegPos S 3I 0 D Length S 3I 0 D CharFld S 3 /Free // ================================================================= // = Extract color component and return it to caller = // ================================================================= String = '.' + %Trim( StringIn ) + '.' ; BegPos = 1 ; For Counter = 1 to Ordinal ; Pos = %Scan( '.' : String : BegPos ) ; BegPos = Pos + 1 ; EndFor ; Length = %Scan( '.' : String : BegPos ) - BegPos ; EvalR CharFld = '000' + %Subst( String : BegPos : Length ) ; Return CharFld ; /End-Free P GetColorComponent... P E // ***************************************************************** // * Program....... RGBEx * // * Description... RGB color routines example * // ***************************************************************** // ----------------------------------------------------------------- // - GetColorComponent - Get color component by ordinal position - // - - // - Parameters: Usage Description - // - - // - Input String containing color components - // - Input Ordinal component to extract - // - - // - Return value: 3-byte zero-filled character color component - // ----------------------------------------------------------------- D GetColorComponent... D Pr 3 D ParameterIn 11 Varying D Options( *VarSize ) D Const D ParameterIn 3I 0 Value // ================================================================= // = Definitions = // ================================================================= // ----------------------------------------------------------------- // - Work variables - // ----------------------------------------------------------------- D String S 11 Varying D Ordinal S 3I 0 D CharFld DS D NbrFld 3S 0 /Free // ================================================================= // = Get color components = // ================================================================= String = '01.002.3' ; CharFld = GetColorComponent ( String : 1 ) ; Dsply CharFld ; Dsply NbrFld ; CharFld = GetColorComponent ( String : 2 ) ; Dsply CharFld ; Dsply NbrFld ; CharFld = GetColorComponent ( String : 3 ) ; Dsply CharFld ; Dsply NbrFld ; *InLR = *On ; /End-Free Booth Martin wrote: > > > Colors are coded by their red, green, blue values where each value is 0 > through 255 (00 through ff in hex) > > A value might be 130:130:130 which is a gray, or it might be 255:0:0 which > would be a red-only. White is 255:255:255 while black is 0:0:0 0.0.0 is > the same as 000.000.000, and either notation is accepted. > > My need is to find each of these block's numerical value. I am finding > this extremely confusing for me as the field can vary from 5 to 11 > characters long. > > After that, I need to convert the number to its hex equivalent. > > Any ideas would be appreciated. > > (yes, its an RPGIV question.) > --------------------------------------------------------- > Booth Martin http://www.MartinVT.com > Booth@xxxxxxxxxxxx > --------------------------------------------------------- > > > _______________________________________________ > This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list > To post a message email: RPG400-L@xxxxxxxxxxxx > To subscribe, unsubscribe, or change list options, > visit: http://lists.midrange.com/mailman/listinfo/rpg400-l > or email: RPG400-L-request@xxxxxxxxxxxx > Before posting, please take a moment to review the archives > at http://archive.midrange.com/rpg400-l.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.