C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #16  
Old January 29th, 2013, 10:18 PM
salem's Avatar
salem salem is online now
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,834 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 14 h 39 m 7 sec
Reputation Power: 1774
> Ok, but for sure, in your humble opinion, strcat is the way to go to append the pixels to the buffer?
No NO NO NO NO!!!!!!!!
You're taking it all way too literally.
strcat is USELESS for appending pixels to the buffer.

I'm trying to get you to understand that the way strcat works is the same way that your 'append pixels to the buffer' would work.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

Reply With Quote
  #17  
Old January 29th, 2013, 11:37 PM
saldar05 saldar05 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 15 saldar05 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 26 m 49 sec
Reputation Power: 0
Ok, so the loop to write out n number of times would be in my loop to write out the pixels:
for int i=0;i<factor;i++)
{
fwrite(buffer, sizeof(RGBTRIPLE),factor, outptr)
}

Cool. Thank you both for that. But the loop to factor the pixels out? I dont follow on that. What is wrong with what I had(besides not working like how it should of course):
buffer[k]=triple;?

Reply With Quote
  #18  
Old January 30th, 2013, 12:47 AM
salem's Avatar
salem salem is online now
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,834 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 14 h 39 m 7 sec
Reputation Power: 1774
> buffer[k]=triple;?
Because k goes 0 1 2 0 1 2 0 1 2 for each pixel you read.

buffer index needs to go 0 1 2 3 4 5 6 7 8 .... if you want three copies of first pixel in 0 1 2, three copies of the second pixel in 3 4 5 and three copies of the third pixel in 6 7 8

Reply With Quote
  #19  
Old January 30th, 2013, 12:52 AM
BobS0327 BobS0327 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 118 BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 18 h 48 m 29 sec
Reputation Power: 44
Some of the issues are documented in the code:

Code:
//  Issue.You're using OldHeight and OldWidth in your outer and inner loops
//   You should be using your newly calculated width and height for your
//	new bitmap image

 // iterate over infile's scanlines
  for (int i = 0; i < abs(OldHeight); i++) {
    // iterate over pixels in scanline
    for (int j = 0; j < Oldwidth; j++) {
      // temporary storage
      RGBTRIPLE triple;
      // read RGB triple from infile
      fread(&triple, sizeof(RGBTRIPLE), 1, inptr);

// Issue.  Here you continually update the same area in buffer 
//  buffer[0] to buffer[factor-1]
//  You must "expand" the pixels here  to completely fill in the buffer file
//  This means you must use a temporary index variable to iterate thru the 
//  buffer variable in order to fill it with the expanded RGB pixels
      //iterate over each pixel factor times
      for (int k = 0; k < factor; k++) {
        buffer[k] = triple;
      }
// Issue.  Here you are ONLY writing THREE bytes in triple to your output file,
//  You should be writing the completely filled in buffer variable.
// In other words, the fwrite is completely wrong
  
// write RGB triple to outfile
// fwrite(&triple, sizeof(RGBTRIPLE), bi.biWidth, outptr);
    }
// Issue.  The following is totally meaningless.  You should skipping over the padding at the end
// of the old file row.  padding, if correctly computed will range between zero and three.
// Why are you adding 54?
	
    // skip over padding, if any
    fseek(inptr, 54 + (Oldwidth * sizeof(RGBTRIPLE) * i), SEEK_SET);

//  Ok. You got this one almost right.  You should be using the width of the new file
    for (int r = 0; r < factor; r++) {
      fwrite(buffer, sizeof(RGBTRIPLE), bi.biWidth, outptr);
    }
// Ok.  the following is correct	
    // write padding to outfile
    for (int p = 0; p < padding; p++)
      fputc(0x00, outptr);
  }


You're putting the cart before the horse on this assignment. You should create the header for the new BMP file first by cloning the old header file and then updating the required fields such as biWidth, biHeight, biSizeImage and bfSize. The new BMP file will NOT display properly in a Paint program if these fields are not updated to reflect the properties of the new file.

Once you have correctly built the new header for the BMP file, you can then concentrate on adding the pixel data to the file.

To reiterate, build the BMP header file first and then add the data to the file.

Finally, you don't come close to building a valid header for your new BMP file in the code that you have provided so far.

Reply With Quote
  #20  
Old January 31st, 2013, 01:55 AM
saldar05 saldar05 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 15 saldar05 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 26 m 49 sec
Reputation Power: 0
Ok, so after getting some time to review over what I need to do, I realized that I need the memcpy function to copy the pixels into the buffer(the destination address). That works like a charm. However, to continously append to the destination address, everything I'm doing doesnt seem to work. For example:

in my code, I have buffer incrementing by one to move to the next memory location:
buffer=buffer+1;

The program compiles for sure, but it crashes on me everytime. would I need to, for example in my memcpy
implement something of this nature:

memcpy(destination address+num bytes,source address, num)?

Or is my question a question of preference?

Reply With Quote
  #21  
Old January 31st, 2013, 02:55 AM
salem's Avatar
salem salem is online now
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,834 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 14 h 39 m 7 sec
Reputation Power: 1774
I dunno - I did this, and it seemed to work (for 1 test)
Code:
  // iterate over infile's scanlines
  for (int i = 0, BHeight = abs(OldHeight); i < BHeight; i++) {
    int bp = 0;
    // iterate over pixels in scanline
    for (int j = 0; j < Oldwidth; j++) {
      // temporary storage
      RGBTRIPLE triple = { 0xde, 0xad, 0xca };

      // read RGB triple from infile
      fread(&triple, sizeof(RGBTRIPLE), 1, inptr);

      //iterate over each pixel factor times  
      for (int k = 0; k < factor; k++) {
        buffer[bp++] = triple;
      }
    }
    // write RGB triple to outfile 
    // fwrite(&triple, sizeof(RGBTRIPLE), bi.biWidth, outptr); 
    for (int k = 0; k < factor; k++) {
      fwrite(buffer, 1, sizeof(RGBTRIPLE) * bi.biWidth, outptr);
      for (int p = 0; p < padding; p++)
        fputc(0x00, outptr);
    }
    // skip over padding, if any
    fseek(inptr, oldpadding, SEEK_CUR);
  }

Like I said, you're over thinking the buffer appending.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Need help resizing a bitmap file

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap