Author Topic: Image palette .FC file format  (Read 264 times)

JonF

  • Professor
  • ****
  • Posts: 149
Image palette .FC file format
« on: March 06, 2024, 10:30:10 AM »
Hi all,

  Does anyone have any information or specifications for the "MicroImage" (?) .fc file format used by CalcImage for image palettes? 

I can replicate the files successfully, but I'm struggling to create a custom.fc file based on the viridis (and associated) colour palette.

In particular, do we know what the (e.g.) two 128 values represent in the example below? They're both in the 0-255 range.
The large value at the end seems to be the decimal representation of the colour.

e.g.
 Item=        128         128     3472512

Thanks!

Probeman

  • Emeritus
  • *****
  • Posts: 2836
  • Never sleeps...
    • John Donovan
Re: Image palette .FC file format
« Reply #1 on: March 06, 2024, 10:40:21 AM »
I think these codes will help.

Here's the code to convert a Surfer .CLR file to a Probe Image/CalcImage .FC (false color) file:

Code: [Select]
Sub ImageConvertCLRtoFC(tFileCLR As String, tFileFC As String)
' Convert the passed CLR file to a FC file with the same name

ierror = False
On Error GoTo ImageConvertCLRtoFCError

Dim astring As String
Dim RGBColor As Long
Dim rval As Long, gval As Long, bval As Long
Dim n As Integer
Dim Percent As Single

' Check for proper extensions
If UCase$(MiscGetFileNameExtensionOnly$(tFileCLR$)) <> ".CLR" Then GoTo ImageConvertCLRtoFCBadLUTExtension
If UCase$(MiscGetFileNameExtensionOnly$(tFileFC$)) <> ".FC" Then GoTo ImageConvertCLRtoFCBadFCExtension

If Dir$(tFileCLR$) = vbNullString Then GoTo ImageConvertCLRtoFCNotFound

Open tFileCLR$ For Input As #Temp1FileNumber%
Open tFileFC$ For Output As #Temp2FileNumber%

astring$ = "False color description for CalcImage"
Print #Temp2FileNumber%, astring$
astring$ = "BEGIN Items"
Print #Temp2FileNumber%, astring$
astring$ = " Interpolate = 1"       ' perform color interpolation
Print #Temp2FileNumber%, astring$

' Read column labels in CLR file "ColorMap 1 1"
Line Input #Temp1FileNumber%, astring$
If astring$ <> "ColorMap 1 1" Then GoTo ImageConvertCLRtoFCNotCLR

' Loop through all values in .CLR file
Do Until EOF(Temp1FileNumber%)
Input #Temp1FileNumber%, Percent!, rval&, gval&, bval&

' Convert percent to color index
n% = Percent! / 100# * 255#
If n% < 0# Then n% = 0
If n% > 255# Then n% = 255

' Convert RGB to RGB color
Call BMPRGB(RGBColor&, rval&, gval&, bval&)
If ierror Then Exit Sub
astring$ = " Item=" & Format$(n%) & " " & Format$(n%) & " " & Format$(RGBColor&)
Print #Temp2FileNumber%, astring$
Loop

astring$ = "END Items"
Print #Temp2FileNumber%, astring$

Close #Temp1FileNumber%
Close #Temp2FileNumber%
Exit Sub

' Errors
ImageConvertCLRtoFCError:
MsgBox Error$, vbOKOnly + vbCritical, "ImageConvertCLRtoFC"
Close #Temp1FileNumber%
Close #Temp2FileNumber%
ierror = True
Exit Sub

ImageConvertCLRtoFCBadLUTExtension:
msg$ = "File " & tFileCLR$ & " does not have the proper .CLR extension."
MsgBox msg$, vbOKOnly + vbExclamation, "ImageConvertCLRtoFC"
ierror = True
Exit Sub

ImageConvertCLRtoFCBadFCExtension:
msg$ = "File " & tFileFC$ & " does not have the proper .FC extension."
MsgBox msg$, vbOKOnly + vbExclamation, "ImageConvertCLRtoFC"
ierror = True
Exit Sub

ImageConvertCLRtoFCNotCLR:
msg$ = "File " & tFileCLR$ & " does not have the proper first line"
MsgBox msg$, vbOKOnly + vbExclamation, "ImageConvertCLRtoFC"
ierror = True
Exit Sub

