You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
1.7 KiB
80 lines
1.7 KiB
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include "dag_split_image.h"
|
|
|
|
#define MAX_IMG_SZ 8*1025*1024
|
|
|
|
int main()
|
|
{
|
|
unsigned char *zInpbuf = NULL;
|
|
|
|
zInpbuf = malloc(MAX_IMG_SZ);
|
|
if (!zInpbuf)
|
|
{
|
|
perror("malloc");
|
|
return -1;
|
|
}
|
|
ssize_t imgSz = read(0, zInpbuf, MAX_IMG_SZ);
|
|
if (imgSz <= 0)
|
|
{
|
|
perror("read");
|
|
free(zInpbuf);
|
|
return -1;
|
|
}
|
|
DataNode *dataList = splitData(zInpbuf, imgSz);
|
|
if (dataList == NULL) {
|
|
fprintf(stderr, "Failed to split data.\n");
|
|
return 1;
|
|
}
|
|
|
|
|
|
unsigned char *Imagedata1 = getDataNodeByIndex(dataList, 1);
|
|
unsigned char *Imagedata2 = getDataNodeByIndex(dataList, 2);
|
|
|
|
uint32_t imageSize1 = getImageDataSize(dataList, 1);
|
|
uint32_t imageSize2 = getImageDataSize(dataList, 2);
|
|
|
|
int x, y;
|
|
FILE *out_bin = stdout;
|
|
|
|
for (int i = 0; i < 54; i++)
|
|
{
|
|
x = Imagedata1[i];
|
|
y = (i < imageSize2) ? Imagedata2[i] : x;
|
|
fwrite(&x, 1, 1, out_bin);
|
|
}
|
|
|
|
int i = 0;
|
|
unsigned long big_img_offset = 54;
|
|
unsigned long small_img_offset = 54;
|
|
|
|
while (big_img_offset < imageSize1)
|
|
{
|
|
if (i == 2400) i = 0;
|
|
|
|
x = Imagedata1[big_img_offset++];
|
|
|
|
if (i < 300 && small_img_offset < imageSize2)
|
|
{
|
|
y = Imagedata2[small_img_offset++];
|
|
fwrite(&y, 1, 1, out_bin);
|
|
}
|
|
else
|
|
{
|
|
fwrite(&x, 1, 1, out_bin);
|
|
}
|
|
|
|
i++;
|
|
}
|
|
|
|
while (big_img_offset < imageSize1)
|
|
{
|
|
x = Imagedata1[big_img_offset++];
|
|
fwrite(&x, 1, 1, out_bin);
|
|
}
|
|
|
|
free(zInpbuf);
|
|
return 0;
|
|
}
|