% \nopdfcompression

\starttext

\startbitmapimage[x=128,y=128,height=100bp,color=rgb]
[encoded data, 101376 characters]
\stopbitmapimage

\startluacode
    function document.TestBitmap(nx,ny)
        local random = math.random
        local maxbit = 2^24
        for i=1,nx do
            for j=1,ny do
                context("%06x",random(0,maxbit))
            end
        end
    end
\stopluacode

\def\RandomBitmap#1#2{\ctxlua{document.TestBitmap(#1,#2)}}

\blank

\startMPcode
    draw textext("\bitmapimage[x=100,y=100]{\RandomBitmap{100}{100}}") xsized 10cm ;
\stopMPcode

\blank

\startMPcode
    draw textext("\bitmapimage[x=200,y=50]{\RandomBitmap{50}{200}}") xsized 10cm ;
\stopMPcode

\startluacode

    local random, floor = math.random, math.floor
    local format = string.format

    local function test(nx,ny,pattern,maxbit)
        local t = { }
        maxbit = maxbit - 1
        for i=1,nx do
            for j=1,ny do
                t[#t+1] = format(pattern,random(0,maxbit))
            end
        end
        figures.bitmapimage {
            data        = table.concat(t),
            xresolution = nx,
            yresolution = ny,
        }
    end

    test(600*2,300/2,"%02x",2^8)
    test(600*2,300/2,"%06x",2^24)
    test(600*2,300/2,"%08x",2^24)

\stopluacode

\stoptext
