gpt4 book ai didi

c - 位提取和隐写术

转载 作者:行者123 更新时间:2023-12-03 04:34:10 26 4
gpt4 key购买 nike

我正在尝试隐写术。我正在尝试从图像中提取文本文件。我能够读取该文件,获取这些位,但我在提取这些位时遇到问题。

int getbits( pixel p) {
return p & 0x03;
}

char extract ( pixel* image ) {
static int postion;
postion = 0;

postion = *image;

postion++;

char curChar;
curChar = '\0';
for(int i = 0; i<4; ++i) {
curChar = curChar << 2;
curChar = curChar | getbits(postion);
}
return curChar;
}

Pixel 是一个无符号字符。我有一个循环调用 extract()fputc(3) 返回值。我觉得我从这些碎片中得到了垃圾。这导致我得到大量(1.5 gig)txt 文件作为返回。

void decode( PgmType* pgm, char output[80] )
{
FILE*outstream;
int i, length;

outstream = fopen(output, "w");

if(!outstream)
{
fatal("Could not open");
}
for(i=0; i < 16; ++i)
{
length = length << 2;
length = length | getbits(*pgm->image);
}
if ((length* 4) < (pgm->width * pgm->height))
{
fatal("File Too Big");
}
for (i = 0 ;i<length; ++i)
{
fputc(extract(pgm->image), outstream);

}
fclose(outstream);

}

最佳答案

您实际上只是读取图像中的第一个像素 - [编辑],因为当您尝试使用静态变量来保持计数时,正如 Oli 指出的那样,您会立即覆盖它。

而是使用位置来跟踪您的计数;但将数据保存在另一个变量中:

相反,extract() 应该类似于:

char extract ( pixel* image )
{
static int postion = 0;

pixel data = image[position];

postion++;

// use 'data' for processing
}

关于c - 位提取和隐写术,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6565510/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com