[Solved] RGB values for a given color

Discuss the word processor
Post Reply
nunof32
Posts: 59
Joined: Sat Jul 28, 2012 9:52 am

[Solved] RGB values for a given color

Post by nunof32 »

Hello,

I have received a document that contains text with a background color. I like the color of that background and would like to add it to my preferred color table (Preferences > Colors > Add). To do that I would need to know the RGB values of the color that is in the received document.

Is there a way to determine the RGB values of the color of something that appears in a document (text, shape, background, highlighting, ...).

Thanks in advance for any help available.
Last edited by Hagar Delest on Fri Aug 15, 2014 2:14 pm, edited 1 time in total.
Reason: tagged [Solved].
OpenOffice 4.1.10 with MacOS X 10.13.6
F3K Total
Volunteer
Posts: 1038
Joined: Fri Dec 16, 2011 8:20 pm

Re: RGB values for a given color

Post by F3K Total »

Yes,
if you notice the colors name, then go to Tools/Options/OpenOffice/Colors -> select the color by name and see the RGB values.
C.png
R
  • MMove 1.0.6
  • Extension for easy, exact positioning of shapes, pictures, controls, frames ...
  • my current system
  • Windows 10 AOO, LOLinux Mint AOO, LO
nunof32
Posts: 59
Joined: Sat Jul 28, 2012 9:52 am

Re: RGB values for a given color

Post by nunof32 »

Many thanks.
OpenOffice 4.1.10 with MacOS X 10.13.6
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: [Solved] RGB values for a given color

Post by acknak »

nunof32 wrote:... Is there a way to determine the RGB values of the color of something that appears in a document (text, shape, background, highlighting, ...). ...
Sorry, no.

OO provides no way to manage colors that are not named, such as colors in a document imported from some other software. There document can use colors with no name but the user can't manage them or inspect them at all. The only way to investigate them directly is to look at the document xml.

You can get the color data indirectly, if you can get it into a named style. The style info is displayed on the Organizer tab when you modify the style. From your description, I can't tell whether the color is part of the paragraph style or a text (character) style.

Alternatively, you could get the color data using some macro code. There may be an example around somewhere; you'd have to Google for it.

If you can attach the document, it wouldn't take a minute to get the data from the xml.
AOO4/LO5 • Linux • Fedora 23
nunof32
Posts: 59
Joined: Sat Jul 28, 2012 9:52 am

Re: [Solved] RGB values for a given color

Post by nunof32 »

Hello acknak,

You are right in what you say. If the color is named the solution provided above by F3K Total is the way to determine its RGB values.

I did forget however to mention that the color I am trying to investigate is NOT named. I believe the document I received has been created in OO but I suspect that the author used a highly customized color table. He used some custom color from that table and that is probably the reason why the name of the color does not show when I open the document in my installation of OO (that uses the default color table).

As per your suggestion I inspected the HTML and discovered the RGB values for the color. Then I added that color onto my own color table, giving it a name *. Now I can use that color wherever I wish !

I believe this problem is now realy solved / closed.

Many thanks all for all your help.

* On OS X, to do that go to Preferences > Colors
OpenOffice 4.1.10 with MacOS X 10.13.6
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: [Solved] RGB values for a given color

Post by John_Ha »

acknak wrote:The only way to investigate them directly is to look at the document xml.
There is another way which is to do a screen copy, and put the colour into an image editor, and use it to analyse the colour.

I tested this by creating an image with a non-standard colour (R=66, G=187, B=193). I inserted the image into Writer and took a screen copy (alt/PrtScrn) and pasted the result into IrfanView. The colour was reported as R=66, G=187, B=193.

At first it seems counter intuitive that copying from the screen can give accurate results. However, you are actually copying the memory values which are driving the screen pixels, so they are completely accurate as they come from the application.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: [Solved] RGB values for a given color

Post by acknak »

Right. Thanks, John. Good suggestion!
AOO4/LO5 • Linux • Fedora 23
gerard24
Volunteer
Posts: 958
Joined: Sat Oct 30, 2010 5:12 pm
Location: France

Re: [Solved] RGB values for a given color

Post by gerard24 »

For Calc (cell background) and Writer (background text, paragraphs) and Shapes color, I'm using RGB extension.
LibreOffice 6.4.5 on Windows 10
Bill
Volunteer
Posts: 8933
Joined: Sat Nov 24, 2007 6:48 am

Re: [Solved] RGB values for a given color

Post by Bill »

There are color picker utility programs for Windows that can display the RGB values for anything on the screen. The screen capture programs PicPick and MWSnap also contain color pickers.
AOO 4.1.14 on Ubuntu MATE 22.04
nunof32
Posts: 59
Joined: Sat Jul 28, 2012 9:52 am

Re: [Solved] RGB values for a given color

Post by nunof32 »

Concerning utilities that determine the RGB values of a pixel on the screen, I have a suspicion that there are other things in play.

MAC OS X comes with a utility that, among many other things, allows for the inspection of the RGB values of any pixel on the screen.

I have done the following test :
- open a text document with the Writer
- insert a (large) shape
- color-fill the shape with, f.i., "Red" (in the default color table of my installation Red is defined as RGB 128 / 0 / 0)
- use ColorSync and check the RGB values of the pixels making up the shape
- IT IS NOT 128 / 0 / 0 ! (actually it is 163 / 0 / 0)

