implement Scaler; include "sys.m"; sys: Sys; include "draw.m"; include "print.m"; include "scaler.m"; DEBUG := 0; # Scaler initialisation init(debug: int, WidthInPixels, ScaleFactorMultiplier, ScaleFactorDivisor: int): ref RESSYNSTRUCT { DEBUG = debug; ScaleFactor := real ScaleFactorMultiplier / real ScaleFactorDivisor; ScaleBound := int ScaleFactor; if (ScaleFactor > real ScaleBound) ScaleBound++; ResSynStruct := ref RESSYNSTRUCT ( WidthInPixels+2, # add 2 for edges ScaleFactorMultiplier, ScaleFactorDivisor, ScaleFactor, int ((real WidthInPixels / real ScaleFactorDivisor))*ScaleFactorMultiplier + 1, ScaleFactorMultiplier != ScaleFactorDivisor, ScaleFactor < 2.0, (ScaleFactorMultiplier * 256 / ScaleFactorDivisor) - ((ScaleFactorMultiplier/ScaleFactorDivisor) * 256), 0, 0, array[NUMBER_RASTERS] of array of int, array[ScaleBound] of array of int, 0, 0 ); if (ResSynStruct.ScaleFactor > real ScaleBound) ScaleBound++; for (i:=0; i 0) { return rs.oBuffer[rs.ndelivered++][:rs.iOutputWidth-1]; } else return nil; } # Create output raster create_out(rs: ref RESSYNSTRUCT, simple: int) { factor: int; if (simple) factor = 1; else factor = 2; out_width := (rs.Width-2) * rs.ScaleFactorMultiplier / rs.ScaleFactorDivisor; number_out := rs.ScaleFactorMultiplier / rs.ScaleFactorDivisor; if (number_out == 2 && !(rs.ScaleFactorMultiplier % rs.ScaleFactorDivisor) ) { rs.nready = 2; rs.ndelivered = 0; return; } if (rs.ScaleFactorMultiplier % rs.ScaleFactorDivisor) { rs.Remainder = rs.Remainder + rs.Repeat; if (rs.Remainder >= 256) # send extra raster { number_out++; rs.Remainder = rs.Remainder - 256; } } # set up pointers into the output buffer output_raster := array[number_out] of array of int; output_raster[:] = rs.oBuffer[0:number_out]; ScaleFactorMultiplier := rs.ScaleFactorMultiplier; ScaleFactorDivisor := rs.ScaleFactorDivisor; sf := factor * ScaleFactorDivisor; # Convert the input data by starting at the bottom right hand corner and move left + up for (i:=(number_out-1); i>=0; i--) { y_index := i*sf/ScaleFactorMultiplier; orast_i := output_raster[i]; orast_y := output_raster[y_index]; for (lx := out_width-1; lx>=0; --lx) { x_index := lx*sf/ScaleFactorMultiplier; orast_i[lx] = orast_y[x_index]; } } rs.nready = number_out; rs.ndelivered = 0; return; } # Synthesise raster line rez_synth(rs: ref RESSYNSTRUCT, output_raster0, output_raster1: array of int) { i := 1; Buffer := rs.Buffer[i]; h_offset := 0; for (j:=1; j