ImageConvertCLRtoFCNotFound:
msg$ = "File " & tFileCLR$ & " was not found."
MsgBox msg$, vbOKOnly + vbExclamation, "ImageConvertCLRtoFC"
ierror = True
Exit Sub

End Sub

And here is how to convert a JEOL .LUT file to a ProbeImage/CalcImage .FC file:

Code: [Select]
Sub ImageConvertLUTtoFC(tFileLUT As String, tFileFC As String)
' Convert the passed LUT file to a FC file with the same name

ierror = False
On Error GoTo ImageConvertLUTtoFCError

Dim i As Integer
Dim astring As String
Dim RGBColor As Long
Dim n As Long, rval As Long, gval As Long, bval As Long

' Check for proper extensions
If UCase$(MiscGetFileNameExtensionOnly$(tFileLUT$)) <> ".LUT" Then GoTo ImageConvertLUTtoFCBadLUTExtension
If UCase$(MiscGetFileNameExtensionOnly$(tFileFC$)) <> ".FC" Then GoTo ImageConvertLUTtoFCBadFCExtension

If Dir$(tFileLUT$) = vbNullString Then GoTo ImageConvertLUTtoFCLUTNotFound

Open tFileLUT$ For Input As #Temp1FileNumber%
Open tFileFC$ For Output As #Temp2FileNumber%

astring$ = "False color description for CalcImage"
Print #Temp2FileNumber%, astring$
astring$ = "BEGIN Items"
Print #Temp2FileNumber%, astring$
astring$ = " Interpolate = 0"       ' all 256 values are specified
Print #Temp2FileNumber%, astring$

' Read column labels
Line Input #Temp1FileNumber%, astring$

' Loop through all values
For i% = 0 To 255
Input #Temp1FileNumber%, n&, rval&, gval&, bval&

' Convert RGB to RGB color
Call BMPRGB(RGBColor&, rval&, gval&, bval&)
If ierror Then Exit Sub
astring$ = " Item=" & Format$(i%) & " " & Format$(i%) & " " & Format$(RGBColor&)
Print #Temp2FileNumber%, astring$
Next i%

astring$ = "END Items"
Print #Temp2FileNumber%, astring$

Close #Temp1FileNumber%
Close #Temp2FileNumber%
Exit Sub

' Errors
ImageConvertLUTtoFCError:
MsgBox Error$, vbOKOnly + vbCritical, "ImageConvertLUTtoFC"
Close #Temp1FileNumber%
Close #Temp2FileNumber%
ierror = True
Exit Sub

ImageConvertLUTtoFCBadLUTExtension:
msg$ = "File " & tFileLUT$ & " does not have the proper .LUT extension."
MsgBox msg$, vbOKOnly + vbExclamation, "ImageConvertLUTtoFC"
ierror = True
Exit Sub

ImageConvertLUTtoFCBadFCExtension:
msg$ = "File " & tFileFC$ & " does not have the proper .FC extension."
MsgBox msg$, vbOKOnly + vbExclamation, "ImageConvertLUTtoFC"
ierror = True
Exit Sub

ImageConvertLUTtoFCLUTNotFound:
msg$ = "File " & tFileLUT$ & " was not found."
MsgBox msg$, vbOKOnly + vbExclamation, "ImageConvertLUTtoFC"
ierror = True
Exit Sub

End Sub

The first two numbers are the color index from 0 to 255 (I don't recall why there's two numbers off hand) and the third number is the RGB color value.   

Please post your viridis file. This can be utilized in CalcImage by naming it to CUSTOM.FC.

Also check this topic:

https://probesoftware.com/smf/index.php?topic=1003.0
« Last Edit: March 06, 2024, 10:48:36 AM by Probeman »
The only stupid question is the one not asked!

JonF

  • Professor
  • ****
  • Posts: 149
Re: Image palette .FC file format
« Reply #2 on: April 24, 2024, 08:17:19 AM »
Thanks for the code!

I don't suppose you could share the BMPRGB function? It looks like both the scripts above are using this function, passing an RGBColor$ variable (by reference?) alongside the read-in (R,G,B) values and presumably the function is altering the RGBColor$ value accordingly, which is then pasted in to the .FC file. Problem is, I'm still not sure what format the colo(u)r value is in. I originally though it was decimal, but there are several values which aren't decimal. It certainly isn't hexadecimal, nor is it (R,G,B).

Here's my latest attempt at the Plasma colour scheme, with how it should look plotted up underneath the CalcImage interpretation of it. Getting there, but not quite right yet!



 

