Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) SecretMessageVcl

 

SecretMessage (VCL) is a tool to add a secret message to a 24-bit bitmap. These secret messages can also be extracted again.

 

SecretMessage (VCL) is the predecessor of SecretMessage.

 

 

 

 

 

Downloads

 

Technical facts

 

 

 

 

 

 

./ToolSecretMessageVcl/ProjectSecretMessage.cpp

 

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
USEFORM("UnitFormSecretMessage.cpp", FormSecretMessage);
USEFORM("UnitFormCreateSecret.cpp", FormCreateSecret);
USEFORM("UnitFormExtractSecret.cpp", FormExtractSecret);
USEFORM("UnitFormAbout.cpp", FormAbout);
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
  try
  {
     Application->Initialize();
     Application->Title = "Secret Message";
     Application->CreateForm(__classid(TFormSecretMessage), &FormSecretMessage);
     Application->Run();
  }
  catch (Exception &exception)
  {
     Application->ShowException(&exception);
  }
  catch (...)
  {
     try
     {
       throw Exception("");
     }
     catch (Exception &exception)
     {
       Application->ShowException(&exception);
     }
  }
  return 0;
}
//---------------------------------------------------------------------------

 

 

 

 

 

./ToolSecretMessageVcl/UnitFormAbout.h

 

