-
-
Save Andoryuuta/010a64c283350e254a8fc1369dfb1396 to your computer and use it in GitHub Desktop.
Some C-like psuedocode
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
int calculateMaxX(QImage *a1, int *pX, int *pY){ | |
int originalImageWidth = QImage::width(a1); | |
int originalImageHeight = QImage::height(a1); | |
int imageWidth_m1 = originalImageWidth - 1; | |
int imageHeight_m1 = originalImageHeight - 1; | |
int tmpImageHeight = imageHeight_m1; | |
int tmp_cur_Y = 0; | |
int cur_X = 0; | |
int cur_Y = 0; | |
int output_Y = 0; | |
if ( *originalImageHeight > 0 ) | |
{ | |
tmpWidth = originalImageWidth; | |
do | |
{ | |
cur_X = 0; | |
totalPixelsCount = 0; | |
if ( tmpWidth <= 0 ) | |
{ | |
imageHeight_m1 = tmpImageHeight; | |
} | |
else | |
{ | |
// Loop over this row from left to right | |
do | |
{ | |
qPixel = QImage::pixel(a1, cur_X, cur_Y); | |
totalPixelsCount_p1 = totalPixelsCount; | |
imageWidth_m1 = tmpWidth; | |
if ( qPixel != 0xFFF0F0F0 && qPixel != 0xFF646464 ) | |
{ | |
totalPixelsCount_p1 = totalPixelsCount++ + 1; | |
if ( cur_X < tmpWidth ) | |
imageWidth_m1 = cur_X; | |
tmpWidth = imageWidth_m1; | |
if ( cur_X > v7 ) | |
v7 = cur_X; | |
} | |
cur_Y = tmp_cur_Y; | |
++cur_X; | |
} | |
while ( cur_X < originalImageWidth ); | |
imageHeight_m1 = tmpImageHeight; | |
// If there was at least 1 pixel in the row with a color that is not #F0F0F0 or #646464 | |
if ( totalPixelsCount_p1 ) | |
{ | |
tmp_cur_Y_2 = output_Y; | |
if ( tmp_cur_Y < tmpImageHeight ) | |
imageHeight_m1 = tmp_cur_Y; | |
tmpImageHeight = imageHeight_m1; | |
if ( tmp_cur_Y > output_Y ) | |
tmp_cur_Y_2 = tmp_cur_Y; | |
output_Y = tmp_cur_Y_2; | |
} | |
tmpWidth = originalImageWidth; | |
} | |
tmp_cur_Y = ++cur_Y; | |
} | |
while ( cur_Y < *originalImageHeight ); | |
} | |
*pX = cur_X; | |
*pY = output_Y; | |
} | |
/* | |
X == Row. Starts from 0 at the left, increases to the right. | |
Y == Column. Starts from 0 at the top, increases to the bottom. | |
*/ | |
void __cdecl DrawPreviewData(QImage *a1, FILE *FilePtr, char isThumbnail){ | |
int orginialImageWidth = QImage::width(a1); | |
int originalImageHeight = QImage::height(a1); | |
int imageWidth_m1 = orginialImageWidth - 1; | |
int imageHeight_m1 = originalImageHeight - 1; | |
// Get the max X that will be produced in the output image. | |
int calculatedMaxX = calculateMaxX(a1); | |
int CalculatedMaxY = calculateMaxY(a1); | |
int usedMaxX = 0; | |
int usedMaxY = 0; | |
if ( isThumbnail ) | |
{ | |
usedMaxY = CalculatedMaxY; | |
} | |
else | |
{ | |
tmpMaxX = calculatedMaxX + 15; | |
// Width | |
tmpWidth = imageWidth_m1 - 15; | |
if ( imageWidth_m1 <= 15 ) | |
tmpWidth = imageWidth_m1; | |
imageWidth_m1 = tmpWidth; | |
// Height | |
tmpHeight = imageHeight_m1 - 15; | |
if ( imageHeight_m1 <= 15 ) | |
tmpHeight = imageHeight_m1; | |
imageHeight_m1 = tmpHeight; | |
// Max X | |
if ( calculatedMaxX >= originalImageWidth - 16 ) | |
tmpMaxX = calculatedMaxX; | |
usedMaxX = tmpMaxX; | |
// Max Y | |
usedMaxY = CalculatedMaxY; | |
if ( CalculatedMaxY < *originalImageHeight - 16 ) | |
usedMaxY = CalculatedMaxY + 15; | |
} | |
if ( usedMaxX < imageWidth_m1 || usedMaxY < imageHeight_m1 ) | |
{ | |
OutputFile = FilePtr; | |
} | |
else | |
{ | |
QImage::copy( | |
a1, | |
&NewQImage, | |
imageWidth_m1, | |
imageHeight_m1, | |
calculatedMaxX - imageWidth_m1, | |
usedMaxY - imageHeight_m1); | |
if ( isThumbnail ) | |
{ | |
NewQImageHeight = QImage::height(&NewQImage); | |
NewQImageWidth = QImage::width(&NewQImage); | |
float maxDim = NewQImageHeight; | |
if ( NewQImageWidth >= NewQImageHeight) | |
maxDim = NewQImageWidth; | |
if ( maxDim > 200.0 ) | |
{ | |
scaledImage = QImage::scaled(&NewQImage, &v54, ((NewQImageWidth * 200.0) / maxDim)); | |
QImage::operator=(&NewQImage, scaledImage); | |
QImage::~QImage(&v54); | |
} | |
} | |
outputPreviewImageWidth = QImage::width(&NewQImage); | |
outputPreviewImageHeight = QImage::height(&NewQImage);; | |
outputPreviewBuffer = malloc(2 * outputPreviewImageWidth * outputPreviewImageHeight); | |
/* | |
// Encode the preview image | |
j = numberOfEncodedBytes | |
*/ | |
outputHeader.width = outputPreviewImageWidth; | |
outputHeader.height = outputPreviewImageHeight; | |
outputHeader.field_10 = 0; | |
outputHeader.DataSize = 2 * j; | |
outputHeader.DataOffset = ftell(File) + sizeof(outputHeader); | |
} | |
// Write header | |
fwrite(&outputHeader, sizeof(outputHeader), 1, File); | |
// Write encoded preview bytes | |
if ( outputPreviewBuffer ) | |
{ | |
fwrite(outputPreviewBuffer, outputHeader.DataSize, 1, File); | |
free(v52); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment