суть программы в том чтобы спрятать один файл (например txt), в другом файле (например bmp), заменив каждый восьмой бит одного файла, каждым битом второго (замена младших битов состовляющих RGB).
компилируется нормально, но при выполнение ошибочка, в чем проблемма?
код sgraf.cpp
Код | //---------------------------------------------------------------------------
#include <vcl.h> #include <cstring.h> #include "stdio.h" #include "sgraf.h" #pragma hdrstop
//--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //-----------------------------------------------------------------------------
void __fastcall TForm1::SpeedButton2Click(TObject *Sender) { if (OpenDialog1->Execute()) { inFileName1 = OpenDialog1->FileName.c_str(); Edit1->Text = OpenDialog1->FileName.c_str(); } } //---------------------------------------------------------------------------
void __fastcall TForm1::SpeedButton3Click(TObject *Sender) { if (OpenDialog2->Execute()) { inFileName2 = OpenDialog2->FileName.c_str(); Edit2->Text = OpenDialog2->FileName.c_str(); } } //---------------------------------------------------------------------------
void __fastcall TForm1::SpeedButton4Click(TObject *Sender) { if (OpenDialog3->Execute()) { outFileName = Edit3->Text.c_str(); } } //--------------------------------------------------------------------------- sgraf::sgraf(void) { size1 = size2 = index1 = index2 = index3 = 0; endProcess = false; } //-----------------------------------------------------------------------------
void __fastcall TForm1::SpeedButton1Click(TObject *Sender) { sgraf *cl = new sgraf(); cl->Init(inFileName1, inFileName2, outFileName); cl->Process(); cl->End(); delete cl; } //--------------------------------------------------------------------------- sgraf::~sgraf(void) { } //-----------------------------------------------------------------------------
void sgraf::Init(const char *inFileName1, const char *inFileName2, const char *outFileName) { FILE *result; result = fopen(inFileName1, "rb"); result = fopen(inFileName2, "rb"); result = fopen(outFileName, "wb"); endProcess = false; } //-----------------------------------------------------------------------------
bool sgraf::ReadNextByte1(char *value) { bool result = false; *value = 0; if(size1 == 0 || index1 == size1) { size1 = fread(&inBuffer1, sizeof(char), bufsize, inFile1); index1 = 0; } if(size1 == 0) endProcess = true; else { *value = inBuffer1[index1++]; result = true; } return result; } //-----------------------------------------------------------------------------
bool sgraf::ReadNextByte2(char *value) { bool result = false; *value = 0; if(size2 == 0 || index2 == size2) { size2 = fread(&inBuffer2, sizeof(char), bufsize, inFile2); index2 = 0; } if(size2 == 0) endProcess = true; else { *value = inBuffer2[index2++]; result = true; } return result; } //-----------------------------------------------------------------------------
void sgraf::WriteNextByte(char value) { if(index3 < bufsize) outBuffer[index3++] = value; else { fwrite(&outBuffer, sizeof(char), bufsize, outFile); index3 = 0; } } //-----------------------------------------------------------------------------
void sgraf::Process() { char inByte1 = 0, inByte2 = 0, outByte = 0; while(ReadNextByte2(&inByte2) && !endProcess) { for(int i=0; i<8 && ReadNextByte1(&inByte1) && !endProcess; i++) { outByte = (inByte1 & 0x7f) | (inByte2 & 0x80); inByte2 = inByte2 << 1; WriteNextByte(outByte); } } } //-----------------------------------------------------------------------------
void sgraf::End(void) { fclose(inFile1); fclose(inFile2); if(index3 > 0) fwrite(&outBuffer, sizeof(char), index3, outFile); fclose(outFile); } //---------------------------------------------------------------------------
|
код sgraf.h
Код | //---------------------------------------------------------------------------
#ifndef sgrafH #define sgrafH //--------------------------------------------------------------------------- #include <Classes.hpp> #include <Controls.hpp> #include <StdCtrls.hpp> #include <Forms.hpp> #include <Buttons.hpp> #include <Dialogs.hpp> //--------------------------------------------------------------------------- class TForm1 : public TForm { __published: // IDE-managed Components TLabel *Label1; TLabel *Label2; TLabel *Label3; TSpeedButton *SpeedButton1; TEdit *Edit1; TEdit *Edit2; TEdit *Edit3; TSpeedButton *SpeedButton2; TSpeedButton *SpeedButton3; TSpeedButton *SpeedButton4; TOpenDialog *OpenDialog1; TOpenDialog *OpenDialog2; TOpenDialog *OpenDialog3; void __fastcall SpeedButton2Click(TObject *Sender); void __fastcall SpeedButton3Click(TObject *Sender); void __fastcall SpeedButton4Click(TObject *Sender); void __fastcall SpeedButton1Click(TObject *Sender); private: // User declarations public: // User declarations __fastcall TForm1(TComponent* Owner); const char* inFileName1; const char* inFileName2; const char* outFileName; };
#pragma once //--------------------------------------------------------------------------- class sgraf { public: sgraf(void); ~sgraf(void); void Init(const char *inFileName1, const char *inFileName2, const char *outFileName); void Process(); void End(); private: static const int bufsize = 4096; char inBuffer1[bufsize]; char inBuffer2[bufsize]; char outBuffer[bufsize];
bool ReadNextByte1(char *value); bool ReadNextByte2(char *value); void WriteNextByte(char value);
size_t size1, index1; size_t size2, index2; size_t index3;
FILE *inFile1; FILE *inFile2; FILE *outFile;
bool endProcess; }; //--------------------------------------------------------------------------- extern PACKAGE TForm1 *Form1; //--------------------------------------------------------------------------- #endif
|
|