Red/Green/Blue/GrayScale images
#1
[Image: Pandora.jpg]

Code: (Select All)
pic = _LoadImage("Pandora.jpg", 32)
Screen pic
Sleep
pic256 = Grayscale256(pic)
Screen pic256
Sleep
red256 = RedScale256(pic)
Screen red256
Sleep
green256 = GreenScale256(pic)
Screen green256
Sleep
blue256 = BlueScale256(pic)
Screen blue256
Sleep

Function Grayscale256 (image As Long)
    Dim As Long d, s, temp, r, g, b
    Dim As _MEM m(1): Dim As _Offset o(1), l
    d = _Dest: s = _Source
    m(0) = _MemImage(image): o(0) = m(0).OFFSET
    temp = _NewImage(_Width(image), _Height(image), 256)
    m(1) = _MemImage(temp): o(1) = m(1).OFFSET
    _Dest temp: For i = 0 To 255: _PaletteColor i, _RGB32(i): Next: _Dest d
    Do
        r = _MemGet(m(0), o(0) + 1, _Unsigned _Byte): g = _MemGet(m(0), o(0) + 2, _Unsigned _Byte): b = _MemGet(m(0), o(0) + 3, _Unsigned _Byte)
        _MemPut m(1), o(1), _RGB(r, g, b, temp) As _UNSIGNED _BYTE
        o(0) = o(0) + 4: o(1) = o(1) + 1
    Loop Until o(0) >= (m(0).OFFSET + m(0).SIZE)
    Grayscale256 = temp
    _MemFree m()
End Function

Function RedScale256 (image As Long)
    Dim As Long d, s, temp: d = _Dest: temp = Grayscale256(image)
    _Dest temp: For i = 0 To 255: _PaletteColor i, _RGB32(i, 0, 0): Next: _Dest d
    RedScale256 = temp
End Function

Function GreenScale256 (image As Long)
    Dim As Long d, s, temp: d = _Dest: temp = Grayscale256(image)
    _Dest temp: For i = 0 To 255: _PaletteColor i, _RGB32(0, i, 0): Next: _Dest d
    GreenScale256 = temp
End Function

Function BlueScale256 (image As Long)
    Dim As Long d, s, temp: d = _Dest: temp = Grayscale256(image)
    _Dest temp: For i = 0 To 255: _PaletteColor i, _RGB32(0, 0, i): Next: _Dest d
    BlueScale256 = temp
End Function
Reply
#2
[Image: image.png]


[Image: image.png]


[Image: image.png]


[Image: image.png]
Reply
#3
Library Collection -> IMG-Support -> imageprocess.bm -> functions MakeGrayscale, ExtractChannels, ExtractBitfields, ShiftRGB can do same and/or similar things, but still keep it 32-bit colors.

Also your grayscale seems not to take the human color perception into account (red * 0.299, green * 0.587, blue * 0.114).
Reply
#4
(01-02-2023, 09:09 PM)RhoSigma Wrote: Library Collection -> IMG-Support -> imageprocess.bm -> functions MakeGrayscale, ExtractChannels, ExtractBitfields, ShiftRGB can do same and/or similar things, but still keep it 32-bit colors.

Also your grayscale seems not to take the human color perception into account (red * 0.299, green * 0.587, blue * 0.114).

I just used the built-in QB64 256-color grayscale and _RGB mapping to translate the colors over quickly and easily.  Smile
Reply




Users browsing this thread: 6 Guest(s)