Let’s briefly introduce the principle of Photoshop image brightness/contrast adjustment:
1. Contrast algorithm formula.
Photoshop processes the contrast increment according to the positive and negative values of the given value respectively.
If newRGB is used to represent the new R, G, and B components of the image pixel, RGB represents the R, G, and B components of the image pixel, Threshold is the given threshold, and Contrast is the contrast increment. When Contrast is greater than 0 When:
1) newRGB = RGB + (RGB - Threshold) * (1 / (1 - Contrast / 255) - 1)
Where, when Contrast is equal to 255 (RGB - Threshold ) * (1 / (1 - Contrast / 255) - 1) is infinite (±). Since the maximum and minimum values of RGB are 255 and 0 respectively, newRGB can only be determined by Threshold, that is, newRGB = RGB >= Threshold ? 255: 0, this is actually setting the image threshold. The image is composed of up to eight colors, namely red, yellow, green, cyan, blue, purple, black and white. There are only up to 8 lines on the grayscale image.
When Contrast is less than 0:
2) newRGB = RGB + (RGB - Threshold) * Contrast / 255
Among them, when Contrast is equal to -255, the image RGB Each component is equal to the threshold, the image is completely gray, and there is only one line on the grayscale image, which is the threshold grayscale.
2. Image brightness adjustment. This article uses the most commonly used non-linear brightness adjustment (this brightness adjustment method is also used in versions below Photoshop CS3, and CS3 and above versions also retain the option of this brightness adjustment method).
3. Image brightness/contrast comprehensive adjustment algorithm. This is very simple. When the brightness and contrast are adjusted at the same time, if the contrast is greater than 0, adjust the brightness now, and then adjust the contrast; when the contrast is less than 0, the opposite is true, adjust the contrast first, and then adjust the brightness.
The following is all the code for Photoshop image brightness/contrast adjustment written using BCB2007 and GDI+ bitmap data, including example code:
//--- -------------------------------------------------- -----------------------
##// Define ARGB pixel structure
typedef union{
ARGB Color;
struct {
BYTE Blue;
BYTE Green;
BYTE Red;
BYTE Alpha;
};
}ARGBQuad, *PARGBQuad;
//------------- -------------------------------------------------- -----------
//---------------------------------------------------------------------------
FORCEINLINE
INT CheckValue(INT value)
{
return value 0? 0 : value >= 255? 255 : value;
}
//---------------------------------------------------------------------------
VOID BrightAndContrast(BitmapData *data, INT bright, INT contrast, BYTE threshold)
{
FLOAT cv = contrast 255? -1.0f : contrast / 255.0f;
if (contrast > 0 && contrast 255)
cv = 1.0f / (1.0f - cv) - 1.0f;
BYTE values[256];
for (INT i = 0; i 256; i ++)
{
INT v = contrast > 0? CheckValue(i + bright) : i;
if (contrast >= 255)
v = v >= threshold? 255 : 0;
else
v = CheckValue(v + (INT)((v - threshold) * cv + 0.5f));
values[i] = contrast 0? CheckValue(v + bright) : v;
}
PARGBQuad p = (PARGBQuad)data->Scan0;
INT offset = data->Stride - data->Width * sizeof(ARGBQuad);
for (UINT y = 0; y Height; y ++, (BYTE*)p += offset)
{
for (UINT x = 0; x Width; x ++, p ++)
{
p->Blue = values[p->Blue];
p->Green = values[p->Green];
p->Red = values[p->Red];
}
}
}
//------------------------------------------ ------------------------------------
// Lock GDI+ bitmap scan line to data
FORCEINLINE
VOID LockBitmap(Gdiplus::Bitmap *bmp, BitmapData *data)
{
Gdiplus::Rect r(0, 0, bmp->GetWidth(), bmp->GetHeight());
bmp->LockBits( &r, ImageLockModeRead | ImageLockModeWrite,
PixelFormat32bppARGB, data);
}
//---------------- -------------------------------------------------- -------
// GDI+ bitmap scan line unlock
FORCEINLINE
VOID UnlockBitmap(Gdiplus::Bitmap *bmp, BitmapData *data)
{
bmp->UnlockBits(data);
}
//--- -------------------------------------------------- -----------------------
##void __fastcall TForm1::Button3Click( TObject *Sender){
Gdiplus::Bitmap *bmp =
new Gdiplus::Bitmap(L"d:\\source.jpg"); Gdiplus::Graphics *g =
new Gdiplus::Graphics(Canvas->Handle); g->DrawImage(bmp,
0, 0);
BitmapData data;
LockBitmap(bmp, &data);
BrightAndContrast(&data,
0 , 100, 121); UnlockBitmap(bmp, &data);
g->DrawImage(bmp, data.Width,
0 );
delete g;
delete bmp;
}
//------------- -------------------------------------------------- ----------

Photoshop is very practical and creative in practical applications. 1) It provides basic editing, repairing and synthesis functions, suitable for beginners and professionals. 2) Advanced features such as content recognition fill and layer style can improve image effects. 3) Mastering shortcut keys and optimizing layer structure can improve work efficiency.

Advanced features of Adobe Photoshop include advanced selection tools, layer blending modes, and actions and scripts. 1) Advanced selection tools such as the Quick Selection Tool and the Color Range Selection Tool can accurately select image areas. 2) Layer blending mode such as "overlapping" mode can create unique visual effects. 3) Actions and scripts can automate repetition of tasks and improve work efficiency.

Photoshop's powerful functions in photo editing and enhancement include: 1. Use the "Repair Brush Tool" to remove acne, 2. Use the "Liquefaction Tool" to slim face, 3. Use the "Frequency Separation" technology to accurately retouch images. These functions are implemented through algorithms and image processing technology to optimize image processing effects.

Key features of Photoshop include layers and masks, adjustment tools, filters and effects. 1. Layers and masks allow independent editing of image parts. 2. Adjust tools such as brightness/contrast can modify image tone and brightness. 3. Filters and effects can quickly add visual effects. Mastering these features can help creative professionals achieve their creative vision.

Photoshop's applications in digital art include painting, illustration and image synthesis. 1) Painting: Using brushes, pencils and mixing tools, the artist can create realistic effects. 2) Illustration: With vector and shape tools, artists can accurately draw complex graphics and add effects. 3) Synthesis: Using mask and layer blending mode, artists can seamlessly blend different image elements.

Photoshop's advanced photo editing and synthesis technologies include: 1. Use layers, masks and adjustment layers for basic operations; 2. Use image pixel values to achieve photo editing effects; 3. Use multiple layers and masks for complex synthesis; 4. Use "liquefaction" tools to adjust facial features; 5. Use "frequency separation" technology to perform delicate photo editing, these technologies can improve image processing level and achieve professional-level effects.

The steps to using Photoshop for brand design include: 1. Use the Pen tool to draw basic shapes, 2. Add shadows and highlights through layer styles, 3. Adjust colors and details, 4. Use smart objects and actions to automatically generate different versions of the design. Photoshop helps designers create and optimize brand elements with the flexibility of layers and masks, ensuring consistency and professionalism of designs, from simple logos to complex branding guides.

Photoshop's subscription model is worth buying. 1) Users can access the latest version and use across devices at any time. 2) The subscription fee is low, and continuous updates and technical support are provided. 3) Advanced functions such as neural filters can be used for complex image processing. Despite the high long-term costs, its convenience and feature updates are valuable to professional users.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software