Probeman

  • Emeritus
  • *****
  • Posts: 2836
  • Never sleeps...
    • John Donovan
Re: Image palette .FC file format
« Reply #3 on: April 24, 2024, 08:59:18 AM »
Very nice.

The BMPRGB (and UnBMPRGB) functions are here:

Code: [Select]
Sub BMPRGB(RGBColor As Long, redvalue As Long, greenvalue As Long, bluevalue As Long)
' Convert RGB to 24 bit color

ierror = False
On Error GoTo BMPRGBError

RGBColor& = RGB(CInt(redvalue&), CInt(greenvalue&), CInt(bluevalue&))

Exit Sub

' Errors
BMPRGBError:
MsgBox Error$, vbOKOnly + vbCritical, "BMPRGB"
ierror = True
Exit Sub

End Sub

Sub BMPUnRGB(RGBColor As Long, redvalue As Long, greenvalue As Long, bluevalue As Long)
' Convert 24 bit color to RGB

ierror = False
On Error GoTo BMPUnRGBError

' RGBcolor = Format(Hex(redvalue&) & Hex(greenvalue&) & Hex(bluevalue&), "000000")
redvalue& = (RGBColor& And &HFF&)
greenvalue& = (RGBColor& And &HFF00&) \ 256     ' this is correct appraently
bluevalue& = (RGBColor& And &HFF0000) \ 65536   ' this is correct apparently
   
Exit Sub

' Errors
BMPUnRGBError:
MsgBox Error$, vbOK + vbCritical, "BMPUnRGB"
ierror = True
Exit Sub

End Sub

These functions just convert RGB values to 24 bit color values (and back again).
The only stupid question is the one not asked!

JonF

  • Professor
  • ****
  • Posts: 149
Re: Image palette .FC file format
« Reply #4 on: April 24, 2024, 10:55:39 AM »
Well, ain't that the weirdest...
I ended up replicating the RGB call in VB to try and figure out where I was going wrong and it turns out VB switches the offset for the R and B channels, hence why my colours were all mixed up (i.e. the blue channel is multiplied by 65536, rather than the red channel). Simply swapped this around and everything is sorted! They are decimal values though, so I wasn't going completely mad.

This is the new LUTs in action:

Gradient .grd file:


PfE demo data:


and I've attached the .FC files for CalcImage to this post. To use them, just copy them to your PfE directory e.g. C:/ProgramData/Probe Software/Probe for EPMA/ and rename your LUT of choice to CUSTOM.FC and then re/start CalcImage, open your project/grd and go to Image Processing > Change Current Image Palettes and select Custom.

Probeman

  • Emeritus
  • *****
  • Posts: 2836
  • Never sleeps...
    • John Donovan
Re: Image palette .FC file format
« Reply #5 on: April 24, 2024, 11:45:37 AM »
Well, ain't that the weirdest...
I ended up replicating the RGB call in VB to try and figure out where I was going wrong and it turns out VB switches the offset for the R and B channels, hence why my colours were all mixed up (i.e. the blue channel is multiplied by 65536, rather than the red channel). Simply swapped this around and everything is sorted! They are decimal values though, so I wasn't going completely mad.
...
and I've attached the .FC files for CalcImage to this post. To use them, just copy them to your PfE directory e.g. C:/ProgramData/Probe Software/Probe for EPMA/ and rename your LUT of choice to CUSTOM.FC and then re/start CalcImage, open your project/grd and go to Image Processing > Change Current Image Palettes and select Custom.

Ha!  I think I ran into the same issue which is why in my code above I have the comment "this is correct apparently"  (with the typo now fixed!)

Code: [Select]
' RGBcolor = Format(Hex(redvalue&) & Hex(greenvalue&) & Hex(bluevalue&), "000000")
redvalue& = (RGBColor& And &HFF&)
greenvalue& = (RGBColor& And &HFF00&) \ 256     ' this is correct appraently
bluevalue& = (RGBColor& And &HFF0000) \ 65536   ' this is correct apparently
The only stupid question is the one not asked!

JonF

  • Professor
  • ****
  • Posts: 149
Re: Image palette .FC file format
« Reply #6 on: April 25, 2024, 01:35:21 AM »
Ha!  I think I ran into the same issue which is why in my code above I have the comment "this is correct apparently"  (with the typo now fixed!)

I saw your comment and had a chuckle once I'd figured out what was going awry!

For completeness, I've also attached the CUSTOM_cividis.FC file to this post