@@ -203,10 +203,10 @@ public RunLengthEncoding(PixImage image) {
203
203
image .getBlue (0 , 0 ));
204
204
continue ;
205
205
}
206
- if (runs .tail .getRed () == (int ) image .getRed (x , y )
207
- && runs .tail .getGreen () == (int ) image .getGreen (x , y )
208
- && runs .tail .getBlue () == (int ) image .getBlue (x , y )) {
209
- runs .tail .Increment ();
206
+ if (runs .tail .getValue (). getRed () == (int ) image .getRed (x , y )
207
+ && runs .tail .getValue (). getGreen () == (int ) image .getGreen (x , y )
208
+ && runs .tail .getValue (). getBlue () == (int ) image .getBlue (x , y )) {
209
+ runs .tail .getValue (). Increment ();
210
210
} else {
211
211
runs .add (1 , (int ) image .getRed (x , y ),
212
212
(int ) image .getGreen (x , y ),
@@ -267,27 +267,27 @@ public void setPixel(int x, int y, short red, short green, short blue) {
267
267
268
268
while (curr != null ) {
269
269
previousIndex = currIndex ;
270
- currIndex += curr .getRunLength ();
270
+ currIndex += curr .getValue (). getRunLength ();
271
271
if (currIndex >= index )
272
272
break ;
273
273
curr = curr .getNext ();
274
274
}
275
275
276
- if (curr .getRed () == (int ) red && curr .getGreen () == (int ) green
277
- && curr .getBlue () == (int ) blue ) {
276
+ if (curr .getValue (). getRed () == (int ) red && curr . getValue () .getGreen () == (int ) green
277
+ && curr .getValue (). getBlue () == (int ) blue ) {
278
278
return ;
279
279
} else {
280
280
if (index == previousIndex + 1 ) {
281
281
if (tryMerge (curr , curr .getPrevious (), red , green , blue )) {
282
- if (curr .getRunLength () == 0 ) {
282
+ if (curr .getValue (). getRunLength () == 0 ) {
283
283
curr .getPrevious ().setNext (curr .getNext ());
284
284
}
285
285
return ;
286
286
}
287
287
}
288
288
if (index == currIndex ) {
289
289
if (tryMerge (curr , curr .getNext (), red , green , blue )) {
290
- if (curr .getRunLength () == 0 ) {
290
+ if (curr .getValue (). getRunLength () == 0 ) {
291
291
curr .getNext ().setPrevious (curr .getPrevious ());
292
292
}
293
293
return ;
@@ -305,10 +305,10 @@ private boolean tryMerge(DoublyLinkedNode curr, DoublyLinkedNode target,
305
305
int red , int green , int blue ) {
306
306
if (target == null )
307
307
return false ;
308
- if (target .getRed () == (int ) red && target .getGreen () == (int ) green
309
- && target .getBlue () == (int ) blue ) {
310
- target .Increment ();
311
- curr .Decrement ();
308
+ if (target .getValue (). getRed () == (int ) red && target . getValue () .getGreen () == (int ) green
309
+ && target .getValue (). getBlue () == (int ) blue ) {
310
+ target .getValue (). Increment ();
311
+ curr .getValue (). Decrement ();
312
312
return true ;
313
313
}
314
314
return false ;
@@ -317,13 +317,9 @@ private boolean tryMerge(DoublyLinkedNode curr, DoublyLinkedNode target,
317
317
private void split (DoublyLinkedNode curr , int red , int green , int blue ,
318
318
int previousRunLength , int nextRunLength ) {
319
319
DoublyLinkedNode previousRun , nextRun ;
320
- previousRun = previousRunLength <= 0 ? curr .getPrevious ()
321
- : new DoublyLinkedNode (previousRunLength , (int ) curr .getRed (),
322
- (int ) curr .getGreen (), (int ) curr .getBlue ());
323
- nextRun = nextRunLength <= 0 ? curr .getNext () : new DoublyLinkedNode (
324
- nextRunLength , (int ) curr .getRed (), (int ) curr .getGreen (),
325
- (int ) curr .getBlue ());
326
- curr .setValue (red , green , blue , 1 );
320
+ previousRun = previousRunLength <= 0 ? curr .getPrevious () : new DoublyLinkedNode (new Run ((int ) curr .getValue ().getRed (), (int ) curr .getValue ().getGreen (), (int ) curr .getValue ().getBlue (), previousRunLength ));
321
+ nextRun = nextRunLength <= 0 ? curr .getNext () : new DoublyLinkedNode (new Run ((int ) curr .getValue ().getRed (),(int ) curr .getValue ().getGreen (), (int ) curr .getValue ().getBlue (), nextRunLength ));
322
+ curr .getValue ().setValue (red , green , blue , 1 );
327
323
if (previousRunLength > 0 ) {
328
324
if (curr .getPrevious () != null )
329
325
curr .getPrevious ().setNext (previousRun );
0 commit comments