当前位置:网站首页>C language picture transcoding for performance testing
C language picture transcoding for performance testing
2022-06-23 22:32:00 【FutureTester】
Recently, I was writing a performance test script for the mobile phone , When the mobile phone uploads picture data , First convert the picture into a pile 16 The character of the base , Transfer characters to , The server decodes the characters into pictures
We are loadrunner In the middle of the test , It needs to be used. C Language encodes pictures
The code is as follows :
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <io.h>
#include <fcntl.h>
#include <stdbool.h>
const char * base64char = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
char * base64_encode( const unsigned char * bindata, char * base64, int binlength )
{
int i, j;
unsigned char current;
for ( i = 0, j = 0 ; i < binlength ; i += 3 )
{
current = (bindata[i] >> 2) ;
current &= (unsigned char)0x3F;
base64[j++] = base64char[(int)current];
current = ( (unsigned char)(bindata[i] << 4 ) ) & ( (unsigned char)0x30 ) ;
if ( i + 1 >= binlength )
{
base64[j++] = base64char[(int)current];
base64[j++] = '=';
base64[j++] = '=';
break;
}
current |= ( (unsigned char)(bindata[i+1] >> 4) ) & ( (unsigned char) 0x0F );
base64[j++] = base64char[(int)current];
current = ( (unsigned char)(bindata[i+1] << 2) ) & ( (unsigned char)0x3C ) ;
if ( i + 2 >= binlength )
{
base64[j++] = base64char[(int)current];
base64[j++] = '=';
break;
}
current |= ( (unsigned char)(bindata[i+2] >> 6) ) & ( (unsigned char) 0x03 );
base64[j++] = base64char[(int)current];
current = ( (unsigned char)bindata[i+2] ) & ( (unsigned char)0x3F ) ;
base64[j++] = base64char[(int)current];
}
base64[j] = '\0';
return base64;
}
void encode(FILE * f_image, FILE * fp_out)
{
unsigned char bindata[2050]; // Data before calculation
char base64[4096]; // Calculated data
size_t bytes; // The actual size of the data before calculation
while ( !feof( f_image ) )
{
bytes = fread( bindata, 1, 2049, f_image );
base64_encode( bindata, base64, bytes );
fprintf( fp_out, "%s", base64 );
}
}
// Get picture file pointer
FILE * f_image = fopen("C:\\Users\\Administrator\\Desktop\\image\\123.jpg", "rb");
// If the picture file is abnormal, you can directly return sign out
if ( f_image == NULL )
{
fprintf(stderr, "Input file open error\n");
return EXIT_FAILURE;
}
encode(f_image, stdout);
// Close picture file pointer
fclose(f_image);
f_image = NULL;
return 0;
}边栏推荐
- What is dynamic registration? What is static registration?
- Impala port
- Apt attack
- 2021-12-19: find the missing numbers in all arrays. Give you an n
- How to create a virtual server through a fortress machine? What are the functions of the fortress machine?
- H264_ AVC analysis
- Grpc: quickly configure the general API to obtain process meta information
- How to use fortress remote server two types of Fortress
- Is the website under construction because there is no FTP upload? Can I upload without FTP
- In the new easygbs kernel version, the intranet mapping to the public network cannot be played. How to troubleshoot?
猜你喜欢

Hackinglab penetration test question 8:key can't find it again

Application practice | Apache Doris integrates iceberg + Flink CDC to build a real-time federated query and analysis architecture integrating lake and warehouse

为什么你的数据图谱分析图上只显示一个值?

游戏安全丨喊话CALL分析-写代码

Game security - call analysis - write code

Opengauss Developer Day 2022 was officially launched to build an open source database root community with developers

应用实践 | Apache Doris 整合 Iceberg + Flink CDC 构建实时湖仓一体的联邦查询分析架构

Pourquoi une seule valeur apparaît - elle sur votre carte de données?

SLSA: 成功SBOM的促进剂

在宇宙的眼眸下,如何正确地关心东数西算?
随机推荐
Go language core 36 lectures (go language practice and application 26) -- learning notes
Targeted, real-time audio and video optimization in remote control
2008R2 CFS with NFS protocol
How does the fortress remote login server operate? What is the application value of Fortress machine?
How to use fortress remote server two types of Fortress
How to lossless publish API gateway why do you need API gateway?
Use bcryptjs to encrypt the password
Interviewer: the difference between uselayouteffect and useeffect
0day1- (cve-2021-44228) log4j2 rce recurrence
2022年性价比高的商业养老保险产品排名
Why don't people like PHP?
This article takes you to understand the JVM class loading mechanism
Tcapulusdb Jun · industry news collection
H264_ AVC analysis
Game security - call analysis - write code
How does the fortress machine view the account assigned by the server? What are the specific steps?
VNC multi gear resolution adjustment, 2008R2 setting 1280 × 1024 resolution
Server classification of hardware knowledge (2)
Is the website under construction because there is no FTP upload? Can I upload without FTP
Command line enumeration, obtaining and modifying time zones