처음 비트맵을 회전하고 크기를 조정하려고 시도했을 때 나는 분명한 선택을 했습니다. 소스 매트릭스에서 각 픽셀을 가져와서 회전 및 크기 조정으로 변환하고 대상의 변환된 위치에 값을 쓰는 것입니다.결과는 다음과 같습니다.
bitmap = J( bmy = 200, bmx = 300, RGB Color( 1, 1, 1 ) );//white
scale = 3;
tranmat = (1 || 0 || 80) |/ (0 || 1 || 10) |/ (0 || 0 || 1); // 2D translation matrix
scalmat = (scale || 0 || 0) |/ (0 || scale || 0) |/ (0 || 0 || 1); // 2D scale matrix
angle = 33 * Pi() / 180;
sangle = Sin( angle );
cangle = Cos( angle );
rotamat = (cangle || -sangle || 0) |/ (sangle || cangle || 0) |/ (0 || 0 || 1); // 2D rotation matrix
forward = (tranmat * scalmat * rotamat)`; // transpose here
// make a sample image
testimage = Text Box( "matrix", <<SETWRAP></SETWRAP>
Transformed text has holesTransformed text has holesTransformed text has holesTransformed text has holes변환된 텍스트에 구멍이 있음
끔찍해 보인다. 올바른 방법은 변환 행렬의 역을 사용하고 "대상 비트맵의 각 픽셀에 대해 소스에서 어떤 픽셀을 사용해야 합니까?"라고 묻는 것입니다. 그러나 답은 거의 항상 4픽셀 사이에 있습니다. 합리적인 답변은 4개 픽셀의 가중 평균을 사용하는 것이며 더 복잡한 답변은 바이큐빅 보간법처럼 보일 수 있습니다. 이 코드는 가중 평균을 사용합니다.
// this bitmap is used to build the image. drawtext will write
// each string into this bitmap.
bitmap = J( bmy = 300, bmx = 580, RGB Color( 1, 1, 1 ) );//white
// drawtext is a slow routine that draws a text string into a buffer,
// then samples that buffer to create a rotated, scaled copy in the
// bitmap buffer.
drawtext = Function(
{x = 0, y = 0, txt = "hello", degAngle = 0, xjust = 0, yjust = 1, fontsize = 99, scale = .5, textcolor = RGB Color( 0, 0, 0 )}, // parms
{// locals, initialized. Creates a transform matrix and its inverse
t = Text Box( txt, <<SETWRAP></SETWRAP>
Sampling the source image with linear interpolationSampling the source image with linear interpolationSampling the source image with linear interpolationSampling the source image with linear interpolation선형 보간으로 소스 이미지 샘플링
코드의 마지막 절반은 매트릭스 변환에 관한 것이 아니라 흥미로운 그림을 만드는 것입니다. 수평 줄무늬는 이미지의 여러 복사본을 함께 혼합하여 만들어지며, 각 이미지는 픽셀을 이동하고 더 먼 이동은 덜 유지합니다.
Big, tilted, orangeBig, tilted, orangeBig, tilted, orangeBig, tilted, orange크고 기울어 진 주황색