I have tried this with other colors noticing each time a discrepancy in the results.

I don't know where these discrepancies come from. Curiously enough if I do the same test with other programs (other than OO), the pixels do have the RGB values that were specified.
OpenOffice 4.1.10 with MacOS X 10.13.6
User avatar
RoryOF
Moderator
Posts: 34613
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: [Solved] RGB values for a given color

Post by RoryOF »

This report of discrepancies in colour handling on a Mac may be linked with the cause of other Mac display difficulties, for example
[Issue] Mac: Blurry text, Retina worse
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: [Solved] RGB values for a given color

Post by acknak »

I wonder if the screen data may be corrected for screen gamma or color profile?

Regardless, it's good to know that using a color picker may not always give the same coordinates that OO is using.
AOO4/LO5 • Linux • Fedora 23
gerard24
Volunteer
Posts: 958
Joined: Sat Oct 30, 2010 5:12 pm
Location: France

Re: [Solved] RGB values for a given color

Post by gerard24 »

May be depending on settings in Tools > Options > AOO, Accessibility (options for high contrast appearance).
Just an idea, don't make a try.
LibreOffice 6.4.5 on Windows 10
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: [Solved] RGB values for a given color

Post by John_Ha »

That is strange. Have a look at the attached colours.odt. I created a red rectangle which Tools > Options > Colours tells me is 255, 51, 51. I screen copied the page and pasted it into IrfanView and analysed the colour, and IrfanView tells me it is 255, 51, 51.

If you want to repeat the text download IrfanView. Open the image > F12 (to bring up the Paint pop-up) > select the colour picker icon > click on the red. This makes the lower colour selection box change to red. Click the red colour selection box > click Define custom colours and read off the value.
Attachments
colours.odt
(28.76 KiB) Downloaded 259 times
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
nunof32
Posts: 59
Joined: Sat Jul 28, 2012 9:52 am

Re: [Solved] RGB values for a given color

Post by nunof32 »

I performed the suggested verification on my MAC.

John_Ha's odt contains a red (255, 51, 51) rectangle.

ColorSync (MAC OS X standard utility) says the pixels are 225, 46, 46.
DigitalColor Meter (another MAC OS X standard utility) says the pixels are 255, 29, 29 (pretty close ...). But these values vary depending on what reference is used : sRGB, Generic RGB or ADOBE RGB !

Reverting to the original problem. acknak's recommendation is very wise : screen color picker utilities are not a reliable way to detremine how a non-named color has been defined in OO (at least for some screens).
OpenOffice 4.1.10 with MacOS X 10.13.6
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: [Solved] RGB values for a given color

Post by John_Ha »

acknak wrote:I wonder if the screen data may be corrected for screen gamma or color profile?
acknak

I don't know. I can see gamma being adjusted in two ways which give different results. In both cases the application sends a colour value to the memory, and the display electronics reads this value, and sends the appropriate voltage/current to the pixel to get it to display. Any colour picker or copy operation reads the memory value.

Method 1 - gamma / colour profile talks to the electronics and adjusts it

If the user perceives that red is not red enough, the gamma boosts the gain on the red amplifier electronics so the red is made stronger. In this case, the memory value stays the same.

Method 2 - gamma / colour profile adjusts the value in memory

If the user perceives that red is not red enough, the value in memory is increased to make red stronger. In this case, the memory value changes.

My gut reaction is that 1 is more likely than 2 but that is no more than a guess.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
User avatar
BratcheGeige
Posts: 11
Joined: Thu Oct 10, 2019 6:02 pm

Re: [Solved] RGB values for a given color

Post by BratcheGeige »

Try this simple code:
First select the cell with the color you want to know.

Sub ReadRGB ''''''''''''''''''''''''''''''''''''''''''
Dim sel as object
Dim Red, Green, Blue As Long
Dim x As Long ' temporary holder variable
Dim RGB As Long
sel = ThisComponent.getCurrentSelection ' ThisComponent refers to the latest open document, not the IDE
RGB = sel.CellBackColor
x = RGB \ 256 ' use backslash (\) to drop the remainder instead of rounding
Red = x \ 256 ' leftmost 8 digits show blue
Green = x - Red * 256 ' middle 8 are green
Blue = RGB - x * 256
MsgBox Red & " " & Green & " " & Blue
End Sub '''
OpenOffice 4.1.7
MacOS 10.15 Catalina
musikai
Volunteer
Posts: 294
Joined: Wed Nov 11, 2015 12:19 am

Re: [Solved] RGB values for a given color

Post by musikai »

Thank you for your code.
I added it as a more elegant alternative than mine to the color conversion snippets here:
viewtopic.php?f=21&t=99268

But as I was about to update some older code I saw that I already had it even simplier by using builtin functions:

Code: Select all

Sub ReadRGB
sel = ThisComponent.getCurrentSelection
ColorValue= sel.CellBackColor
MsgBox red(ColorValue) & " " & green(ColorValue) & " " & blue(ColorValue)
End Sub
Win7 Pro, Lubuntu 15.10, LO 4.4.7, OO 4.1.3
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
Post Reply