-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
makeTga.sms and makeTgaRGB.sms are B&W, RGB color gradient examples. …
…Removed deprecated gradientTGA.sms
- Loading branch information
1 parent
24e00ed
commit 2215eec
Showing
3 changed files
with
84 additions
and
35 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/local/bin/sms -qm 10g | ||
# Demonstrates generating a 3-byte color map TGA image (B, G, R gradient) | ||
|
||
{ | ||
# Image dimensions | ||
let width = 256; | ||
let height = 256; | ||
|
||
# TGA file header size is 18 bytes | ||
let headerSize = 18; | ||
|
||
# Each pixel in a 3-byte color map has 3 bytes (B, G, R) | ||
let bytesPerPixel = 3; | ||
|
||
# Create a blank buffer with header size + width * height * bytesPerPixel for the image | ||
let buffer = ui8Repeat([ui8(0)], headerSize + width * height * bytesPerPixel); | ||
|
||
# Write the TGA header to the buffer | ||
# ID length (1 byte), Color Map Type (1 byte), Image Type (1 byte) | ||
buffer[0] = ui8(0); # No image ID field | ||
buffer[1] = ui8(0); # No color map | ||
buffer[2] = ui8(2); # Uncompressed, true-color image | ||
|
||
# Color Map Specification (5 bytes) | ||
buffer[3] = ui8(0); # First entry index (2 bytes) | ||
buffer[4] = ui8(0); | ||
buffer[5] = ui8(0); # Color map length (2 bytes) | ||
buffer[6] = ui8(0); | ||
buffer[7] = ui8(0); # Color map entry size (1 byte) | ||
|
||
# Image Specification (10 bytes) | ||
buffer[8] = ui8(0); # X-origin (2 bytes) | ||
buffer[9] = ui8(0); | ||
buffer[10] = ui8(0); # Y-origin (2 bytes) | ||
buffer[11] = ui8(0); | ||
buffer[12] = ui8(mod(width, 256)); # Width (2 bytes) | ||
buffer[13] = ui8(width / 256); | ||
buffer[14] = ui8(mod(height, 256)); # Height (2 bytes) | ||
buffer[15] = ui8(height / 256); | ||
buffer[16] = ui8(24); # Pixel depth (1 byte, 24 bits for BGR color) | ||
buffer[17] = ui8(0); # Image descriptor (1 byte) | ||
|
||
# Fill the image buffer with a color gradient | ||
for (let i = 0; i < height; i++) { | ||
for (let j = 0; j < width; j++) { | ||
# Calculate the pixel index after the header | ||
let pixelIndex = headerSize + (i * width + j) * bytesPerPixel; | ||
|
||
# Create a gradient (B, G, R) | ||
let blue = ui8(i * 255 / height); # Blue gradient based on vertical position | ||
let green = ui8(j * 255 / width); # Green gradient based on horizontal position | ||
let red = ui8((i + j) * 255 / (width + height)); # Red gradient combining both positions | ||
|
||
# Assign color values to the buffer | ||
buffer[pixelIndex] = blue; | ||
buffer[pixelIndex + 1] = green; | ||
buffer[pixelIndex + 2] = red; | ||
}; | ||
}; | ||
|
||
# Write the buffer to a file | ||
let success = fileWriteArr("color_gradient.tga", buffer); | ||
if (success) | ||
putLn("Color gradient TGA file 'color_gradient.tga' has been created.") | ||
else { | ||
putLn("Something went wrong..."); | ||
putLn(str(success)); | ||
}; | ||
}; | ||
|