//---------------------------------------------------------------------------
/*
  Secret Message, tool to add secret messages to images
  Copyright (C) 2009  Richel Bilderbeek

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#ifndef UnitFormAboutH
#define UnitFormAboutH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
//---------------------------------------------------------------------------
class TFormAbout : public TForm
{
__published: // IDE-managed Components
  TImage *ImageAuthor;
  TPanel *PanelTop;
  TPanel *PanelTopRight;
  TPanel *Panel1;
  TPanel *Panel2;
  TPanel *Panel3;
  TPanel *Panel4;
  TPanel *Panel5;
  TPanel *Panel6;
  TRichEdit *RichEdit;
private: // User declarations
public: // User declarations
  __fastcall TFormAbout(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormAbout *FormAbout;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

./ToolSecretMessageVcl/UnitFormAbout.cpp

 

//---------------------------------------------------------------------------
/*
  Secret Message, tool to add secret messages to images
  Copyright (C) 2009  Richel Bilderbeek

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "UnitFormAbout.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormAbout *FormAbout;
//---------------------------------------------------------------------------
__fastcall TFormAbout::TFormAbout(TComponent* Owner)
  : TForm(Owner)
{
}
//---------------------------------------------------------------------------

 

 

 

 

 

./ToolSecretMessageVcl/UnitFormCreateSecret.h

 

//---------------------------------------------------------------------------
/*
  Secret Message, tool to add secret messages to images
  Copyright (C) 2009  Richel Bilderbeek

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#ifndef UnitFormCreateSecretH
#define UnitFormCreateSecretH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <ComCtrls.hpp>
#include <Dialogs.hpp>
#include <ExtDlgs.hpp>
#include <Graphics.hpp>
//---------------------------------------------------------------------------
class TFormCreateSecret : public TForm
{
__published: // IDE-managed Components
  TPanel *PanelCreateSecret;
  TImage *ImageResult;
  TImage *ImageMessage;
  TImage *ImageOriginal;
  TOpenPictureDialog *OpenDialog;
  TSavePictureDialog *SaveDialog;
  TPanel *PanelLoadOriginal;
  TPanel *PanelLoadMessage;
  TPanel *PanelSave;
  void __fastcall PanelLoadOriginalMouseDown(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
  void __fastcall PanelLoadMessageMouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
  void __fastcall PanelSaveMouseDown(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
  void __fastcall FormResize(TObject *Sender);
private: // User declarations
public: // User declarations
  __fastcall TFormCreateSecret(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormCreateSecret *FormCreateSecret;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

./ToolSecretMessageVcl/UnitFormCreateSecret.cpp

 

//---------------------------------------------------------------------------
/*
  Secret Message, tool to add secret messages to images
  Copyright (C) 2009  Richel Bilderbeek

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "UnitFunctions.h"
#include "UnitFormCreateSecret.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormCreateSecret *FormCreateSecret;
//---------------------------------------------------------------------------
__fastcall TFormCreateSecret::TFormCreateSecret(TComponent* Owner)
  : TForm(Owner)
{
  ImageResult->Stretch = false;
  ImageResult->Align = alClient;
  OnResize(0);
}
//---------------------------------------------------------------------------
void __fastcall TFormCreateSecret::PanelLoadOriginalMouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  if (OpenDialog->Execute() == false) return;
  ImageOriginal->Picture->LoadFromFile(OpenDialog->FileName);

  //Valid bitmap?
  if ( ImageOriginal->Picture->Bitmap == 0
    || ImageOriginal->Picture->Bitmap->PixelFormat != pf24bit)
  {
    PanelLoadMessage->Visible = false;
    return;
  }

  PanelLoadMessage->Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TFormCreateSecret::PanelLoadMessageMouseDown(
      TObject *Sender, TMouseButton Button, TShiftState Shift, int X,
      int Y)
{
  if (OpenDialog->Execute() == false) return;
  ImageMessage->Picture->LoadFromFile(OpenDialog->FileName);

  //Valid bitmap?
  if ( ImageMessage->Picture->Bitmap == 0
    || ImageMessage->Picture->Bitmap->PixelFormat != pf24bit)
  {
    PanelSave->Visible = false;
    return;
  }


  PanelSave->Visible = true;
  AddMessageRed(ImageOriginal,ImageMessage,ImageResult);
  ImageResult->Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TFormCreateSecret::PanelSaveMouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  if (SaveDialog->Execute() == false) return;
  ImageResult->Picture->SaveToFile(SaveDialog->FileName);
  
}
//---------------------------------------------------------------------------
void __fastcall TFormCreateSecret::FormResize(TObject *Sender)
{
  const int width = ClientWidth / 3;
  PanelLoadOriginal->Width = width;
  PanelLoadMessage->Width = width;
  PanelSave->Width = width;
}
//---------------------------------------------------------------------------

 

 

 

 

 

./ToolSecretMessageVcl/UnitFormExtractSecret.h

 

//---------------------------------------------------------------------------
/*
  Secret Message, tool to add secret messages to images
  Copyright (C) 2009  Richel Bilderbeek

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#ifndef UnitFormExtractSecretH
#define UnitFormExtractSecretH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
#include <Dialogs.hpp>
#include <ExtDlgs.hpp>
//---------------------------------------------------------------------------
class TFormExtractSecret : public TForm
{
__published: // IDE-managed Components
  TPanel *PanelExtractSecret;
  TImage *ImageSecret;
  TOpenPictureDialog *OpenDialog;
  void __fastcall PanelExtractSecretMouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
private: // User declarations
public: // User declarations
  __fastcall TFormExtractSecret(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormExtractSecret *FormExtractSecret;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

./ToolSecretMessageVcl/UnitFormExtractSecret.cpp

 

//---------------------------------------------------------------------------
/*
  Secret Message, tool to add secret messages to images
  Copyright (C) 2009  Richel Bilderbeek

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "UnitFunctions.h"

#include "UnitFormExtractSecret.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormExtractSecret *FormExtractSecret;
//---------------------------------------------------------------------------
__fastcall TFormExtractSecret::TFormExtractSecret(TComponent* Owner)
  : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TFormExtractSecret::PanelExtractSecretMouseDown(
      TObject *Sender, TMouseButton Button, TShiftState Shift, int X,
      int Y)
{
  if (OpenDialog->Execute() == false) return;
  ImageSecret->Picture->LoadFromFile(OpenDialog->FileName);

  //Valid bitmap?
  if ( ImageSecret->Picture->Bitmap == 0
    || ImageSecret->Picture->Bitmap->PixelFormat != pf24bit)
  {
    ImageSecret->Visible = false;
    return;
  }
  ImageSecret->Visible = true;
  ExtractMessageRed(ImageSecret,ImageSecret);
}
//---------------------------------------------------------------------------

 

 

 

 

 

./ToolSecretMessageVcl/UnitFormSecretMessage.h

 

//---------------------------------------------------------------------------
/*
  Secret Message, tool to add secret messages to images
  Copyright (C) 2009  Richel Bilderbeek

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#ifndef UnitFormSecretMessageH
#define UnitFormSecretMessageH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Dialogs.hpp>
#include <ExtCtrls.hpp>
#include <ExtDlgs.hpp>
#include <ComCtrls.hpp>
#include <Menus.hpp>
#include <Graphics.hpp>
//---------------------------------------------------------------------------
class TFormSecretMessage : public TForm
{
__published: // IDE-managed Components
  TPanel *PanelCreate;
  TPanel *PanelExtract;
  TPanel *PanelAbout;
  void __fastcall PanelCreateMouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
  void __fastcall PanelExtractMouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
  void __fastcall PanelAboutMouseDown(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
private: // User declarations
public: // User declarations
  __fastcall TFormSecretMessage(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormSecretMessage *FormSecretMessage;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

./ToolSecretMessageVcl/UnitFormSecretMessage.cpp

 

//---------------------------------------------------------------------------
/*
  Secret Message, tool to add secret messages to images
  Copyright (C) 2009  Richel Bilderbeek

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include <boost/shared_ptr.hpp>

#include "UnitFormSecretMessage.h"
#include "UnitFormCreateSecret.h"
#include "UnitFormExtractSecret.h"
#include "UnitFormAbout.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormSecretMessage *FormSecretMessage;
//---------------------------------------------------------------------------
__fastcall TFormSecretMessage::TFormSecretMessage(TComponent* Owner)
  : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TFormSecretMessage::PanelCreateMouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  boost::shared_ptr<TFormCreateSecret> f(new TFormCreateSecret(0));
  f->ShowModal();
}
//---------------------------------------------------------------------------

void __fastcall TFormSecretMessage::PanelExtractMouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  boost::shared_ptr<TFormExtractSecret> f(new TFormExtractSecret(0));
  f->ShowModal();
}
//---------------------------------------------------------------------------

void __fastcall TFormSecretMessage::PanelAboutMouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  boost::shared_ptr<TFormAbout> f(new TFormAbout(0));
  f->ShowModal();
}
//---------------------------------------------------------------------------

 

 

 

 

 

./ToolSecretMessageVcl/UnitFunctions.h

 

//---------------------------------------------------------------------------
/*
  Secret Message, tool to add secret messages to images
  Copyright (C) 2009  Richel Bilderbeek

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#ifndef UnitFunctionsH
#define UnitFunctionsH
//---------------------------------------------------------------------------
#include <ExtCtrls.hpp>
namespace Extctrls { struct TImage; }
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/CppAddMessageRed.htm
void AddMessageRed(
  const Extctrls::TImage * const original,
  const Extctrls::TImage * const message,
  Extctrls::TImage * const result);
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/CppExtractMessageRed.htm
void ExtractMessageRed(
  const Extctrls::TImage * const original,
  Extctrls::TImage * const result);
//---------------------------------------------------------------------------
//Get a pixel's RGB values
//From http://www.richelbilderbeek.nl/CppGetPixel.htm
void GetPixel(
  const Extctrls::TImage * const image,
  const int x,
  const int y,
  unsigned char& red,
  unsigned char& green,
  unsigned char& blue);
//---------------------------------------------------------------------------
//Set a pixel's RGB values
//From http://www.richelbilderbeek.nl/CppSetPixel.htm
void SetPixel(
  Extctrls::TImage * const image,
  const int x,
  const int y,
  const unsigned char red,
  const unsigned char green,
  const unsigned char blue);
//---------------------------------------------------------------------------
const bool IsWhite(const Extctrls::TImage * const image, const int x, const int y);
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

./ToolSecretMessageVcl/UnitFunctions.cpp

 

//---------------------------------------------------------------------------
/*
  Secret Message, tool to add secret messages to images
  Copyright (C) 2009  Richel Bilderbeek

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// From http://www.richelbilderbeek.nl
//---------------------------------------------------------------------------
#pragma hdrstop

#include <cassert>
#include <algorithm>
#include "UnitFunctions.h"

//---------------------------------------------------------------------------
//Makes all red pixels even, except when there's a message pixel
//From http://www.richelbilderbeek.nl/CppAddMessageRed.htm
void AddMessageRed(
  const TImage * const original,
  const TImage * const message,
  TImage * const result)
{
  assert(original!=0 && "Image is NULL");
  assert(message!=0 && "Image is NULL");
  assert(result!=0 && "Image is NULL");
  assert(original->Picture->Bitmap!=0 && "Bitmap is NULL");
  assert(message->Picture->Bitmap!=0 && "Bitmap is NULL");
  assert(result->Picture->Bitmap!=0 && "Bitmap is NULL");
  assert(original->Picture->Bitmap->PixelFormat == pf24bit && "Bitmap must be 24 bit");
  assert(message->Picture->Bitmap->PixelFormat == pf24bit && "Bitmap must be 24 bit");
  assert(result->Picture->Bitmap->PixelFormat == pf24bit && "Bitmap must be 24 bit");

  //Get sizes and set size
  const int widthOriginal = original->Picture->Bitmap->Width;
  const int widthMessage  = message->Picture->Bitmap->Width;
  const int width = std::min(widthOriginal, widthMessage);
  result->Picture->Bitmap->Width = width;
  const int heightOriginal = original->Picture->Bitmap->Height;
  const int heightMessage  = message->Picture->Bitmap->Height;
  const int height = std::min(heightOriginal, heightMessage);
  result->Picture->Bitmap->Height = height;

  //Get the pixel offsets
  const int dx1 = (widthOriginal  - width ) / 2;
  const int dx2 = (widthMessage   - width ) / 2;
  const int dy1 = (heightOriginal - height) / 2;
  const int dy2 = (heightMessage  - height) / 2;
  assert(dx1 >= 0);
  assert(dx2 >= 0);
  assert(dy1 >= 0);
  assert(dy2 >= 0);

  for (int y=0; y!=height; ++y)
  {
    for(int x=0; x!=width; ++x)
    {
      const int x1 = dx1 + x;
      const int x2 = dx2 + x;
      const int x3 = x;
      assert(x1 >= 0);
      assert(x2 >= 0);
      assert(x3 >= 0);
      assert(x1 < original->Picture->Width);
      assert(x2 < message->Picture->Width );
      assert(x3 < result->Picture->Width  );
      const int y1 = dy1 + y;
      const int y2 = dy2 + y;
      const int y3 = y;
      assert(y1 >= 0);
      assert(y2 >= 0);
      assert(y3 >= 0);
      assert(y1 < original->Picture->Height);
      assert(y2 < message->Picture->Height);
      assert(y3 < result->Picture->Height);
      unsigned char r = 0;
      unsigned char g = 0;
      unsigned char b = 0;
      //Get original's pixel
      GetPixel(original,x1,y1,r,g,b);
      //Make colors even by increment, watch out for 256
      if (r%2 != 0)
      {
        if (r == 255) {--r;}
        else { ++r; }
      }
      assert(r%2 == 0);
      assert(r <= 254);
      //Add message
      const bool isWhite = IsWhite(message,x2,y2);
      if (isWhite == true) ++r;
      //Write to result image
      SetPixel(result,x3,y3,r,g,b);
    }
  }
}
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/CppExtractMessageRed.htm
void ExtractMessageRed(
  const TImage * const original,
  TImage * const result)
{
  assert(original!=0 && "Image is NULL");
  assert(result!=0 && "Image is NULL");
  assert(original->Picture->Bitmap!=0 && "Bitmap is NULL");
  assert(result->Picture->Bitmap!=0 && "Bitmap is NULL");
  assert(original->Picture->Bitmap->PixelFormat == pf24bit && "Bitmap must be 24 bit");
  assert(result->Picture->Bitmap->PixelFormat == pf24bit && "Bitmap must be 24 bit");

  //Get sizes and set size
  const int width = original->Picture->Bitmap->Width;
  result->Picture->Bitmap->Width = width;
  const int height = original->Picture->Bitmap->Height;
  result->Picture->Bitmap->Height = height;

  for (int y=0; y!=height; ++y)
  {
    for(int x=0; x!=width; ++x)
    {
      unsigned char r = 0;
      unsigned char g = 0;
      unsigned char b = 0;
      //Get original's pixel
      GetPixel(original,x,y,r,g,b);
      //Make colors even by increment, watch out for 256
      if (r%2 == 0)
      {
        //No message pixel
        SetPixel(result,x,y,0,0,0);
      }
      else
      {
        //Message pixel
        SetPixel(result,x,y,255,255,255);
      }
    }
  }

}
//---------------------------------------------------------------------------
//Get a pixel's RGB values
//From http://www.richelbilderbeek.nl/CppGetPixel.htm
void GetPixel(
  const TImage * const image,
  const int x,
  const int y,
  unsigned char& red,
  unsigned char& green,
  unsigned char& blue)
{
  assert(image!=0 && "Image is NULL");
  assert(image->Picture->Bitmap!=0 && "Bitmap is NULL");
  assert(image->Picture->Bitmap->PixelFormat == pf24bit && "Bitmap must be 24 bit");
  assert( x >= 0 && "x coordinat is below zero");
  assert( y >= 0 && "y coordinat is below zero");
  assert( x < image->Picture->Bitmap->Width  && "x coordinat is beyond image width");
  assert( y < image->Picture->Bitmap->Height && "y coordinat is beyond image height");

  const unsigned char * const line
    = static_cast<unsigned char *>(image->Picture->Bitmap->ScanLine[y]);

  red   = line[x*3+2];
  green = line[x*3+1];
  blue  = line[x*3+0];
}
//---------------------------------------------------------------------------
//Set a pixel's RGB values
//From http://www.richelbilderbeek.nl/CppSetPixel.htm
void SetPixel(
  TImage * const image,
  const int x,
  const int y,
  const unsigned char red,
  const unsigned char green,
  const unsigned char blue)
{
  assert(image!=0 && "Image is NULL");
  assert(image->Picture->Bitmap!=0 && "Bitmap is NULL");
  assert(image->Picture->Bitmap->PixelFormat == pf24bit && "Bitmap must be 24 bit");
  assert( x >= 0 && "x coordinat is below zero");
  assert( y >= 0 && "y coordinat is below zero");
  assert( x < image->Picture->Bitmap->Width  && "x coordinat is beyond image width");
  assert( y < image->Picture->Bitmap->Height && "y coordinat is beyond image height");

  unsigned char * const line
    = static_cast<unsigned char *>(image->Picture->Bitmap->ScanLine[y]);

  line[x*3+2] = red;
  line[x*3+1] = green;
  line[x*3+0] = blue;
}
//---------------------------------------------------------------------------
const bool IsWhite(const TImage * const image, const int x, const int y)
{
  unsigned char r = 0;
  unsigned char g = 0;
  unsigned char b = 0;
  GetPixel(image,x,y,r,g,b);
  const int sum = static_cast<int>(r)
    + static_cast<int>(g)
    + static_cast<int>(b);
  return (sum / 3 > 127);

}
//---------------------------------------------------------------------------

#pragma package(smart_init)

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml