<commit_before>/**
 * FreeRDS: FreeRDP Remote Desktop Services (RDS)
 * Bitmap Encoder
 *
 * Copyright 2013 <NAME> <<EMAIL>>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "encoder.h"

#include <winpr/crt.h>

int freerds_bitmap_encoder_grid_init(rdsBitmapEncoder* encoder)
{
	int i, j, k;
	int tileSize;
	int tileCount;

	encoder->gridWidth = ((encoder->desktopWidth + (encoder->maxWidth - 1)) / encoder->maxWidth);
	encoder->gridHeight = ((encoder->desktopHeight + (encoder->maxHeight - 1)) / encoder->maxHeight);

	tileSize = encoder->maxWidth * encoder->maxHeight * 4;
	tileCount = encoder->gridWidth * encoder->gridHeight;

	encoder->gridBuffer = (BYTE*) malloc(tileSize * tileCount);
	encoder->grid = (BYTE**) malloc(tileCount * sizeof(BYTE*));

	for (i = 0; i < encoder->gridHeight; i++)
	{
		for (j = 0; j < encoder->gridWidth; j++)
		{
			k = (i * encoder->gridHeight) + j;
			encoder->grid[k] = &(encoder->gridBuffer[k * tileSize]);
		}
	}

	return 0;
}

int freerds_bitmap_encoder_grid_uninit(rdsBitmapEncoder* encoder)
{
	if (encoder->gridBuffer)
	{
		free(encoder->gridBuffer);
		encoder->gridBuffer = NULL;
	}

	if (encoder->grid)
	{
		free(encoder->grid);<commit_msg>Fixed bug in encoder where it was using the incorrect stride (per Marc-Andre).<commit_after>/**
 * FreeRDS: FreeRDP Remote Desktop Services (RDS)
 * Bitmap Encoder
 *
 * Copyright 2013 <NAME> <<EMAIL>>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "encoder.h"

#include <winpr/crt.h>

int freerds_bitmap_encoder_grid_init(rdsBitmapEncoder* encoder)
{
	int i, j, k;
	int tileSize;
	int tileCount;

	encoder->gridWidth = ((encoder->desktopWidth + (encoder->maxWidth - 1)) / encoder->maxWidth);
	encoder->gridHeight = ((encoder->desktopHeight + (encoder->maxHeight - 1)) / encoder->maxHeight);

	tileSize = encoder->maxWidth * encoder->maxHeight * 4;
	tileCount = encoder->gridWidth * encoder->gridHeight;

	encoder->gridBuffer = (BYTE*) malloc(tileSize * tileCount);
	encoder->grid = (BYTE**) malloc(tileCount * sizeof(BYTE*));

	for (i = 0; i < encoder->gridHeight; i++)
	{
		for (j = 0; j < encoder->gridWidth; j++)
		{
			k = (i * encoder->gridWidth) + j;
			encoder->grid[k] = &(encoder->gridBuffer[k * tileSize]);
		}
	}

	return 0;
}

int freerds_bitmap_encoder_grid_uninit(rdsBitmapEncoder* encoder)
{
	if (encoder->gridBuffer)
	{
		free(encoder->gridBuffer);
		encoder->gridBuffer = NULL;
	}

	if (encoder->grid)
	{
		free(encoder->grid);
{'fraction_non_alphanumeric': 0.13262451035254616, 'fraction_numerical': 0.00783435926133184, 'mean_word_length': 4.218978102189781, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4402620', 'n_tokens_mistral': 1209, 'n_tokens_neox': 1125, 'n_words': 347}