# Can this Delphi 6 bitmap modification code be sped up with SIMD or another approach?

I have a Delphi 6 application that modifies bitmaps in real time. Currently I am using the code shown below to do quickie brightness boost and contrast changes. If the operation were just an addition or just a multiplication, I could see how SIMD could be used, but since both an addition and a multiplication are involved, and since there is also the Trunc() operation to restrict it to the range of a Byte, I'm not sure if SIMD could be used here. Here are my questions:

1. Can SIMD be used with this code and do you know of a good code sample I could work from? What kind of a speed boost could I expect?
2. Would the (potential) padding of the scan lines be a problem?
3. Any general optimization tips on speeding up the code?

;

`// A fast version of this function would be to only allow range reductions // as a power of 2 and then use shl operations instead of divisions. procedure doBrightnessAndContrast(var clip: tbitmap; compressionRatio: double; shiftValue: Byte); var p0: PByte; x,y: Integer; begin for y := 0 to clip.Height-1 do begin p0 := clip.scanline[y]; // Can't just do the whole buffer as a big block of bytes since the // individual scan lines may be padded for CPU alignment. for x := 0 to clip.Width - 1 do begin // Red p0^ := IntToByte(Trunc(p0^ * compressionRatio) + shiftValue); Inc(p0); // Green p0^ := IntToByte(Trunc(p0^ * compressionRatio) + shiftValue); Inc(p0); // Green p0^ := IntToByte(Trunc(p0^ * compressionRatio) + shiftValue); Inc(p0); end; end; end; `

Sure, SSE or MMX is possible.

In your case however you may get almost the same speed improvement if you precompute a 256 entry table using your equations.

Then replace all computations with a simple table lookup. My best bet is, that on modern processors this will give nearly the same speed as MMX/SSE.

Category:performance Views:0 Time:2011-12-26

## Related post

• Constructing a bitmap from code; what steps are necessary? 2009-07-28

I'm building a System.Drawing.Bitmap in code from a byte array, and i'm not sure what properties and such need to be set so that it will properly save as a .BMP file. I have Bitmap b = new Bitmap(width, height, PixelFormat.Format32bppArgb); as my con

• How to simulate a Delphi breakpoint in code? 2008-10-02

I am pretty sure I have seen this before, but I haven't found out / remembered how to do it. I want to have a line of code that when executed from the Delphi debugger I want the debugger to pop-up like there was a break point on that line. Something

• VB to Delphi string manipulation code conversion 2009-12-18

I have some VB source code and want to convert it to Delphi: Do While Not EOF(textfile) Line Input #textfile, Line Dim retstring() As String retstring = Split(Line, Chr(32)) first = retstring(0) second = retstring(1) I have some text file with lines

• Delphi To Java code conversion: image.canvas.pixels 2010-03-15

I'm trying to convert an old Delphi program I wrote into Java to compile and run on my Android phone. I'm running the Android 2.1 operating system but am using version 1.6 of the SDK. I have a routine in Delphi where I set the colour of pixels on a c

• DELPHI : EEncodingError - Invalid code page on windows xp embedded 2010-06-09

Hi I have a application that works well on windows xp pro, windows Visa, windows 7 But when I run it on windows xp embedded it does not work and gives the following error: EEncodingError - Invalid code page When the App was made with Delphi 2006 it w

• Delphi 2010: integrated code formatter disappeared from menu 2010-06-14

How to get back integrated source code formatting back to Delphi? I suppose I disabled some package or something and there is no more an option in Edit menu to format source. What package should I get back installed to have it on again? -------------

• Wrong Unicode conversion, how to store accent characters in Delphi 2010 source code and handle character sets? 2010-07-27

We are upgrading our project from Delphi 2006 to Delphi 2010. Old code was: InputText: string; InputText := SomeTEditComponent.Text; ... for i := 1 to length(InputText) do if InputText[i] in ['0'..'9', 'a'..'z', 'Ř' { and more special characters } ]

• android how to save a bitmap - buggy code 2010-09-02

Im trying to serialize a class in wich i have a bitmap variable. Here is the code that is a bit working.... I need help to find out what is still wrong..... private Bitmap myVideoScreenshotBm; private void writeObject(ObjectOutputStream out) throws I

• Bitmap-analysis code works pre-2.2, not 2.2 2010-10-04

I'm creating "maps" for a game I'm making, and it's working fine on <=Android 2.1, but 2.2 is causing problems. I'm not sure if this is a common method, so I'll explain what I'm doing. First, I draw the map which the user is going to see then I dr

• How Delphi Compiles my code 2010-12-04

How will the Delphi compiler compiles the following code ; uses a_big_unit; procedure TForm1.Button1Click(Sender: TObject); var acompont : T_a_big_component ; begin if (true = false ) then // or if false then begin bc := Tbig_component.create(self) e

• Android bitmap native code - linking problem 2011-02-08

I have a problem when compiling my app, which is inspired from bitmap-plasma. I was calling if ((ret = AndroidBitmap_getInfo(env, bitmap, &info)) < 0) { LOGE("AndroidBitmap_getInfo() failed ! error=%d", ret); return; } if (info.format != ANDRO

• Delphi 2007 R2 Code Completion not listing base class members 2011-05-23

I've recently installed Delphi 2007 R2 along with GExperts1.34, DelphiSpeedUp3.1 and IDEFixPack4.1. The code completion feature doesn't work for me. Say, I create a new form and in the public section I hit CTRL+SPACE, I see only certain members of TO

• Delphi to Java code conversion 2012-02-11

how can i convert the specific code written in Delphi to JAVA try LLine := TMemoryStream.Create; IdTCPClient1.IOHandler.WriteLn('atext'); IdTCPClient1.IOHandler.ReadStream(LLine, -1); LLine.Position := 0; LLine.Read(intval, 4); //the server is sendin

• How to display tooltip or hint similar to Delphi XE tooltip code insight 2011-01-20

I'm looking at wanting to implement a tooltip similar to the way Delphi XE does when you're debugging and you hover over an object. ie, it opens up a hint window with + signs which you can expand etc. I'm trying to create a hint window which will sho

• How could this Java code be sped up? 2011-09-16

I am trying to benchmark how fast can Java do a simple task: read a huge file into memory and then perform some meaningless calculations on the data. All types of optimizations count. Whether it's rewriting the code differently or using a different J

• How do I apply a blue to yellow gradient on a bitmap through code, brightness as factor 2012-01-12

I need to apply a blue to yellow gradient to a bitmap. The factor here is the brightness. The dark areas of the photo need to be blueish and the brightest area's yellow. So the brightness of every pixel needs to be taken as a factor. Can someone help

• Can this code be sped up? 2014-02-15

Hi. I mentioned in another thread that my entire code to go through 9 sheets takes 24 hours. People mentioned that sounded too long and suggested I post a new thread asking for help on speed. The below code takes somewhere around 40 minutes. I have t

• Converting a Delphi 5 engine control app to Android - need advice on the approach 2010-11-16

I have an app written in Delphi 5 that I want to convert to run on Android 2.x. The app is pretty simple; its used to upload/download configuration files to a separate microprocessor over a Modbus serial link. (It's an engine management chip for use

• What is the most critical piece of code you have written and how did you approach it? 2008-10-06

Put it another way: what code have you written that cannot fail. I'm interested in hearing from those who have worked on projects dealing with heart monitors, water testing, economic fundamentals, missile trajectories, or the O2 concentration on the